function CImagePreloader(cbfn)
{
	// store the call-back
	this.cbfn = cbfn;
	
	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.aImages = new Array;
}

CImagePreloader.prototype.preload = function(aImages)
{
  // record the number of images.
	this.nImages = aImages.length;
	
	// for each image, call preload()
	for (var i=0; i < aImages.length; i++) {
		this.preloadImage(aImages[i]);
	}
}

CImagePreloader.prototype.preloadImage = function(ImageUrl)
{
	// create new Image object and add to array
	var oImage = new Image();
	
	// set up event handlers for the Image object
	oImage.onload  = CImagePreloader.prototype.onload;
	oImage.onerror = CImagePreloader.prototype.onerror;
	oImage.onabort = CImagePreloader.prototype.onabort;

	// assign pointer back to this.
	oImage.oImagePreloader = this;
	oImage.bLoaded = false;

	// assign the .src property of the Image object
	oImage.src = ImageUrl;
	
	// Attach to array
	this.aImages.push(oImage);
}

CImagePreloader.prototype.onComplete = function()
{
	this.nProcessed++;
	if (this.nProcessed == this.nImages) {
		this.cbfn();
	}
}

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

CImagePreloader.prototype.onerror = function()
{
	this.bError = true;
	this.oImagePreloader.onComplete();
}

CImagePreloader.prototype.onabort = function()
{
	this.bAbort = true;
	this.oImagePreloader.onComplete();
}
