/*
 +-------------------------------------------------------------------+
 |                    J S - I L O A D E R   (v1.1)                   |
 |                          P a r t   II                             |
 |                                                                   |
 | Copyright Gerd Tentler                www.gerd-tentler.de/tools   |
 | Created: Dec. 6, 2006                 Last modified: Apr. 9, 2007 |
 +-------------------------------------------------------------------+
 | This program may be used and hosted free of charge by anyone for  |
 | personal purpose as long as this copyright notice remains intact. |
 |                                                                   |
 | Obtain permission before selling the code for this program or     |
 | hosting this software on a commercial website or redistributing   |
 | this software over the Internet or in any other medium. In all    |
 | cases copyright must remain intact.                               |
 +-------------------------------------------------------------------+

======================================================================================================
 This script was tested with the following systems and browsers:

 - Windows XP: IE 6, NN 7, Opera 7, Firefox 1
 - Mac OS X:   IE 5

 If you use another browser or system, this script may not work for you - sorry.

 NOTE: Safari 1 (Mac OS X) does not support "document.images[].complete", so the loading image will
       not be shown.
======================================================================================================
*/
  function ILOADER() {
    this.iv, this.timer;
    this.imgAll = this.opacity = 0;

    this.getObj = function(id) {
      var obj;
      if(document.getElementById) obj = document.getElementById(id);
      else if(document.all) obj = document.all[id];
      return obj;
    }

    this.setOpacity = function(obj, opacity) {
      if(obj && !document.layers) {
        obj.style.opacity = opacity / 100;
        obj.style.MozOpacity = opacity / 100;
        obj.style.KhtmlOpacity = opacity / 100;
        obj.style.filter = 'alpha(opacity=' + opacity + ')';
      }
    }

    this.fadeIn = function(id) {
      var obj = this.getObj(id);
      if(obj) {
        if(document.all) obj.style.position = 'absolute';
        obj.style.visibility = 'visible';
        if(fadeInSpeed && this.opacity < 100) {
          this.opacity += fadeInSpeed;
          if(this.opacity > 100) this.opacity = 100;
          this.setOpacity(obj, this.opacity);
          if(this.timer) clearTimeout(this.timer);
          this.timer = setTimeout("iloader.fadeIn('" + id + "')", 1);
        }
        else {
          this.opacity = 100;
          this.setOpacity(obj, 100);
        }
      }
    }

    this.checkImages = function() {
      if(this.imgAll < document.images.length) this.imgAll = document.images.length;
      for(var i = cnt = 0; i < this.imgAll; i++) {
        if(document.images[i] && document.images[i].complete) cnt++;
        else if(document.images[i].complete == null) cnt++;
      }
      window.status = cnt + ' / ' + this.imgAll;
      if(cnt >= this.imgAll) {
        if(this.iv) clearInterval(this.iv);
        setTimeout('iloader.loaded()', 100);
      }
    }

    this.init = function() {
      if(document.images && document.images.length) {
        if(this.iv) clearInterval(this.iv);
        this.iv = setInterval('iloader.checkImages()', 100);
      }
      else iloader.loaded();
    }

    this.loaded = function() {
      window.status = '';
      this.fadeIn('Content');
      var obj = this.getObj('divImage');
      obj.style.visibility = 'hidden';
    }
  }

//----------------------------------------------------------------------------------------------------
// Show loading image
//----------------------------------------------------------------------------------------------------

  if((document.all || document.getElementById) && !safari) {
    document.write('</div>');
    var iloader = new ILOADER();
    iloader.init();
  }

//----------------------------------------------------------------------------------------------------
