

var promoAnimURL = function(id, target, anchorid, images, times, urls)
{
	this.myid = id;
	this.myAnchor = anchorid
	this.updateTime = 50;
	this.imageArray = images;
	this.timeArray = times;
	this.urlArray = urls;
	this.myTarget = target;
	this.currentOpacity = 100;
	this.activeImage = 0;
	this.activeTime = 0;
	
	this.setOpacity = function(imageId, opacity)
	{
		// update opacity -  opacity:0.4; filter:alpha(opacity=40)
		document.getElementById(imageId).style.opacity=opacity/100;
		//imageArray[activeImage].style.filter="alpha(opacity=50"+ currentOpacity + ")";
		document.getElementById(imageId).style.filter="alpha(opacity="+ opacity + ")";
	}

	this.nextTime = function()
	{
		this.activeTime++;
		if (this.activeTime >= this.timeArray.length)
		{
			this.activeTime = 0;
		}
	}
	
	this.prepNextImage = function()
	{
		// set the current image to the top and full opacity
		document.getElementById(this.myTarget+"_top").src = this.imageArray[this.activeImage];
		this.currentOpacity = 100;
		this.setOpacity(this.myTarget+"_top", this.currentOpacity);
		// set the URL of the link
		document.getElementById(this.myAnchor).href = this.urlArray[this.activeImage];
		// set the next image on the bottom
		this.activeImage++;
		if (this.activeImage >= this.imageArray.length)
		{
			this.activeImage = 0;
		}
		document.getElementById(this.myTarget+"_bottom").src = this.imageArray[this.activeImage];
	}
}
	
promoAnimURL.prototype.updateBPAnim = function()
{
	var next = false;
	// update current opacity
	this.currentOpacity = this.currentOpacity - (100*this.updateTime / (1000*this.timeArray[this.activeTime]));
	//this.currentOpacity = this.currentOpacity - 2;
	// check for under/overflow
	if (this.currentOpacity < 0)
	{
		// set to fully transparent
		this.currentOpacity = 0;
		next = true;
	}

	
	this.setOpacity(this.myTarget+"_top", this.currentOpacity);
	
	if (next == true)
	{
		// set up for next transition
		this.prepNextImage();
		// wait for the next time
		this.nextTime();
		this.nextTime();
		setTimeout(this.myid+".updateBPAnim();", this.timeArray[this.activeTime-1] * 1000);
	}
	else
	{
		setTimeout(this.myid+".updateBPAnim();", this.updateTime);
	}
}

promoAnimURL.prototype.start = function()
{
	this.prepNextImage();
	this.nextTime();
	setTimeout(this.myid+".updateBPAnim();", this.timeArray[this.activeTime -1] * 1000);
}





