
function ImagePreload( p_aImages, p_pfnPercent, p_pfnFinished ) {  
   // Call-back functions
   this.m_pfnPercent = p_pfnPercent;
   this.m_pfnFinished = p_pfnFinished;

   // Class Member Vars
   this.m_nLoaded = 0;
   this.m_nProcessed = 0;
   this.m_aImages = new Array;
   this.m_nICount = p_aImages.length;
   this.m_bPreloadComplete = false;

   // Preload Array of Images
   for( var i = 0; i < p_aImages.length; i++ )
       this.Preload( p_aImages[i] );
}

//this.Preload = function ( p_oImage ) {
ImagePreload.prototype.Preload = function( p_oImage ) {  
   var oImage = new Image;
   this.m_aImages.push( oImage );

   oImage.onload = ImagePreload.prototype.OnLoad;

   oImage.oImagePreload = this;  // Give the Image Object a Reference to our Class..
   oImage.bLoaded = false;       // Custom value added to track state
   oImage.source = p_oImage;     // Original Source Path to Image (for later use)
   oImage.src = p_oImage;        // Image Object Source Path
}

//this.OnComplete = function() {
ImagePreload.prototype.OnComplete = function() {
   this.m_nProcessed++;
   if ( this.m_nProcessed == this.m_nICount ) {
	   this.m_bPreloadComplete = true;
       this.m_pfnFinished();
   }
   else
       this.m_pfnPercent( Math.round( (this.m_nProcessed / this.m_nICount) * 10 ) );
   
   //this.m_nProcessed++;
}

//this.OnLoad = function() {
ImagePreload.prototype.OnLoad = function() {
   //$('#canvas-visible').after(this);
   // 'this' pointer points to oImage Object because this function was previously assigned
   // as an event-handler for the oImage Object.
   this.bLoaded = true;
   this.oImagePreload.m_nLoaded++; // Access our Class with the Reference assigned previously..
   this.oImagePreload.OnComplete();
}


//this.OnError = function() {   
ImagePreload.prototype.OnError = function() {
	// 'this' pointer points to oImage Object
   this.bError = true;
   this.oImagePreload.OnComplete();
}

//this.OnAbort = function() {   
ImagePreload.prototype.OnAbort = function() {   
	// 'this' pointer points to oImage Object
   this.bAbort = true;
   this.oImagePreload.OnComplete();
}



