var Imgs = new Array();
var errors = 0;
var postep = 0;
var afterLoadURL="";
var URLs = new Array(
	"templates/html/bg_cover.jpg",
	"templates/html/book.gif",
	"templates/html/klucz.jpg"
);

function Sprawdz(){
	var notcompl = 0;
	var compl = 0;
	var w = Imgs.length;

	for (var i=0; i<w; i++){
    	if (Imgs[i].complete){compl++;}else{notcompl++;}
	}

	postep = Math.ceil(compl/w*100);

	document.getElementById('PSTAT').innerHTML=postep+"%";
	document.getElementById('PBAR').style.width=((postep!=0) ? (postep)*2 : 2);
	document.getElementById('PBAR2').style.width=((postep!=0) ? 200-(postep)*2 : 198);

	if(notcompl > errors){
		setTimeout("Sprawdz();", 200);
	}else if(notcompl == 0){
		setTimeout("top.location.replace('"+afterLoadURL+"')", 200);
	}else if(notcompl == errors){
		document.getElementById('PINFO').innerHTML='Błąd podczas wczytywania. Proszę kliknąć <A href="' + afterLoadURL + '">tutaj</A>.';
	}
}

function Laduj(url){
    	var i = Imgs.length;
		Imgs[i] = new Image();
		Imgs[i].onerror = function (){errors++;}
		Imgs[i].src = url;
}

function Init()
{
	document.getElementById('PINFO').innerHTML = "&nbsp";
	
	var HTMLElementCollection = document.getElementsByTagName("META");
	var done = 0;
	for(a=0;a<HTMLElementCollection.length;a++){
		var Element = HTMLElementCollection[a];
		if(Element.name.toUpperCase()=="GOTOURL"){
			afterLoadURL = Element.content;
			done++;
		}
		/*if(Element.name.toUpperCase()=="MYLANG"){
			URLs[URLs.length] = "templates/html/lang/" + Element.content + "/t_lista_linii.gif";
			URLs[URLs.length] = "templates/html/lang/" + Element.content + "/t_lista_przystankow.gif";
			URLs[URLs.length] = "templates/html/lang/" + Element.content + "/t_przystanek.gif";
			done++;
		}*/
		if(done==1)break;
	}
	
	setTimeout("document.getElementById('PINFO').innerHTML = 'Jeżeli serwis nie zostanie wczytany w ciągu klikunastu sekund, proszę kliknąć <A href=\"" + afterLoadURL + "\">tutaj</A>.';", 35000);
	
	if(document.images && URLs.length>0){
		for(i in URLs)Laduj(URLs[i]);
		Sprawdz();
	}else{
		top.location.replace(afterLoadURL);
	}
}