// JavaScript Document

/*

Image Cross Fade Redux
Original Author: steve@slayeroffice.com
Modified by: Chris Wheeler
New Modified by: Design ruleSeven | www.designruleseven.com

Please leave this notice intact.

*/
window.addEventListener?window.addEventListener("load",init,false):window.attachEvent("onload",init);
window.addEventListener?window.addEventListener("load",init2,false):window.attachEvent("onload",init2);
window.addEventListener?window.addEventListener("load",init3,false):window.attachEvent("onload",init3);
window.addEventListener?window.addEventListener("load",initAdvisory,false):window.attachEvent("onload",initAdvisory);

var d=document, container, container2, container3, containerAd, imgs = new Array(), imgs2 = new Array(), imgs3 = new Array(), imgsAd = new Array(), zInterval = null, current=0, current2=0, current3=0, currentAd=0, pause=false;

function initAdvisory()
{
	if(!d.getElementById || !d.createElement) return;
	containerAd = d.getElementById('advisory');
	containerAd.style.backgroundImage = 'none';
	imgsAd = containerAd.getElementsByTagName('img');
	for(i=1; i<imgsAd.length; i++) imgsAd[i].xOpacity = 0;
	imgsAd[0].style.display = 'block';
	imgsAd[0].xOpacity = 1;
	setTimeout(xfadeAd,5000);
}


function init()
{
	if(!d.getElementById || !d.createElement) return;
	container = d.getElementById("blockOne");
	if(container != undefined)
	{
		container.style.backgroundImage="none";
		imgs = container.getElementsByTagName("img");
		for(i=1; i<imgs.length; i++) imgs[i].xOpacity = 0;
		imgs[0].style.display = "block";
		imgs[0].xOpacity = 1;
		setTimeout(xfade,4000);
	}
}


function init2()
{
	if(!d.getElementById || !d.createElement) return;
	container2 = d.getElementById("blockTwo");
	if(container2 != undefined)
	{
		container2.style.backgroundImage="none";
		imgs2 = container2.getElementsByTagName("img");
		for(i=1; i<imgs2.length; i++) imgs2[i].xOpacity = 0;
		imgs2[0].style.display = "block";
		imgs2[0].xOpacity = 1;
		setTimeout(xfade2,8000);
	}
}


function init3()
{
	if(!d.getElementById || !d.createElement) return;
	container3 = d.getElementById("blockThree");
	if(container3 != undefined)
	{
		container3.style.backgroundImage="none";
		imgs3 = container3.getElementsByTagName("img");
		for(i=1; i<imgs3.length; i++) imgs3[i].xOpacity = 0;
		imgs3[0].style.display = "block";
		imgs3[0].xOpacity = 1;
		setTimeout(xfade3,6000);
	}
}


function 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(xfade,4000);
	}
	else setTimeout(xfade,50);
}


function xfade2()
{
	cOpacity  = imgs2[current2].xOpacity;
	nIndex2   = imgs2[current2+1]?current2+1:0;
	nOpacity  = imgs2[nIndex2].xOpacity;

	cOpacity -=.05;
	nOpacity +=.05;

	imgs2[nIndex2].style.display = 'block';
	imgs2[current2].xOpacity = cOpacity;
	imgs2[nIndex2].xOpacity = nOpacity;

	setOpacity(imgs2[current2]);
	setOpacity(imgs2[nIndex2]);

	if(cOpacity<=0)
	{
		imgs2[current2].style.display = 'none';
		current2 = nIndex2;
		setTimeout(xfade2,8000);
	}
	else setTimeout(xfade2,50);
}


function xfade3()
{
	cOpacity  = imgs3[current3].xOpacity;
	nIndex3   = imgs3[current3+1]?current3+1:0;
	nOpacity  = imgs3[nIndex3].xOpacity;

	cOpacity -=.05;
	nOpacity +=.05;

	imgs3[nIndex3].style.display = 'block';
	imgs3[current3].xOpacity = cOpacity;
	imgs3[nIndex3].xOpacity = nOpacity;

	setOpacity(imgs3[current3]);
	setOpacity(imgs3[nIndex3]);

	if(cOpacity<=0)
	{
		imgs3[current3].style.display = 'none';
		current3 = nIndex3;
		setTimeout(xfade3,6000);
	}
	else setTimeout(xfade3,50);
}


function xfadeAd()
{
	cOpacity  = imgsAd[currentAd].xOpacity;
	nIndexAd  = imgsAd[currentAd+1]?currentAd+1:0;
	nOpacity  = imgsAd[nIndexAd].xOpacity;

	cOpacity -=.05;
	nOpacity +=.05;

	imgsAd[nIndexAd].style.display = 'block';
	imgsAd[currentAd].xOpacity = cOpacity;
	imgsAd[nIndexAd].xOpacity = nOpacity;

	setOpacity(imgsAd[currentAd]);
	setOpacity(imgsAd[nIndexAd]);

	if(cOpacity<=0)
	{
		imgsAd[currentAd].style.display = 'none';
		currentAd = nIndexAd;
		setTimeout(xfadeAd,6000);
	}
	else setTimeout(xfadeAd,50);
}


function setOpacity(obj)
{
	if(obj.xOpacity > 1) { obj.xOpacity = 1; return; }
	obj.style.KHTMLOpacity = obj.xOpacity;
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
}
