/*****

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_initb,false):window.attachEvent("onload",so_initb);

var db=document, imgsb=new Array(), currentb=0;
var velocidadb=3400;

function so_initb() {
	if(!db.getElementById || !db.createElement)return;
	
	css = db.createElement("link");
	css.setAttribute("href",raiz + "xfade2b.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	db.getElementsByTagName("head")[0].appendChild(css);

	//Josema 25/06/2007	
	db.getElementById("imageContainerb").style.visibility="visible";
	db.getElementById("imageContainerb").style.display="block";
	
	imgsb = db.getElementById("imageContainerb").getElementsByTagName("img");
	if(imgsb.length>0){
		for(i=1;i<imgsb.length;i++) imgsb[i].xOpacity = 0;
		imgsb[0].style.display = "block";
		imgsb[0].xOpacity = .99;
		
		setTimeout(so_xfadeb,velocidadb);
	}
}

function so_xfadeb() {
	cOpacity = imgsb[currentb].xOpacity;
	nIndex = imgsb[currentb+1]?currentb+1:0;

	nOpacity = imgsb[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgsb[nIndex].style.display = "block";
	imgsb[currentb].xOpacity = cOpacity;
	imgsb[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgsb[currentb]); 
	setOpacity(imgsb[nIndex]);
	
	if(cOpacity<=0) {
		imgsb[currentb].style.display = "none";
		currentb = nIndex;
		setTimeout(so_xfadeb,velocidadb);
	} else {
		setTimeout(so_xfadeb,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) + ")";
	}
	
}