/*****

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_initc,false):window.attachEvent("onload",so_initc);

var dc=document, imgsc=new Array(), currentc=0;
var velocidadc=6000;

function so_initc() {
	if(!dc.getElementById || !dc.createElement)return;
	
	css = dc.createElement("link");
	css.setAttribute("href",raiz + "xfade2c.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	dc.getElementsByTagName("head")[0].appendChild(css);

	//Josema 25/06/2007	
	dc.getElementById("imageContainerc").style.visibility="visible";
	dc.getElementById("imageContainerc").style.display="block";
	
	imgsc = dc.getElementById("imageContainerc").getElementsByTagName("img");
	if(imgsc.length>0){
		for(i=1;i<imgsc.length;i++) imgsc[i].xOpacity = 0;
		imgsc[0].style.display = "block";
		imgsc[0].xOpacity = .99;
		
		setTimeout(so_xfadec,velocidadc);
	}
}

function so_xfadec() {
	cOpacity = imgsc[currentc].xOpacity;
	nIndex = imgsc[currentc+1]?currentc+1:0;

	nOpacity = imgsc[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgsc[nIndex].style.display = "block";
	imgsc[currentc].xOpacity = cOpacity;
	imgsc[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgsc[currentc]); 
	setOpacity(imgsc[nIndex]);
	
	if(cOpacity<=0) {
		imgsc[currentc].style.display = "none";
		currentc = nIndex;
		setTimeout(so_xfadec,velocidadc);
	} else {
		setTimeout(so_xfadec,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) + ")";
	}
	
}