/*****

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, imgs = new Array(), imgs2 = new Array(), imgs3 = new Array(), imgs4 = new Array(), imgs5 = new Array(), zInterval = null, current=0, pause=false;

function so_init() {
	if(!d.getElementById || !d.createElement)return;

	// DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
	// http://slayeroffice.com/code/imageCrossFade/xfade2.css
	css = d.createElement("link");
	css.setAttribute("href","xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);

	imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	//imgs2 = d.getElementById("imageContainer2").getElementsByTagName("img");
	//for(i=1;i<imgs2.length;i++) imgs2[i].xOpacity = 0;
	//imgs2[0].style.display = "block";
	//imgs2[0].xOpacity = .99;
	
//	imgs3 = d.getElementById("imageContainer3").getElementsByTagName("img");
//	for(i=1;i<imgs3.length;i++) imgs3[i].xOpacity = 0;
//	imgs3[0].style.display = "block";
//	imgs3[0].xOpacity = .99;

//	imgs4 = d.getElementById("imageContainer4").getElementsByTagName("img");
//	for(i=1;i<imgs4.length;i++) imgs4[i].xOpacity = 0;
//	imgs4[0].style.display = "block";
//	imgs4[0].xOpacity = .99;
	
	imgs5 = d.getElementById("imageContainer5").getElementsByTagName("img");
	for(i=1;i<imgs5.length;i++) imgs5[i].xOpacity = 0;
	imgs5[0].style.display = "block";
	imgs5[0].xOpacity = .99;


	
	
	setTimeout(so_xfade,1000);
	//setTimeout(so_xfade2,2500);
	//setTimeout(so_xfade3,2500);
	//setTimeout(so_xfade4,2500);
	setTimeout(so_xfade5,1000);

}

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, 1500);
	} 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_xfade2() {
//	cOpacity = imgs2[current].xOpacity;
//	nIndex = imgs2[current+1]?current+1:0;

//	nOpacity = imgs2[nIndex].xOpacity;
//	
//	
//	cOpacity-=.05; 
//	nOpacity+=.05;
//	
//	imgs2[nIndex].style.display = "block";
//	imgs2[current].xOpacity = cOpacity;
//	imgs2[nIndex].xOpacity = nOpacity;
//	
//	setOpacity(imgs2[current]); 
//	setOpacity(imgs2[nIndex]);
//	
//	if(cOpacity<=0) {
//		imgs2[current].style.display = "none";
//		current = nIndex;
//		setTimeout(so_xfade2,2500);
//	} else {
//		setTimeout(so_xfade2,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_xfade3() {
//	cOpacity = imgs3[current].xOpacity;
//	nIndex = imgs3[current+1]?current+1:0;

//	nOpacity = imgs3[nIndex].xOpacity;
//	
//	
//	cOpacity-=.05; 
//	nOpacity+=.05;
//	
//	imgs3[nIndex].style.display = "block";
//	imgs3[current].xOpacity = cOpacity;
//	imgs3[nIndex].xOpacity = nOpacity;
//	
//	setOpacity(imgs3[current]); 
//	setOpacity(imgs3[nIndex]);
//	
//	if(cOpacity<=0) {
//		imgs3[current].style.display = "none";
//		current = nIndex;
//		setTimeout(so_xfade3,2500);
//	} else {
//		setTimeout(so_xfade3,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_xfade4() {
//	cOpacity = imgs4[current].xOpacity;
//	nIndex = imgs4[current+1]?current+1:0;

//	nOpacity = imgs4[nIndex].xOpacity;
//	
//	
//	cOpacity-=.05; 
//	nOpacity+=.05;
//	
//	imgs4[nIndex].style.display = "block";
//	imgs4[current].xOpacity = cOpacity;
//	imgs4[nIndex].xOpacity = nOpacity;
//	
//	setOpacity(imgs4[current]); 
//	setOpacity(imgs4[nIndex]);
//	
//	if(cOpacity<=0) {
//		imgs4[current].style.display = "none";
//		current = nIndex;
//		setTimeout(so_xfade4,2500);
//	} else {
//		setTimeout(so_xfade4,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_xfade5() {
	cOpacity = imgs5[current].xOpacity;
	nIndex = imgs5[current+1]?current+1:0;

	nOpacity = imgs5[nIndex].xOpacity;
	
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs5[nIndex].style.display = "block";
	imgs5[current].xOpacity = cOpacity;
	imgs5[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs5[current]); 
	setOpacity(imgs5[nIndex]);
	
	if(cOpacity<=0) {
		imgs5[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade5,1500);
	} else {
		setTimeout(so_xfade5,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) + ")";
	}
	
}

