/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html

*****/

/* PLEASE NOTE: I modified the original code from slayroffice.com to accomodate my needs in my webpage.
   I needed to cross fade a single div element and modified the code to do this for me.
   If you want to use the code please download the original from slayeroffice.com for best results 
*/



var d = document;
var subD;
var divs = new Array();
var zInterval = null;
var nCurrentDiv = 0;
var nTargetDiv = 0;
var bFading = false;
var bLoading = true;

function so_init(nNumDivs)
{
	if(!d.getElementById || !d.createElement)
		return;

	var sQS;
	sQS = document.location.search;

	if(sQS != "")
	{
		if(sQS.search("imgLoad") > 0)
		{
			var aParams;
			aParams = sQS.split("=");
			nCurrentDiv = parseInt(aParams[1]);
		}
	}

	if (nCurrentDiv == 0)
	{
		nCurrentDiv = 1;
	}

	subD = window.frames["subIFrame"].document;

	if(nNumDivs > 1)
	{
		subD.getElementById("subPageThumb"+nCurrentDiv).className = "subPageThumbActive";
	}

	var i;
	for(i=1; i<=nNumDivs; ++i)
	{
		divs[i] = d.getElementById("subPageContent" + i);
		divs[i].xOpacity = 0;
	}

	divs[nCurrentDiv].style.display = "block";
	divs[nCurrentDiv].xOpacity = .99;
	
	bLoading = false;
}

function doXFade(nTarg)
{
	if(bLoading)
		return;
	if(bFading)
		return;
	
	if(nCurrentDiv == nTarg)
		return;
	
	bFading = true;

	subD.getElementById("subPageThumb"+nCurrentDiv).className = "subPageThumbInactive";
	subD.getElementById("subPageThumb"+nTarg).className = "subPageThumbActive";

	if(nCurrentDiv < nTarg)
	{
		subD.getElementById("subPageThumb"+nTarg+"B").focus();
		subD.getElementById("subPageThumb"+nTarg+"B").blur();
	}
	else
	{
		subD.getElementById("subPageThumb"+nTarg+"F").focus();
		subD.getElementById("subPageThumb"+nTarg+"F").blur();
	}

	nTargetDiv = nTarg;
	so_xfade();
}

function so_xfade()
{
	cOpacity = divs[nCurrentDiv].xOpacity;
	nOpacity = divs[nTargetDiv].xOpacity;
	
	cOpacity-=.1;
	nOpacity+=.1;
	
	divs[nTargetDiv].style.display = "block";
	divs[nCurrentDiv].xOpacity = cOpacity;
	divs[nTargetDiv].xOpacity = nOpacity;
	
	setOpacity(divs[nCurrentDiv]);
	setOpacity(divs[nTargetDiv]);
	
	if(cOpacity<=0)
	{
		divs[nCurrentDiv].style.display = "none";
		nCurrentDiv = nTargetDiv;
		bFading = false;
	}
	else
	{
		setTimeout(so_xfade,50);
	}
	
	function setOpacity(obj)
	{
		if(obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
}