

function ImageLoader (imageUrls, loadHandler)
{
   this.imageUrls = imageUrls;
   this.loadHandler = loadHandler;
   this.loadedImages = 0;
   this.abortedImages = 0;
   this.images = new Array(this.imageUrls.length);
   for (var i = 0; i < this.imageUrls.length; i++)
   {
     this.images[i] = new Image();
     this.images[i].imageLoader = this;
     this.images[i].onload = this.loaded;
     this.images[i].onerror = this.aborted;
     this.images[i].src = imageUrls[i];
   }
}

ImageLoader.prototype.loaded = function(evt)
{
   var imageLoader = this.imageLoader;
   imageLoader.loadedImages++;
   imageLoader.checkAll();
};


ImageLoader.prototype.aborted = function(evt)
{
   var imageLoader = this.imageLoader;
   imageLoader.abortedImages++;
   imageLoader.checkAll();
};

ImageLoader.prototype.checkAll = function()
{
   if (this.loadedImages + this.abortedImages === this.images.length)
   {
     this.loadHandler(this.images);
   }
};