/*****
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_init4,false):window.attachEvent("onload",so_init4);

var d4=document, imgs4=new Array(), zInterval=null, current4=0, pause=false;

function so_init4() {
	if(!d4.getElementById || !d4.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
	css4 = d4.createElement("link");
	css4.setAttribute("href","xfade4.css");
	css4.setAttribute("rel","stylesheet");
	css4.setAttribute("type","text/css");
	d4.getElementsByTagName("head")[0].appendChild(css4);

	imgs4 = d4.getElementById("baner4x").getElementsByTagName("img");
	for(i4=1;i4<imgs4.length;i4++) {
	
	imgs4[i4].xOpacity4 = 0;
	imgs4[i4].style.visibility = "hidden";
	}
	imgs4[0].style.visibility = "visible";
	imgs4[0].style.display = "block";
	imgs4[0].style.position = "absolute";
	imgs4[0].xOpacity4 = 1.0;
	
	setTimeout(so_xfade4,1000); // czas do pierwszej zmiany
}

function so_xfade4() {
	cOpacity4 = imgs4[current4].xOpacity4;
	nIndex4 = imgs4[current4+1]?current4+1:0;

	nOpacity4 = imgs4[nIndex4].xOpacity4;
	
	cOpacity4-=.05; 
	nOpacity4+=.05;
	
	imgs4[nIndex4].style.display = "block";
	imgs4[nIndex4].style.position = "absolute";
	imgs4[nIndex4].style.visibility = "visible";
	imgs4[nIndex4].style.left = "0px";
	imgs4[current4].xOpacity4 = cOpacity4;
	imgs4[nIndex4].xOpacity4 = nOpacity4;
	
	setOpacity4(imgs4[current4]);
	setOpacity4(imgs4[nIndex4]);
	
	if(cOpacity4<=0) {
		imgs4[current4].style.display = "none";
		imgs4[current4].style.position = "relative";
		current4 = nIndex4;
		setTimeout(so_xfade4,3000); // czas pomiedzy kolejnymi obrazkami
	} else {
		setTimeout(so_xfade4,25);
	}
	
	function setOpacity4(obj) {
		if(obj.xOpacity4>1.0) {
			obj.xOpacity4 = 1.0;
			return;
		}
		obj.style.opacity = obj.xOpacity4;
		obj.style.MozOpacity = obj.xOpacity4;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity4*100) + ")";
	}
}
