
/*  Preloader */



function Preloader_Object(id)
{
  //public
  this.Id = id;
  this.Images = new Array();
  this.ImagesSize = new Array();
  this.fnError = "";
  this.fnOK = "";
  this.fnDraw = "";
  this.Errors = 0;
  this.Loaded = 0;
  this.LoadedSize = 0;
  this.SizeToLoad = 0;
  this.Time = 250;
  this.Counting = 0;

  // private
  this.PreloadTimer="";

  this.LoadImage = function (url,size)
  {
   if (document.images)
      {
      var i = this.Images.length;
      this.Images[i] = new Image();
      this.Images[i].onerror = this.PreloadOnError;
      this.Images[i].src = url;
      this.ImagesSize[i] = size;
      }
  }

  this.PreloadOnError = function (i)
  {
    this.Errors++;
  }

  this.Start = function (fnok, fnerr,fndraw)
  {
    this.fnOK = fnok;
    this.fnError = fnerr;
    this.fnDraw = fndraw;
    this.PreloadCheck();
  }

  this.PreloadCheck = function ()
  {
    var i = 0;
    this.Loaded = 0;
    this.LoadedSize = 0;
    this.SizeToLoad = 0;
    for(i=0;i<this.Images.length;i++)
      {
      this.SizeToLoad += this.ImagesSize[i];
      if (this.Images[i].complete)
        {
        this.LoadedSize += this.ImagesSize[i];
        this.Loaded++;
        }
      }
    eval(this.fnDraw);
    if (this.Loaded+this.Errors>=this.Images.length)
    // gdy wloadowano wywoluje fn dot. błędu lub dalszych instrukcji
      {
      window.clearTimeout(this.PreloadTimer);
      if (this.Errors==0) eval(this.fnOK)
                     else eval(this.fnError)
      }
    else
    // gdy nie wloadowano ponownie sprawdzacza
      {
      this.Counting += this.Time;
      this.PreloadTimer = window.setTimeout(this.Id+'.PreloadCheck()',this.Time);
      }
  }

}



window.preloader = new Preloader_Object("window.preloader");





