/*
	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_b,false):window.attachEvent('onload',so_init_b);

var d_b=document, imgs_b = new Array(), zInterval_b = null, current_b=0, pause_b=false;

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

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

	imgs_b = d_b.getElementById('slideshow2').getElementsByTagName('img');
	for(i=1;i<imgs_b.length;i++) imgs_b[i].xOpacity = 0;
	imgs_b[0].style.display = 'block';
	imgs_b[0].xOpacity = .99;

	setTimeout(so_xfade_b,3000);
}

function so_xfade_b()
{
	cOpacity = imgs_b[current_b].xOpacity;
	nIndex = imgs_b[current_b+1]?current_b+1:0;
	nOpacity = imgs_b[nIndex].xOpacity;

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

	imgs_b[nIndex].style.display = 'block';
	imgs_b[current_b].xOpacity = cOpacity;
	imgs_b[nIndex].xOpacity = nOpacity;

	setOpacity(imgs_b[current_b]);
	setOpacity(imgs_b[nIndex]);

	if(cOpacity<=0)
	{
		imgs_b[current_b].style.display = 'none';
		current_b = nIndex;
		setTimeout(so_xfade_b,3000);
	}
	else
	{
		setTimeout(so_xfade_b,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) + ')';
	}
}
