var loadBarWidth        = 334;     // Groessen.
var loadBarBorderWidth  =   1;
var loadBarPaddingWidth =   2;

var loadBarText = "Lade Grafiken ...";    // Text in der Leiste.
var loadBarFgColor     = "#333300";        // Farben.
var loadBarBgColor     = "#ffffff";
var loadBarBorderColor = "#000000";

var loadBarFontFamily   = "Arial,Helvetica,sans-serif";    // Schrift.
var loadBarFontStyle    = "plain";
var loadBarFontWeight   = "bold";
var loadBarFontSize     = "10pt";

// Initialize load bar and start loading images.

var loadBar;        // Handles to layers
var loadBarLow;
var loadBarHigh;

var loadBarHeight;    // Load bar height.

var loadBarImgList;     // Array of images to download.
var loadBarImgCount;    // Number of images that have completed loading.

function loadBarStart(srcList, x, y) {

  var i, w, h;

  if (!isMinNS4 && !isMinIE4)
    return;

  // Build the load bar if not already done.

  if (!loadBar)
    loadBarBuild();

  // Get handles to the nested layers.

  loadBarLow  = getLayer("loadbarlow");
  loadBarHigh = getLayer("loadbarhigh");

  // Get the height of the load bar.

  loadBarHeight = getHeight(loadBarLow);

  // Position and set initial clipping regions of nested layers.

  moveLayerTo(loadBarLow, 0, 0);
  moveLayerTo(loadBarHigh, 0, 0);
  if (isMinIE4)
    clipLayer(loadBar, 0, 0, loadBarWidth, loadBarHeight);
  clipLayer(loadBarLow, loadBarBorderWidth,  loadBarBorderWidth,
            loadBarWidth - loadBarBorderWidth,
            loadBarHeight - loadBarBorderWidth);
  clipLayer(loadBarHigh, loadBarBorderWidth,  loadBarBorderWidth,
            loadBarBorderWidth, loadBarHeight - loadBarBorderWidth);

  // Initialize and display the load bar.

  if (isMinNS4) {
    w = window.innerWidth;
    h = window.innerHeight;
  }
  if (isMinIE4) {
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
  if (x == null)
    x = Math.round((w  - loadBarWidth)  / 2);
  if (y == null)
    y = Math.round((h - loadBarHeight) / 2);
  moveLayerTo(loadBar, x, y);
  showLayer(loadBar);

  // Initialize image counter.

  loadBarImgCount = 0;

  // Start loading images.

  loadBarImgList = new Array();
  for (i = 0; i < srcList.length; i++) {
    loadBarImgList[i] = new Image();
    loadBarImgList[i].onabort = loadBarUpdate;
    loadBarImgList[i].onerror = loadBarUpdate;
    loadBarImgList[i].onload  = loadBarUpdate;
    loadBarImgList[i].src = srcList[i];
  }
}

//----------------------------------------------------------------------------
// Create the load bar.
//----------------------------------------------------------------------------

function loadBarBuild() {

  var lowText, highText, tblStart, tblEnd;
  var padding;
  var str;
  var x, y;

  // Set up code for load bar text.

  padding = loadBarPaddingWidth + loadBarBorderWidth;

  lowText  = 'color:' + loadBarFgColor + ';'
           + 'font-family:' + loadBarFontFamily + ';'
           + 'font-size:' + loadBarFontSize + ';'
           + 'font-style:' + loadBarFontStyle + ';'
           + 'font-weight:' + loadBarFontWeight + ';';
  highText = 'color:' + loadBarBgColor + ';'
           + 'font-family:' + loadBarFontFamily + ';'
           + 'font-size:' + loadBarFontSize + ';'
           + 'font-style:' + loadBarFontStyle + ';'
           + 'font-weight:' + loadBarFontWeight + ';';
  tblStart = '<table border=0 cellpadding=' + padding
           + ' cellspacing=0 width="100%"><tr valign=center><td align=center>';
  tblEnd   = '</td></tr></table>';
  if (isMinNS4)
          str = '<layer name="loadbarlow"'
              + ' bgcolor="' + loadBarBgColor + '"'
              + ' width=' + loadBarWidth
              + ' visibility=inherit>' + tblStart
              + '<span style="' + lowText + '">' + loadBarText
              + '</span>' + tblEnd + '</layer>\n'
              + '<layer name="loadbarhigh"'
              + ' bgcolor="' + loadBarFgColor + '"'
              + ' width=' + loadBarWidth
              + ' visibility=inherit>' + tblStart
              + '<span style="' + highText + '">' + loadBarText
              + '</span>' + tblEnd + '</layer>\n';
  if (isMinIE4)
          str = '<div id="loadbarlow"'
              + ' style="position:absolute;'
              + ' background-color:' + loadBarBgColor + ';'
              + ' loadBarWidth:' + loadBarWidth + 'px;">' + tblStart
              + '<span style="' + lowText + '">' + loadBarText
              + '</span>' + tblEnd + '</div>\n'
              + '<div id="loadbarhigh"'
              + ' style="position:absolute;'
              + ' background-color:' + loadBarFgColor + ';'
              + ' loadBarWidth:' + loadBarWidth + 'px;">' + tblStart
              + '<span style="' + highText + '">' + loadBarText
              + '</span>' + tblEnd + '</div>\n';

  // Create it as a new layer.

  if (isMinNS4) {
    loadBar = new Layer(loadBarWidth);
    loadBar.document.writeln(str);
    loadBar.document.close();
  }
  if (isMinIE4) {
    str = '<div id="loadBar" style="position:absolute;'
        + ' width:' + loadBarWidth + 'px;'
        + ' height:100%">'
        + str + '</div>\n';

    // Insert HTML code at end of page. For IE4, need to scroll window to
    // end of page, insert and scroll back to correct bug.

    if (!isMinIE5) {
      x = getPageScrollX();
      y = getPageScrollY();
      window.scrollTo(getPageWidth(), getPageHeight());
    }
    document.body.insertAdjacentHTML("beforeEnd", str);
    if (!isMinIE5)
      window.scrollTo(x, y);

    loadBar = getLayer("loadBar");
  }
  setBgColor(loadBar, loadBarBorderColor);
}

//----------------------------------------------------------------------------
// Function called when all images have loaded. Can be redefined.
//----------------------------------------------------------------------------

function loadBarEnd() {
}

//----------------------------------------------------------------------------
// Update the load bar.
//----------------------------------------------------------------------------

function loadBarUpdate() {

  var pct;

  // Update the number of images that have finished loading.

  loadBarImgCount++;

  // Get load as a percentage, reclip top layer.

  pct = loadBarImgCount / loadBarImgList.length;
  clipLayer(loadBarHigh, loadBarBorderWidth, loadBarBorderWidth,
            Math.round(pct * loadBarWidth) - loadBarBorderWidth,
            loadBarHeight - loadBarBorderWidth);

  if (loadBarImgCount == loadBarImgList.length) {
    setTimeout('hideLayer(loadBar)', 500);
    loadBarEnd();
  }
}

