/* 
// ImageLoader v1.1a (c) 2002 by TR
//
// IMPLEMENTATION
//
// 1) Insert Code within Head

<SCRIPT LANGUAGE=javascript type="text/javascript" src="imgloader.js"></SCRIPT>
<style>
<!--
.lbContainer { font-family: Verdana, sans-serif; font-size: 8pt; text-align: center; margin: 0px }
.lbContainer A { text-decoration: none }
.lbContainer A:hover { text-decoration: underline }
.lbBox       { text-align: left; background-color: #C0C0C0; margin-top: 3px; margin-bottom: 3px; margin-left: auto; margin-right: auto; padding: 0px; border-style: solid; border-width: 1px; border-color: black }
.lbBar       { background-color: blue; font-size: 0px; margin: 1px }
-->
</style>

// 2.) Define EventHandler which calls LoadImages() function
//     (for example when page was loaded)

<SCRIPT LANGUAGE=javascript type="text/javascript">
<!--
function window_onload() {
	ilLoadImages();
	// window.setTimeout("ilLoadImages()",3000);
}
window.onload = window_onload;
//-->
</SCRIPT>
<body>

// 3. Insert script with definitions and lbInsert() function
// somewhere on the Page with alternate HTML if Browser doesnt support scripts

<SCRIPT LANGUAGE=javascript type="text/javascript">
<!--
	ilImages = "1.gif, 2.gif, 3.gif";
	ilPath = "subdir1/subdir2";
	ilNextUrl = "loadbar.htm";
	ilLoadUrl = false;
	ilMsgLoading = "Loading ...";
	ilMsgFinished = "Finished Loading";
	ilMsgLoadUrl = "Loading next page ...";
	ilUrlText = "Click here for next Page";
	ilShowPercent = true;
	lbWidth = 200;
	lbHeight = 8;
	lbVisibility = "visible|hidden";
	lbInsert();
//-->
</SCRIPT>
<NOSCRIPT>
<p><a href="nextpage.htm">Click here to load next page</a></p>
</NOSCRIPT>

*/

// GENERAL FUNCTIONS

// Public Variables
var ilImages = "";
var ilPath = "";
var ilNextUrl = "";
var ilLoadUrl = false;
var ilMsgLoading = "Lade ...";
var ilMsgFinished = "Fertig";
var ilMsgLoadUrl = "Lade nächste Seite ...";
var ilUrlText = "Hier klicken für weiter";
var ilShowPercent = true;
var lbWidth = 200;
var lbHeight = 8;
var lbVisibility = "visible";

// Private Variables
var ilFileList = null;
var ilImageList = null;
var ilImagesTotal = 0;
var ilImageCount = 0;
var lbEnabled = false;

function lbInsert() {

	var str = "";
	if (!document.getElementById) {
		str = "<p><a href='" + ilNextUrl + "'>"+ilUrlText+"</a></p>";
		lbEnabled = false;
	}
	else {
		str = "<div id='lbContainer' class='lbContainer' style='visibility:"+lbVisibility+"'>";
		str += "<span id='lbText'>&nbsp;</span>";
		str += "<div id='lbBox' class='lbBox' style='width: "+(lbWidth+4)+"px'>";
		str += "<div id='lbBar' class='lbBar' style='width: 0px; height: "+lbHeight+"px'>";
		str += "</div></div></div>";
		lbEnabled = true;
	}
	document.write(str);
}

function lbUpdateHtml(html) {
	document.getElementById("lbText").innerHTML = html;
}

function lbUpdate() {
	var str;	
	if (ilImageCount<ilImagesTotal) {
		ilImageCount++;
		var p = Math.round(ilImageCount/ilImagesTotal*100);
		str = ilMsgLoading;
		str += (ilShowPercent) ? (" "+p+"%"):"";
		
		if (lbEnabled) {
			lbUpdateHtml(str);
			var w = Math.round(lbWidth*p/100);
			document.getElementById("lbBar").style.width = w;
		}
		window.status = str;
	}
	if (ilImageCount>=ilImagesTotal) {
		str = ilMsgFinished;
		if (lbEnabled) lbUpdateHtml(str);
		window.status = str;
		
		if (ilLoadUrl && (ilNextUrl != "")) {
			str = ilMsgLoadUrl;
			if (lbEnabled)
				lbUpdateHtml(str);
			window.status = str;
			self.location = ilNextUrl;
		}
		else {
			if (lbEnabled)
				lbUpdateHtml("<a href="+ilNextUrl+">"+ilUrlText+"</a>");
		}
	}
}

function ilLoadImages() {

	ilImages = ilImages.replace(/\s*/gi,"");
	ilFileList = ilImages.split(",");
	ilImagesTotal = ilFileList.length;
	ilImageCount = 0;

	delete ilImageList;
	ilImageList = new Array(ilImagesTotal);
	
	if (lbEnabled)
		document.getElementById("lbContainer").style.visibility = "visible";

	var i;
	for (i=0; i<ilImagesTotal; i++) {
		ilImageList[i] = new Image();
		ilImageList[i].id = "img" + i;
		ilImageList[i].onerror = lbUpdate;
		ilImageList[i].onload = lbUpdate;
		ilImageList[i].oncancel = lbUpdate;
		ilImageList[i].src = ilPath + ilFileList[i];
	}
}
