// JavaScript Document
var Preloader = Class.create();

Preloader.prototype = {

  initialize:function()
  {
	this.bilder = new Array();
	this.amount = 0;
	this.totalcomplete = 0;
	this.intervalTime = 100;
	this.finished=false;
	this.doingCheck=false;
  },
  
  getImages:function() {
	return this.bilder;
  },
  
  
  load:function(img_name) {
    this.bilder[this.amount] = new Image();
	this.bilder[this.amount].completed = false;
    this.bilder[this.amount].src = img_name;
	this.amount++;
  },
  
  check:function() {
	  if(this.doingCheck == false)
	  {
		  //if not already checking preloading status, check
		  this.doingCheck = true;
		  this.counter = setTimeout(this['check'], this.intervalTime);
	  }
	  
	  if(this.amout == 0 && !this.finished) { return; }
	  
	  for(i=0; i < this.bilder.length; i++)
	  {
	  	if(this.bilder[i].complete)
		{
			this.bilder[i].completed = true;
			this.totalcomplete++;
		}
	  }
	  
	  //if all images are loaded, amout == totalcomplete, then stop Timeout
	  if(this.amount == this.totalcomplete) { 
	  	clearTimeout(this.counter);
		this.finished = true;
		return true;
	  }
  }
}