/*
	Image Cross Fade Redux
	Version 1.0
	Last revision: 02.15.2006
	steve@slayeroffice.com

	Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*/

window.addEventListener?window.addEventListener('load',so_inits,false):window.attachEvent('onload',so_inits);

var d=document, imgss = new Array(), zInterval = null, current=0, pause=false;

function so_inits()
{
	if(!d.getElementById || !d.createElement)return;

	csss = d.createElement('link');
	csss.setAttribute('href','slideshow3.css');
	csss.setAttribute('rel','stylesheet');
	csss.setAttribute('type','text/csss');
	d.getElementsByTagName('head')[0].appendChild(csss);

	imgss = d.getElementById('rotators').getElementsByTagName('img');
	for(i=1;i<imgss.length;i++) imgss[i].xOpacity = 0;
	imgss[0].style.display = 'block';
	imgss[0].xOpacity = .99;

	setTimeout(so_xfades,3000);
}

function so_xfades()
{
	cOpacity = imgss[current].xOpacity;
	nIndex = imgss[current+1]?current+1:0;
	nOpacity = imgss[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	imgss[nIndex].style.display = 'block';
	imgss[current].xOpacity = cOpacity;
	imgss[nIndex].xOpacity = nOpacity;

	setOpacitys(imgss[current]);
	setOpacitys(imgss[nIndex]);

	if(cOpacity<=0)
	{
		imgss[current].style.display = 'none';
		current = nIndex;
		setTimeout(so_xfades,3000);
	}
	else
	{
		setTimeout(so_xfades,50);
	}

	function setOpacitys(objs)
	{
		if(objs.xOpacity>.99)
		{
			objs.xOpacity = .99;
			return;
		}

		objs.style.opacity = objs.xOpacity;
		objs.style.MozOpacity = objs.xOpacity;
		objs.style.filter = 'alpha(opacity=' + (objs.xOpacity*100) + ')';
	}
}
