
// Setup array for panel control images
aPnlConImg = new Array(4);
aPnlConImg[0] = new Array( "hpPrevOvr.gif", "hpPrevOut.gif" );
aPnlConImg[1] = new Array( "hpPlayOvr.gif", "hpPlayOut.gif" );
aPnlConImg[2] = new Array( "hpPauseOvr.gif", "hpPauseOut.gif" );
aPnlConImg[3] = new Array( "hpNextOvr.gif", "hpNextOut.gif" );

// Panel array
var aPanels = new Array(5);
aPanels[0] = new Array("32509_1",12,"?sec=A1");
aPanels[1] = new Array("32509_2",12,"?sec=PL&cat=5000");
aPanels[2] = new Array("32509_3",12,"?sec=PL&cat=WEB6");
aPanels[3] = new Array("32509_4",12,"?sec=PL&cat=WEB134");
aPanels[4] = new Array("32509_5",12,"?sec=A5");
aPanels[5] = new Array("32509_6",12,"?sec=A4");


// Constructor, initializes and launches process
crossfader = function( fadetime, delay )
{
	this.Panels = aPanels.length - 1;
	this.Playing = true;
	this.Index = Math.round(Math.random() * (this.Panels - 1));
	this.FTime = fadetime;	// nDur
	this.Delay = delay;		// nDelay
	this.TMult = 1000;

	// Initialize DIV styles in aPanels array
	for (var iPnl = 0; iPnl < aPanels.length; iPnl++)
	{
		document.getElementById(aPanels[iPnl][0]).style.opacity = 0;
		document.getElementById(aPanels[iPnl][0]).style.position = "absolute";
		document.getElementById(aPanels[iPnl][0]).style.filter = "alpha(opacity=0)";
		document.getElementById(aPanels[iPnl][0]).style.visibility = "hidden";
	}

	this.animate();
}

// Method to animate panels
crossfader.prototype.animate = function()
{
	if (this.nID1)
		clearInterval(this.nID1);

	// Store prior index
	this.PrevIdx = this.Index;

	// Increment index
	this.Index++;

	// If index exceeds panels, restart
	if (this.Index > this.Panels)
		this.Index = 0;

	document.getElementById( aPanels[this.Index][0] ).style.visibility = "visible";

	this.nInt = 50;
	this.nTime = 0;

	var oCF = this;
	this.nID2 = setInterval(function() { oCF.fade() }, this.nInt);
}

crossfader.prototype.fade = function()
{
	this.nTime += this.nInt;
	
	var ieop = Math.round( this.easeInOut(this.nTime, 0, 1, this.FTime) * 100 );
	var op = ieop / 100;

	document.getElementById( aPanels[this.Index][0] ).style.opacity = op;
	document.getElementById( aPanels[this.Index][0] ).style.filter = "alpha(opacity="+ieop+")";
	
	if (this.PrevIdx > -1)
	{
		document.getElementById( aPanels[this.PrevIdx][0] ).style.opacity = 1 - op;
		document.getElementById( aPanels[this.PrevIdx][0] ).style.filter = "alpha(opacity="+(100 - ieop)+")";
	}
	
	if (this.nTime == this.FTime)
	{
		clearInterval( this.nID2 );
		
		if (this.PrevIdx > -1)
			document.getElementById( aPanels[this.PrevIdx][0] ).style.visibility = "hidden";	
		
		var oCF = this;
		this.nID1 = setInterval(function() { oCF.animate() }, this.Delay);
	}
}

crossfader.prototype.easeInOut = function(t,b,c,d)
{
	return c/2 * (1 - Math.cos(Math.PI * t / d)) + b;
}

crossfader.prototype.toggleplay = function()
{
	oDiv = document.getElementById("PausePanel");
	
	if (this.Playing)
	{
		this.Playing = false;

		// Cancel any current intervals
		if (this.nID1)
			clearTimeout(this.nID1);

		if (this.nID2)
			clearTimeout(this.nID2);

		oImg = oDiv.childNodes[0];
		oImg.setAttribute( "src", "images/AdvantecR2_2/hpPlayOut.gif" );	
	}
	else
	{
		this.Playing = true;
		oImg = oDiv.childNodes[0];
		oImg.setAttribute( "src", "images/AdvantecR2_2/hpPauseOut.gif" );	
		this.animate();		
	}
}

crossfader.prototype.swapimage = function( sImgEle, iImgIdx )
{
	switch (sImgEle)
	{
		case "iPrvPnl":
			sNewImg = "images/AdvantecR2_2/" + aPnlConImg[0][iImgIdx];
			break;

		case "iConPnl":
			sNewImg = "images/AdvantecR2_2/" + (this.Playing ? aPnlConImg[2][iImgIdx] : aPnlConImg[1][iImgIdx]);
			break;

		case "iNxtPnl":
			sNewImg = "images/AdvantecR2_2/" + aPnlConImg[3][iImgIdx];
			break;
	}

	//alert("sImgEle=[" + sImgEle + "], sNewImg=[" + sNewImg + "], iImgIdx=[" + iImgIdx + "]");

	oEle = document.getElementById(sImgEle);
	oEle.src = sNewImg;
}

crossfader.prototype.prevpanel = function()
{
}

crossfader.prototype.nextpanel = function()
{
}