/*
Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com
Please leave this notice intact. 
Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
This code has been modified by the J.W. Hulme Company for use on http://www.jwhulmeco.com/
*/


window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, imgs=[0,0,0], zInterval = null, current=[0,0,0], pause=false, preinit=true, fadeamount=[.03,.03,.03], fadetime=[25,25,25], swapdelay=[3000,500,6000];
imgs[0] = new Array();
imgs[1] = new Array();
imgs[2] = new Array();

function so_init() {
	if(!d.getElementById || !d.createElement)return;

	imgs[0] = d.getElementById("imageContainer1").getElementsByTagName("img");
/*
	imgs[1] = d.getElementById("imageContainer2").getElementsByTagName("img");
	imgs[2] = d.getElementById("imageContainer3").getElementsByTagName("img");
	for(h=0;h<imgs.length;h++){for(i=1;i<imgs[h].length;i++){imgs[h][i].xOpacity = 0;}}
	for(j=0;j<imgs.length;j++)
	{
	imgs[j][current[j]].style.display = "block";
	imgs[j][current[j]].xOpacity = .99;
	}
*/
	for(i=1;i<imgs[0].length;i++){imgs[0][i].xOpacity = 0;}
	imgs[0][0].style.display = "block";
	imgs[0][0].xOpacity = .99;

	setTimeout(so_xfade0,6000);
//	setTimeout(so_xfade1,10000);
//	setTimeout(so_xfade2,11500);
}

function so_xfade0() {
	cOpacity = imgs[0][current[0]].xOpacity;
	nIndex = imgs[0][current[0]+1]?current[0]+1:0;

	nOpacity = imgs[0][nIndex].xOpacity;
	
	cOpacity-=fadeamount[0]; 
	nOpacity+=fadeamount[0];
	
	imgs[0][nIndex].style.display = "block";
	imgs[0][current[0]].xOpacity = cOpacity;
	imgs[0][nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[0][current[0]]); 
	setOpacity(imgs[0][nIndex]);
	
	if(cOpacity<=0) {
		imgs[0][current[0]].style.display = "none";
		current[0] = nIndex;
		if(nIndex==0){
		setTimeout(so_xfade0,swapdelay[2]);
		} else {
		setTimeout(so_xfade0,swapdelay[0]);
		}
//		setTimeout(so_xfade1,swapdelay[1]);
	} else {
		setTimeout(so_xfade0,fadetime[0]);
	}
}
function so_xfade1() {
	cOpacity = imgs[1][current[1]].xOpacity;
	nIndex = imgs[1][current[1]+1]?current[1]+1:0;

	nOpacity = imgs[1][nIndex].xOpacity;
	
	cOpacity-=fadeamount[1]; 
	nOpacity+=fadeamount[1];
	
	imgs[1][nIndex].style.display = "block";
	imgs[1][current[1]].xOpacity = cOpacity;
	imgs[1][nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[1][current[1]]); 
	setOpacity(imgs[1][nIndex]);
	
	if(cOpacity<=0) {
		imgs[1][current[1]].style.display = "none";
		current[1] = nIndex;
//		setTimeout(so_xfade1,swapdelay[1]);
		setTimeout(so_xfade2,swapdelay[2]);
	} else {
		setTimeout(so_xfade1,fadetime[1]);
	}
}
function so_xfade2() {
	cOpacity = imgs[2][current[2]].xOpacity;
	nIndex = imgs[2][current[2]+1]?current[2]+1:0;

	nOpacity = imgs[2][nIndex].xOpacity;
	
	cOpacity-=fadeamount[2]; 
	nOpacity+=fadeamount[2];
	
	imgs[2][nIndex].style.display = "block";
	imgs[2][current[2]].xOpacity = cOpacity;
	imgs[2][nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[2][current[2]]); 
	setOpacity(imgs[2][nIndex]);
	
	if(cOpacity<=0) {
		imgs[2][current[2]].style.display = "none";
		current[2] = nIndex;
//		setTimeout(so_xfade2,swapdelay[2]);
		setTimeout(so_xfade0,swapdelay[0]);
	} else {
		setTimeout(so_xfade2,fadetime[2]);
	}
}
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) + ")";
}