/*****

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_initB,false):window.attachEvent("onload",so_initB);

var d=document, imgsB = new Array(), zInterval = null, currentB=0, pause=false;

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

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


        imgsB = d.getElementById("imageContainerB").getElementsByTagName("img");
	for(i=1;i<imgsB.length;i++) imgsB[i].xOpacity = 0;
	imgsB[0].style.display = "block";
	imgsB[0].xOpacity = .99;
	
	setTimeout(so_xfadeB,10000);
}

function so_xfadeB() {
	cOpacity = imgsB[currentB].xOpacity;
	nIndex = imgsB[currentB+1]?currentB+1:0;

	nOpacity = imgsB[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgsB[nIndex].style.display = "block";
	imgsB[currentB].xOpacity = cOpacity;
	imgsB[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgsB[currentB]);
	setOpacity(imgsB[nIndex]);
	
	if(cOpacity<=0) {
		imgsB[currentB].style.display = "none";
		currentB = nIndex;
		setTimeout(so_xfadeB,8000);
	} else {
		setTimeout(so_xfadeB,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) + ")";
	}
	
}
