/*
	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_init,false):window.attachEvent('onload',so_init);

var so_imgs = new Array(), so_current=0, so_timeout=1500;

/*  function so_init() output in template file */

function so_xfade()
{
	cOpacity = so_imgs[so_current].xOpacity;
	nIndex = so_imgs[so_current+1]?so_current+1:0;
	nOpacity = so_imgs[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	so_imgs[nIndex].style.display = 'block';
	so_imgs[so_current].xOpacity = cOpacity;
	so_imgs[nIndex].xOpacity = nOpacity;

	setOpacity(so_imgs[so_current]);
	setOpacity(so_imgs[nIndex]);

	if (cOpacity<=0)
	{
		so_imgs[so_current].style.display = 'none';
		so_current = nIndex;
		setTimeout(so_xfade,so_timeout);
	}
	else
	{
		setTimeout(so_xfade,50);
	}

	function setOpacity(obj)
	{
		if (obj.xOpacity>.99)
		{
			obj.xOpacity = .99;
		}

		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
	}
}