﻿function CpoImage(n,t,i,r){this.Img=document.getElementById(n);if(!this.Img){window.console.log("Image not found: "+n);return}this.Url=t,this.UrlBase=i,this.UrlLink=r,this.OriginalUrl=this.Img.src,this.Img.parentNode&&this.Img.parentNode.tagName.toLowerCase()=="a"&&(this.ParentNode=this.Img.parentNode),this.OnClick=this.Img.onclick+"",this.Values=[]}CpoImage.prototype.SetImageReplace=function(n,t){window.clearTimeout(this.SetNewThread),this.NewUrl=this.ReplaceText(this.Url,n,t),this.NewUrlBase=this.ReplaceText(this.UrlBase,n,t),this.NewUrlLink=this.ReplaceText(this.UrlLink,n,t),this.OnClick&&(this.NewOnClick=this.ReplaceText(this.OnClick,n,t)),this.SetNewThread=window.setTimeout(Cpo.CreateDelegate(this,this.SetNew),50)},CpoImage.prototype.ReplaceText=function(n,t,i){return this.Values[t]=i,n.replace(/\[[^\]]*\]/gi,Cpo.CreateDelegate(this,this.RegExRep))},CpoImage.prototype.RegExRep=function(n){var r=n.substring(1,n.length-1).split("|"),u=this.Values[r[0]];if(!u){if(r[1])return r[1];r[0]}return u},CpoImage.prototype.SetNew=function(){this.Img.src=this.NewUrl,this.Img.highRes=this.NewUrlBase,this.OnClick&&(eval("this.ClickFunc = "+this.NewOnClick),this.Img.onclick=this.ClickFunc),this.ParentNode&&(this.ParentNode.href=this.NewUrlLink)},typeof Sys!="undefined"&&Sys.Application.notifyScriptLoaded();
