cpPicLink = function(id,dest,img,link){
	this.name=id;
	this.dest=document.getElementById(dest);
	this.timeout=null;
	this.status='null';
	this.img=img.split("$");
	this.link=link.split("$");
	this.max=this.img.length;
	this.nr=0;
	this.timeout=null;
	this.alpha=100;

	this.linkClick=function(){
		if(this.link[(this.nr) % this.max]!='') location.href=this.link[(this.nr) % this.max];
	}

	this.init=function(){
		this.dest.innerHTML='<div id="'+this.name+'_firstDiv" style="display:none;cursor:pointer;position:absolute;"><img id="'+this.name+'_firstPic" src="'+this.img[(this.nr+1) % this.max]+'" /></div>'+
							'<div id="'+this.name+'_secondDiv" onClick="cpPicLinkItem[\''+this.name+'\'].linkClick();" style="cursor:pointer;position:absolute;"><img id="'+this.name+'_secondPic" src="'+this.img[(this.nr) % this.max]+'" /></div>'+
							'<img id="'+this.name+'_right_img" style="cursor:pointer;position:absolute; right:2px;" src="pic/arrow_right.png" onClick="cpPicLinkItem[\''+this.name+'\'].fadeNext();" />'+
							'<img id="'+this.name+'_left_img" style="cursor:pointer;position:absolute; right:35px;" src="pic/arrow_left.png" onClick="cpPicLinkItem[\''+this.name+'\'].fadePrior();" />';
		this.timeout=setTimeout("cpPicLinkItem['"+this.name+"'].fadeNext();",9000);

	}

	this.fadeNext=function(){
		if(this.status!='fading') clearTimeout(this.timeout);
		this.status='fading';
		this.alpha=this.alpha-10;
		document.getElementById(this.name+'_firstDiv').style.display='';
		document.getElementById(this.name+'_secondDiv').style.filter = "alpha(opacity:"+this.alpha+")";
		document.getElementById(this.name+'_secondDiv').style.KHTMLOpacity = 
			document.getElementById(this.name+'_secondDiv').style.MozOpacity = 
			document.getElementById(this.name+'_secondDiv').style.opacity = this.alpha/100;
		if(this.alpha==0) {
			this.nr=(this.nr+1) % this.max;
			document.getElementById(this.name+'_secondPic').src=this.img[(this.nr) % this.max];
			document.getElementById(this.name+'_secondDiv').style.display='';
			document.getElementById(this.name+'_secondDiv').style.KHTMLOpacity = 
				document.getElementById(this.name+'_secondDiv').style.MozOpacity = 
				document.getElementById(this.name+'_secondDiv').style.opacity = 1;
			document.getElementById(this.name+'_secondDiv').style.filter='';
			document.getElementById(this.name+'_firstPic').src=this.img[(this.nr+1) % this.max];
			document.getElementById(this.name+'_firstDiv').style.display='none';
			this.alpha=100;
			this.status='waiting';
			this.timeout=setTimeout("cpPicLinkItem['"+this.name+"'].fadeNext();",9000);
		} else this.timeout=setTimeout("cpPicLinkItem['"+this.name+"'].fadeNext();",50);
	}

	this.fadePrior=function(){
		this.nr=(this.max+this.nr-2) % this.max;
		document.getElementById(this.name+'_firstPic').src=this.img[(this.nr+1) % this.max];
		this.fadeNext();
	}

	this.init();
}


var cpPicLinkItem=Array();

function addcpPicLink(id,dest,img,link){
	if(cpPicLinkItem[id]==null) {
		cpPicLinkItem[id]=new cpPicLink(id,dest,img,link);
	}
}
