ImagePreloader = function(images,callback) {
  this.init(images,callback);
}
$.extend(ImagePreloader.prototype, {
   // object variables


   init: function(images,callback) {
     // do initialization here
    this.images = images;
	this.callback = callback;
	this.imgarray = images.split(',');
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;
	this.nImages = this.imgarray.length;
	
	for (var i=0; i< this.imgarray.length;i++){
	path = this.imgarray[i];
	this.preload(path);
	}
   },

   preload: function(image) {
     	var oImage = new Image;
		this.aImages.push(oImage);
		// set up event handlers for the Image object
		oImage.onload = this.onload;
		oImage.onerror = this.onerror;
		oImage.onabort = this.onabort;
		// assign pointer back to this.
		oImage.oImagePreloader = this;
		oImage.bLoaded = false;		    
		// assign the .src property of the Image object
		oImage.src = image;
   },
	onComplete:function(){
		this.nProcessed++;
			if(this.nProcessed == this.nImages){
			this.callback(this.images);
			}
	},
	onload:function(){
		this.bLoaded = true;
		this.oImagePreloader.nLoaded++;
		this.oImagePreloader.onComplete();
	},
	onerror:function(){
		this.bError = true;		    
		this.oImagePreloader.onComplete();
	},
	onabort:function(){
		this.bAbort = true;
		this.oImagePreloader.onComplete();
	}
});

