/*****

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


*****/

window.addEventListener ? window.addEventListener("load", so_init,false) : window.attachEvent("onload", so_init);

var rotimgs = new Array(), zInterval = null, current=0, pause=false;

function so_init()
{
	if(!document.getElementById || !document.createElement)return;
	
	css = document.createElement("link");
	css.setAttribute("href","xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	document.getElementsByTagName("head")[0].appendChild(css);

	rotimgs = document.getElementById("imageContainer").getElementsByTagName("img");
	for(i=1 ; i<rotimgs.length ; i++) rotimgs[i].xOpacity = 0;
	rotimgs[0].style.display = "block";
	rotimgs[0].xOpacity = .99;
	so_xfade();
}

function so_xfade()
{
	cOpacity = rotimgs[current].xOpacity;
	nIndex = rotimgs[current+1]?current+1:0;

	nOpacity = rotimgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	rotimgs[nIndex].style.display = "block";
	rotimgs[current].xOpacity = cOpacity;
	rotimgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(rotimgs[current]); 
	setOpacity(rotimgs[nIndex]);
	
	if(cOpacity<=0)
	{
		rotimgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,5*1000);
	}
	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) + ")";
	}
	
}