/*****

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

var xf_imgs = new Array(), xf_current=0;

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

/*
	css = document.createElement("link");
	css.setAttribute("href","http://export.acces-adulte.com/xfade/xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	document.getElementsByTagName("head")[0].appendChild(css);
*/

	xf_imgs = document.getElementById("xfade_container").getElementsByTagName("img");
	for(i=0;i<xf_imgs.length-1;i++) { xf_imgs[i].style.display = "none"; xf_imgs[i].xOpacity = 0; }
	xf_imgs[xf_imgs.length-1].style.display = "block";
	xf_imgs[xf_imgs.length-1].xOpacity = .99;
	xf_current = xf_imgs.length-1;

	setTimeout(xf_so_xfade,1000);
}

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


function xf_so_xfade() {
	cOpacity = xf_imgs[xf_current].xOpacity;
	nIndex = xf_imgs[xf_current+1]?xf_current+1:0;
	nOpacity = xf_imgs[nIndex].xOpacity;

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

	xf_imgs[nIndex].style.display = "block";
	xf_imgs[xf_current].xOpacity = cOpacity;
	xf_imgs[nIndex].xOpacity = nOpacity;

	xf_setOpacity(xf_imgs[xf_current]);
	xf_setOpacity(xf_imgs[nIndex]);

	if(cOpacity<=0) {
		xf_imgs[xf_current].style.display = "none";
		xf_current = nIndex;
		setTimeout(xf_so_xfade,1000);
	} else {
		setTimeout(xf_so_xfade,50);
	}
}
