function ImagePreloader(images,callback)
{
	// store the callback
	this.callback = callback;

	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;

	// record the number of images.
	this.nImages = images.length;
	
	if(typeof Array.prototype.push=='undefined')
    	Array.prototype.push=function(){
        	var
            	i=0,
            	b=this.length,
            	a=arguments;
        	for(i;i<a.length;i++)
            	this[b+i]=a[i];
        	return this.length
    	};


	// for each image, call preload()
	for ( var i = 0; i < images.length; i++ ) 
		this.preload(images[i]);
}
ImagePreloader.prototype.preload = function(image)
{
	//alert(' inner preload function called');
	// create new Image object and add to array
	var oImage = new Image;
	
	this.aImages.push(oImage);
	//alert('error check of inner preload function');
	// set up event handlers for the Image object
	oImage.onload = ImagePreloader.prototype.onload;
	oImage.onerror = ImagePreloader.prototype.onerror;
	oImage.onabort = ImagePreloader.prototype.onabort;
	
	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;
	oImage.source = image;
	
	// assign the .src property of the Image object
	oImage.src = image;
	
}
ImagePreloader.prototype.onComplete = function()
{
	this.nProcessed++;
	if ( this.nProcessed == this.nImages ){
		//alert('processed all');
		this.callback(this.aImages);
		
	}
}
ImagePreloader.prototype.onload = function()
{
	this.bLoaded = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.onComplete();
	//alert('image loaded # ' + this.oImagePreloader.nLoaded);
}
ImagePreloader.prototype.onerror = function()
{
	//alert('on error');
	this.bError = true;
	this.oImagePreloader.onComplete();
}
ImagePreloader.prototype.onabort = function()
{
	//alert('abort');
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}
