/*
	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 d=document, imgs = new Array(), zInterval = null, current=0, pause=false;
var imgsB = new Array(), b_current=0, b_pause=false;
var imgsC = new Array(), c_current=0, c_pause=false;

function sleep(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 


function so_init()
{
	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.getElementsByTagName('head')[0].appendChild(css);

	imgs = d.getElementById('rotatorA').getElementsByTagName('img');
		for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
		imgs[0].style.display = 'block';
		imgs[0].xOpacity = .99;
	setTimeout(so_xfade,3000);

	imgsB = d.getElementById('rotatorB').getElementsByTagName('img');
		for(i=1;i<imgsB.length;i++) imgsB[i].xOpacity = 0;
		imgsB[0].style.display = 'block';
		imgsB[0].xOpacity = .99;
	setTimeout(so_xfadeB,4000);
	

	imgsC = d.getElementById('rotatorC').getElementsByTagName('img');
		for(i=1;i<imgsC.length;i++) imgsC[i].xOpacity = 0;
		imgsC[0].style.display = 'block';
		imgsC[0].xOpacity = .99;
	setTimeout(so_xfadeC,5000);

}

function so_xfade()
{
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;

	cOpacity-=.05;
	nOpacity+=.05;

	imgs[nIndex].style.display = 'block';
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;

	setOpacity(imgs[current]);
	setOpacity(imgs[nIndex]);

	if(cOpacity<=0)
	{
		imgs[current].style.display = 'none';
		current = nIndex;
		setTimeout(so_xfade,4000);
	}
	else
	{
		setTimeout(so_xfade,35);
	}
}


function so_xfadeB()
{
	b_cOpacity = imgsB[b_current].xOpacity;
	b_nIndex = imgsB[b_current+1]?b_current+1:0;
	b_nOpacity = imgsB[b_nIndex].xOpacity;

	b_cOpacity-=.05;
	b_nOpacity+=.05;

	imgsB[b_nIndex].style.display = 'block';
	imgsB[b_current].xOpacity = b_cOpacity;
	imgsB[b_nIndex].xOpacity = b_nOpacity;

	setOpacity(imgsB[b_current]);
	setOpacity(imgsB[b_nIndex]);

	if(b_cOpacity<=0)
	{
		imgsB[b_current].style.display = 'none';
		b_current = b_nIndex;
		setTimeout(so_xfadeB,4000);
	}
	else
	{
		setTimeout(so_xfadeB,35);
	}
}

function so_xfadeC()
{
	c_cOpacity = imgsC[c_current].xOpacity;
	c_nIndex = imgsC[c_current+1]?c_current+1:0;
	c_nOpacity = imgsC[c_nIndex].xOpacity;

	c_cOpacity-=.05;
	c_nOpacity+=.05;

	imgsC[c_nIndex].style.display = 'block';
	imgsC[c_current].xOpacity = c_cOpacity;
	imgsC[c_nIndex].xOpacity = c_nOpacity;

	setOpacity(imgsC[c_current]);
	setOpacity(imgsC[c_nIndex]);

	if(c_cOpacity<=0)
	{
		imgsC[c_current].style.display = 'none';
		c_current = c_nIndex;
		setTimeout(so_xfadeC,4000);
	}
	else
	{
		setTimeout(so_xfadeC,35);
	}
}

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) + ')';
}
