/*****

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 adds = new Array(), zInterval = null, current=0, pause=false;

function so_init() {
	d=document;
	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","/xfade/xfade2.css");
//	css.setAttribute("rel","stylesheet");
//	css.setAttribute("type","text/css");
//	d.getElementsByTagName("head")[0].appendChild(css);

//	adds = d.getElementById("AddsContainer").getElementsById("Adds");
	i=0;
	while(tmp=d.getElementById("Adds"+i)) {
//		alert("Adds"+i);
		adds[i]=tmp;
		adds[i].xOpacity = 0;
		i=i+1;
	}
	adds[0].style.display = "block";
	adds[0].xOpacity = .99;

	setTimeout(so_xfade,5000);
}

function so_pause(sopause) {
	pause=sopause;
}

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

	nOpacity = adds[nIndex].xOpacity;

	if (!pause) {

		cOpacity-=.05;
		nOpacity+=.05;

		adds[nIndex].style.display = "block";
		adds[current].xOpacity = cOpacity;
		adds[nIndex].xOpacity = nOpacity;

		setOpacity(adds[current]);
		setOpacity(adds[nIndex]);

		if(cOpacity<=0) {
			adds[current].style.display = "none";
			current = nIndex;
			setTimeout(so_xfade,5000);
		} else {
			setTimeout(so_xfade,50);
		}

	} else {
		if (cOpacity>=.50) {
			cOpacity=.99;
			nOpacity=0;
			adds[current].xOpacity = cOpacity;
			adds[nIndex].xOpacity = nOpacity;
			setOpacity(adds[current]);
			setOpacity(adds[nIndex]);
			adds[current].style.display = "block";
			adds[nIndex].style.display = "none";
		} else {
			cOpacity=0;
			nOpacity=.99;
			adds[current].xOpacity = cOpacity;
			adds[nIndex].xOpacity = nOpacity;
			setOpacity(adds[current]);
			setOpacity(adds[nIndex]);
			adds[current].style.display = "none";
			adds[nIndex].style.display = "block";
		}
		setTimeout(so_xfade,1000);
	}

	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) + ")";
	}

}

