/*****
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 imgs = new Array(), zInterval = null, current=0, pause=false;
var imgs2 = new Array(), zInterval2 = null, current2=0, pause2=false;
var imgs3 = new Array(), zInterval3 = null, current3=0, pause3=false;
var imgs4 = new Array(), zInterval4 = null, current4=0, pause4=false;

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

	imgs = document.getElementById("slideshow").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	// sets inital delay of first transisition in ms
	setTimeout(so_xfade,3000);
	
	// second slideshow
	imgs2 = document.getElementById("slideshow2").getElementsByTagName("img");
	for(i=1;i<imgs2.length;i++) imgs2[i].xOpacity2 = 0;
	imgs2[0].style.display = "block";
	imgs2[0].xOpacity2 = .99;
	
	// sets inital delay of first transisition in ms
	setTimeout(so_xfade2,4000);
	
	// third slideshow
	imgs3 = document.getElementById("slideshow3").getElementsByTagName("img");
	for(i=1;i<imgs3.length;i++) imgs3[i].xOpacity3 = 0;
	imgs3[0].style.display = "block";
	imgs3[0].xOpacity3 = .99;
	
	// sets inital delay of first transisition in ms
	setTimeout(so_xfade3,5000);
	
	// forth slideshow
	imgs4 = document.getElementById("slideshow4").getElementsByTagName("img");
	for(i=1;i<imgs4.length;i++) imgs4[i].xOpacity4 = 0;
	imgs4[0].style.display = "block";
	imgs4[0].xOpacity4 = .99;
	
	// sets inital delay of first transisition in ms
	setTimeout(so_xfade4,6000);
}

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

	nOpacity = imgs[nIndex].xOpacity;
	
	// changes speed of fade, higher values increase speed
	cOpacity-=.03; 
	nOpacity+=.03;
	
	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;
		// sets delay between each fade in ms
		setTimeout(so_xfade,6000);
	} 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*99) + ")";
	}
	
}
// second slideshow
function so_xfade2() {
	cOpacity2 = imgs2[current2].xOpacity2;
	nIndex2 = imgs2[current2+1]?current2+1:0;

	nOpacity2 = imgs2[nIndex2].xOpacity2;
	
	// changes speed of fade, higher values increase speed
	cOpacity2-=.03; 
	nOpacity2+=.03;
	
	imgs2[nIndex2].style.display = "block";
	imgs2[current2].xOpacity2 = cOpacity2;
	imgs2[nIndex2].xOpacity2 = nOpacity2;
	
	setOpacity2(imgs2[current2]); 
	setOpacity2(imgs2[nIndex2]);
	
	if(cOpacity2<=0) {
		imgs2[current2].style.display = "none";
		current2 = nIndex2;
		// sets delay between each fade in ms
		setTimeout(so_xfade2,6000);
	} else {
		setTimeout(so_xfade2,50);
	}
	
	function setOpacity2(obj2) {
		if(obj2.xOpacity2>.99) {
			obj2.xOpacity2 = .99;
			return;
		}
		obj2.style.opacity = obj2.xOpacity2;
		obj2.style.MozOpacity = obj2.xOpacity2;
		obj2.style.filter = "alpha(opacity=" + (obj2.xOpacity2*99) + ")";
	}
	
}

// third slideshow
function so_xfade3() {
	cOpacity3 = imgs3[current3].xOpacity3;
	nIndex3 = imgs3[current3+1]?current3+1:0;

	nOpacity3 = imgs3[nIndex3].xOpacity3;
	
	// changes speed of fade, higher values increase speed
	cOpacity3-=.03; 
	nOpacity3+=.03;
	
	imgs3[nIndex3].style.display = "block";
	imgs3[current3].xOpacity3 = cOpacity3;
	imgs3[nIndex3].xOpacity3 = nOpacity3;
	
	setOpacity3(imgs3[current3]); 
	setOpacity3(imgs3[nIndex3]);
	
	if(cOpacity3<=0) {
		imgs3[current3].style.display = "none";
		current3 = nIndex3;
		// sets delay between each fade in ms
		setTimeout(so_xfade3,6000);
	} else {
		setTimeout(so_xfade3,50);
	}
	
	function setOpacity3(obj3) {
		if(obj3.xOpacity3>.99) {
			obj3.xOpacity3 = .99;
			return;
		}
		obj3.style.opacity = obj3.xOpacity3;
		obj3.style.MozOpacity = obj3.xOpacity3;
		obj3.style.filter = "alpha(opacity=" + (obj3.xOpacity3*99) + ")";
	}
	
}

// forth slideshow
function so_xfade4() {
	cOpacity4 = imgs4[current4].xOpacity4;
	nIndex4 = imgs4[current4+1]?current4+1:0;

	nOpacity4 = imgs4[nIndex4].xOpacity4;
	
	// changes speed of fade, higher values increase speed
	cOpacity4-=.03; 
	nOpacity4+=.03;
	
	imgs4[nIndex4].style.display = "block";
	imgs4[current4].xOpacity4 = cOpacity4;
	imgs4[nIndex4].xOpacity4 = nOpacity4;
	
	setOpacity4(imgs4[current4]); 
	setOpacity4(imgs4[nIndex4]);
	
	if(cOpacity4<=0) {
		imgs4[current4].style.display = "none";
		current4 = nIndex4;
		// sets delay between each fade in ms
		setTimeout(so_xfade4,6000);
	} else {
		setTimeout(so_xfade4,50);
	}
	
	function setOpacity4(obj4) {
		if(obj4.xOpacity4>.99) {
			obj4.xOpacity4 = .99;
			return;
		}
		obj4.style.opacity = obj4.xOpacity4;
		obj4.style.MozOpacity = obj4.xOpacity4;
		obj4.style.filter = "alpha(opacity=" + (obj4.xOpacity4*99) + ")";
	}
	
}
