/*****

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


*****/


window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, imgsx = new Array(), imgsw = new Array(), imgsv = new Array(), zInterval = null, xcurrent=0, wcurrent=0, vcurrent=0, pause=false;

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

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

	imgsx = d.getElementById("imageContainer1").getElementsByTagName("img");
	for(i=1;i<imgsx.length;i++) imgsx[i].xOpacity = 0;
	imgsx[0].style.display = "block";
	imgsx[0].xOpacity = .99;
	
	imgsw = d.getElementById("imageContainer2").getElementsByTagName("img");
	for(i=1;i<imgsw.length;i++) imgsw[i].wOpacity = 0;
	imgsw[0].style.display = "block";
	imgsw[0].wOpacity = .99;
	
	imgsv = d.getElementById("imageContainer3").getElementsByTagName("img");
	for(i=1;i<imgsv.length;i++) imgsv[i].vOpacity = 0;
	imgsv[0].style.display = "block";
	imgsv[0].vOpacity = .99;
	
	setTimeout(so_xfade,3333);
	setTimeout(so_wfade,6666);
	setTimeout(so_vfade,10000);
}

function so_xfade() {
	cOpacity = imgsx[xcurrent].xOpacity;
	nIndex = imgsx[xcurrent+1]?xcurrent+1:0;

	nOpacity = imgsx[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgsx[nIndex].style.display = "block";
	imgsx[xcurrent].xOpacity = cOpacity;
	imgsx[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgsx[xcurrent]); 
	setOpacity(imgsx[nIndex]);
	
	if(cOpacity<=0) {
		imgsx[xcurrent].style.display = "none";
		xcurrent = nIndex;
		setTimeout(so_xfade,10000);
	} else {
		setTimeout(so_xfade,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) + ")";
	}
	
}
function so_wfade() {
	cOpacity = imgsw[wcurrent].wOpacity;
	nIndex = imgsw[wcurrent+1]?wcurrent+1:0;

	nOpacity = imgsw[nIndex].wOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgsw[nIndex].style.display = "block";
	imgsw[wcurrent].wOpacity = cOpacity;
	imgsw[nIndex].wOpacity = nOpacity;
	
	setOpacity(imgsw[wcurrent]); 
	setOpacity(imgsw[nIndex]);
	
	if(cOpacity<=0) {
		imgsw[wcurrent].style.display = "none";
		wcurrent = nIndex;
		setTimeout(so_wfade,10000);
	} else {
		setTimeout(so_wfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.wOpacity>.99) {
			obj.wOpacity = .99;
			return;
		}
		obj.style.opacity = obj.wOpacity;
		obj.style.MozOpacity = obj.wOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.wOpacity*100) + ")";
	}
	
}
function so_vfade() {
	cOpacity = imgsv[vcurrent].vOpacity;
	nIndex = imgsv[vcurrent+1]?vcurrent+1:0;

	nOpacity = imgsv[nIndex].vOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgsv[nIndex].style.display = "block";
	imgsv[vcurrent].vOpacity = cOpacity;
	imgsv[nIndex].vOpacity = nOpacity;
	
	setOpacity(imgsv[vcurrent]); 
	setOpacity(imgsv[nIndex]);
	
	if(cOpacity<=0) {
		imgsv[vcurrent].style.display = "none";
		vcurrent = nIndex;
		setTimeout(so_vfade,10000);
	} else {
		setTimeout(so_vfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.vOpacity>.99) {
			obj.vOpacity = .99;
			return;
		}
		obj.style.opacity = obj.vOpacity;
		obj.style.MozOpacity = obj.vOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.vOpacity*100) + ")";
	}
	
}
