/*****

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 d=document, imgsF = new Array(), zInterval = null, currentF=0, pause=false;

function so_init() {
	if(!d.getElementById || !d.createElement)return;
	
	imgsF = d.getElementById("fotos").getElementsByTagName("img");
	for(i=1;i<imgsF.length;i++) imgsF[i].xOpacity = 0;
	imgsF[0].style.display = "block";
	imgsF[0].xOpacity = .99;
	
	setTimeout(so_xfadeF,4000);
}

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