/* ROTATOR */
/* milo ze chcesz zobaczyc jak to dziala :) */

var rotateTime = 5000;
var rotateBannerOpacity = 1;
var banners = new Array();
var banners2 = new Array();
var zindex_start = 30;
var objInterval;

function rotateBgInit(){
	rotateBannerOpacity = 1;
	objInterval = setInterval("rotateOpacity()", 20); // wykonujemy ciagle	
}

function rotateAdd(id){
	banners.push(id);
	banners2 = banners.slice(0); // tworzymy kopie tablicy
}

function rotateOpacity(){	
	opa = document.getElementById(banners[0]);
	if(rotateBannerOpacity == 1){
		opa.style.zIndex = ++zindex_start;
		//Gdy ostatni banner, to nalezy pokazac banner nr 1
		if(banners.length==1){
			opa2 = document.getElementById(banners2[0]);	
			opa2.style.opacity = 1;
	        opa2.style.filter = "alpha(opacity = "+1*100+")";	
		}
		// Gdy mamy jeszcze bannery w wektorze, to pokazujemy nastepny
		if (banners.length > 1) {
			opa2 = document.getElementById(banners[1]);	
			opa2.style.opacity = 1;
	        opa2.style.filter = "alpha(opacity = "+1*100+")";
		}		
		rotateBannerOpacity -= 0.1;	// Zmniejszamy widocznosc aktualnego bannera
	}
	if(rotateBannerOpacity < 1 && rotateBannerOpacity > 0){
		rotateBannerOpacity -= 0.1;
		if (rotateBannerOpacity < 0) rotateBannerOpacity = 0;
		opa.style.opacity = rotateBannerOpacity;
        opa.style.filter = "alpha(opacity = "+rotateBannerOpacity*100+")";
	}
	else{		
		clearInterval(objInterval);	// czyscimy handlera 					
		setTimeout("rotateChange()", 20);
	}
}

function rotateChange(){			
	last = banners.shift(); //usuwamy pierwszy banner z wektora
	if(banners.length==0){
		banners = banners2.slice(0); //jesli usunelismy wszystkie bannery to przywracamy kopie
	}
	setTimeout("rotateBgInit()", rotateTime);
}

jQuery(document).ready(function() {
	// oparte o jquery ale w zasadzie moznaby bez :)
    setTimeout("rotateBgInit()", rotateTime);
});
