var preloader = 
{
  //-------------------------------------------------------------------------
  container : null,
  callbacks : {
                allDone : null,
                imgDone : null
              },
  doneCount : 0,
  imgCount  : 0,
  
  //-------------------------------------------------------------------------
  start : function(_srcArray, _callbackAllDone, _callbackImgDone)
  {
    //check if preloader still busy
    if (this.container)
      return false;
    
    //remember callbacks
    this.callbacks.allDone  = _callbackAllDone;
    this.callbacks.imgDone  = _callbackImgDone;
    
    //create invisible container
    this.container = document.createElement("div");
    this.container.style.display = "none";
    document.body.appendChild(this.container);
    
    //set counters
    this.doneCount  = 0;
    this.imgCount   = _srcArray.length;
    
    //create img elements
    var html = "";
    for (var idx=0; idx<this.imgCount; idx++)
      html += '<img src="'+_srcArray[idx]+'" onload="preloader.imageLoaded();" />';
    this.container.innerHTML = html;
    
    return true;
  },
  
  //-------------------------------------------------------------------------
  imageLoaded : function()
  {
    //count all loaded images
    this.doneCount++;
    
    //do image-done callback
    if (this.callbacks.imgDone)
      this.callbacks.imgDone();
    
    //check if all is done
    if (this.doneCount == this.imgCount)
    {
      //clear all html
      document.body.removeChild(this.container);
      this.container = null;
      
      //do all-done callback
      if (this.callbacks.allDone)
        this.callbacks.allDone();
    }
  },
  
  //-------------------------------------------------------------------------
  getPercentage : function()
  {
    return Math.round((this.doneCount / this.imgCount) * 100);
  }
  
  //-------------------------------------------------------------------------
};