/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html


*****/


window.addEventListener?window.addEventListener("load",sop_init,false):window.attachEvent("onload",sop_init);

var doc=document, imgss = new Array(), zINT = null, curr=0, pause=false;

function sop_init() {
	if(!doc.getElementById || !doc.createElement)return;
	
	css =doc.createElement("link");
	css.setAttribute("href","http://currencycorp.com.au/include/xfade2_2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	doc.getElementsByTagName("head")[0].appendChild(css);
	
	imgss =doc.getElementById("imageContainer2").getElementsByTagName("img");
	for(i=1;i<imgss.length;i++) imgss[i].xOpacity = 0;
	imgss[0].style.display = "block";
	imgss[0].xOpacity = .99;
	
	setTimeout(so_xwfade,3000);
}

function so_xwfade() {
	cOpacity = imgss[curr].xOpacity;
	nIndex = imgss[curr+1]?curr+1:0;
	nOpacity = imgss[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgss[nIndex].style.display = "block";
	imgss[curr].xOpacity = cOpacity;
	imgss[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgss[curr]); 
	setOpacity(imgss[nIndex]);
	
	if(cOpacity<=0) {
		imgss[curr].style.display = "none";
		curr = nIndex;
		setTimeout(so_xwfade,1000);
	} else {
		setTimeout(so_xwfade,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) + ")";
	}
	
}
