// JavaScript Document
function newDiv(id, style){
	var div = document.createElement("div");
	div.setAttribute("id", id);
	if (document.all && !document.captureEvents)
		div.style.setAttribute("cssText", style, 0);
	else
		div.setAttribute("style", style);
	
	return div;
}

function preLoader(images, pfad){
	this.Pfad = pfad;
	this.Images = images;
	this.ImagesCount = images.length;
	this.PreLoaderDiv = null;
	this.LoadInterval = null;
	this.StatusInfoObject = null;
	this.OnLoaded = null;
	this.LoadLineObject = null;
	this.LoadLineMaxWidth = 300;
	this.OnImageLoaded = null;
	this.ImagesLoaded = 0;
}

preLoader.prototype.StartLoad = function(){
	var div = newDiv("preLoadDiv", "position:absolute; left:0px; top:0px; width:1px; height:1px; overflow:hidden; opacity:0; filter:Alpha(opacity=0);");
	div.preLoader = this;
	
	for(var i = 0; i < this.ImagesCount; i++){
		var img = document.createElement("img");
		img.src = this.Pfad + "/" + this.Images[i];
		div.appendChild(img);
	}
	
	document.getElementsByTagName("body")[0].appendChild(div);
	this.PreLoaderDiv = div;
	
	this.LoadInterval = window.setInterval("document.getElementById('preLoadDiv').preLoader.checkStatus();", 100);
}


preLoader.prototype.checkStatus = function(){
	var images = this.PreLoaderDiv.getElementsByTagName("img");
	var loadedImages = 0;
	
	for(var i = 0; i < images.length; i++){
		if(images[i].complete)
			loadedImages++;
	}
	this.ImagesLoaded = loadedImages;
	
	if(this.StatusInfoObject != null)
		this.StatusInfoObject.innerHTML = Math.floor((100 / this.ImagesCount) * loadedImages) + "%";
	
	if(this.LoadLineObject != null)
		this.LoadLineObject.style.width = ((this.LoadLineMaxWidth / this.ImagesCount) * loadedImages) + "px";
	
	if(this.OnImageLoaded != null)
		eval(this.OnImageLoaded);
	
	if(loadedImages == this.ImagesCount){
		window.clearInterval(this.LoadInterval);
		this.LoadInterval = null;
		
		if(this.OnLoaded != null){
			eval(this.OnLoaded);
		}
	}
}
