function Preloader(images, callback)
{
    this.callback = callback;
    this.nLoaded = 0;
    this.nProcessed = 0;
    
    this.aImages = new Array;
    this.nImages = images.length;
    
    for(var i = 0; i<images.length; i++)
    {
      this.preload(images[i]);
    }
}


Preloader.prototype.preload = function(image)
{
  var oImage = new Image;
  this.aImages.push(oImage);
  
  oImage.onload = Preloader.prototype.onload;
  oImage.onerror = Preloader.prototype.onerror;
  oImage.onabort = Preloader.prototype.onabort;
  
  oImage.oPreloader = this;
  oImage.bLoader = false;
  oImage.src = image;
}

Preloader.prototype.onComplete = function()
{
  this.nProcessed++;
  if(this.nProcessed == this.nImages)
  {
    this.callback(this.aImages, this.nLoaded)
  }
}

Preloader.prototype.onload = function()
{
  this.bLoaded = true;
  this.oPreloader.nLoaded++;
  this.oPreloader.onComplete();
}

Preloader.prototype.onerror = function()
{
  this.bError = true;
  this.oPreloader.onComplete();
}

Preloader.prototype.onabort = function()
{
  this.bAbort = true;
  this.oPreloader.onComplete();
}
