/*****

Image Cross Fade Redux
Version 1.1
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_banner,false):window.attachEvent("onload",so_init_banner);

var dbanner=document, imgsbanner = new Array(), currentbanner=0;

function so_init_banner() {
	if(!dbanner.getElementById || !dbanner.createElement)return;
	
	imgsbanner = dbanner.getElementById("bannerHomepage").getElementsByTagName("img");
	for(i=1;i<imgsbanner.length;i++) imgsbanner[i].xOpacity = 0;
	imgsbanner[0].style.display = "block";
	imgsbanner[0].xOpacity = .99;
	
	setTimeout(so_xfade_banner,10000);
}

function so_xfade_banner() {
	cOpacity = imgsbanner[currentbanner].xOpacity;
	nIndex = imgsbanner[currentbanner+1]?currentbanner+1:0;
	nOpacity = imgsbanner[nIndex].xOpacity;
	
	cOpacity-=.05;
	nOpacity+=.05;
	
	imgsbanner[nIndex].style.display = "block";
	imgsbanner[currentbanner].xOpacity = cOpacity;
	imgsbanner[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgsbanner[currentbanner]); 
	setOpacity(imgsbanner[nIndex]);
	
	if(cOpacity<=0) {
		imgsbanner[currentbanner].style.display = "none";
		currentbanner = nIndex;
		setTimeout(so_xfade_banner,10000);
	} else {
		setTimeout(so_xfade_banner,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) + ")";
	}
	
}
