
/*** DO NOT EDIT BELOW THIS LINE ***/

var PreloadMeter=function(path, imgArray, textElemId, loadText, func)
{
 this.path=path;  
 this.imgArray=imgArray;
 this.textElemId=textElemId;
 this.textElem=document.getElementById(this.textElemId);
 this.loadText=loadText;
 this.func=func||null;
 this.totalSize=0;
 this.loadedAmount=0;
 this.imgCount=0;
 this.errorCount=0;
 this.buffer=[];
 
 this.init=function()
 {
  var imgName, imgSize, imgData, node;
  
  if(!this.textElem)
   alert('The element with ID \"'+this.textElemId+'\" was not found. (Case must match exactly)');  
  else
  {
   this.textElem.appendChild(document.createTextNode(this.loadText)) ;
    
   for(var i=0, len=this.imgArray.length; i<len; i++)   
   {
    imgData = this.imgArray[i].split('|');
    if(!imgData[1] || isNaN(imgData[1]) )
    {
     alert('Size not properly specified for \"'+imgData[0]+'\"');
     imgData[1]='0';
    }
    this.buffer[i] = {};
    this.buffer[i].img = new Image();
    this.buffer[i].fileSize = Number(imgData[1])||0;
    this.totalSize += this.buffer[i].fileSize;
    this.buffer[i].img.onload=function(inst, idx){return function(){inst.update(idx, true)}}(this, i);
    this.buffer[i].img.onerror=function(inst, idx){return function(){inst.update(idx, false)}}(this, i);
    this.buffer[i].img.src = this.path + imgData[0];    
   }
  } 
 }
 
 this.update=function(idx, result)
 {
  var pcLoaded=0, txt="";
  
  if(result)
  { 
   this.imgCount++;
   this.loadedAmount+=this.buffer[ idx ].fileSize;
  }
  else
   this.errorCount++;     
  
  txt=this.loadText + (pcLoaded=Math.round((this.loadedAmount/this.totalSize)*100)) +'%';
  
  this.textElem.firstChild.nodeValue = txt; 
  
  if(this.imgCount + this.errorCount == this.imgArray.length)
  {
   if(this.errorCount)
    txt += " [Failed:" + (100-pcLoaded) + '%]';  
   
   this.textElem.firstChild.nodeValue=txt;
    
   if(this.func)
    this.func();
  }
 }
 
 this.init(/*1938*/);
}
