function ImagePreloader(callback) {
	// store the call-back
	this.callback = callback;
	
	// initialize internal state.
	this.nLoaded = 0;
	this.nProcessed = 0;
	this.nError = 0;
	this.nAbort = 0;
	this.aImages = new Array;
	this.loadedImages = new Array;
	this.startDisplay = 0;
}

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

var pCount = 0;

ImagePreloader.prototype.preloadSingle = function(imageNode) {
	// create new Image object and add to array
	var oImage = new Image;
	this.aImages.push(oImage);

	// 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;

	// assign the .src property of the Image object
	
	var randomnumber=Math.floor(Math.random()*1000000);

	oImage.src = imageNode.getAttribute('src');
	oImage.width = imageNode.getAttribute('width');
	oImage.height = imageNode.getAttribute('height');
	
	pCount++;
		
	oImage.imageNode = imageNode;
}

ImagePreloader.prototype.onload = function() {
	this.bLoad = true;
	this.oImagePreloader.nLoaded++;
	this.oImagePreloader.nProcessed++;
	this.oImagePreloader.callback(this);
}

ImagePreloader.prototype.onerror = function() {
	this.bError = true;
	this.oImagePreloader.nError++;
	this.oImagePreloader.nProcessed++;
	this.oImagePreloader.callback(this);
}

ImagePreloader.prototype.onabort = function() {
	this.bAbort = true;
	this.oImagePreloader.nAbort++;
	this.oImagePreloader.nProcessed++;
	this.oImagePreloader.callback(this);
}
