var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + 'js/Lib/';
document.write ('<SCR' + 'IPT LANGUAGE="JavaScript1.2" SRC="'+ cPath +'BMenu3.js" TYPE="text/javascript"><\/SCR' + 'IPT>');

function initMenus () {
  if (_aMs.length == 0) {
    var oMenu = new HoriMenu(0);
  }
}

function initStartMenus () {
  if (_aMs.length == 0) {
    var oMenu = new Menu(0);
  }
}

function HoriMenu(nLevel) {
  this.init = BTextMenu;
  this.init (0);
  this.aPos = [51, 79];
  this.aElementWidth = [];
  this.nChildOffset = 1;
  this.nElementHeight = 20;

this.BMenu_getLink = this.getLink;
this.getLink = function (nElem) {
  var cLink = this.BMenu_getLink(nElem);
  cLink = cLink.replace(/href="/,"href=\"/");
  return (cLink);
}

  this.calculateSize = function() {
    this.nWidth = 0;
    this.aElementWidth = [];
    for (var i=0; i < this.aElements.length; i++) {
      this.aElementWidth[i] = this.getStringWidth (this.aElements[i][1]);
      this.nWidth += 6 + this.aElementWidth[i] + 6;
    }
    this.nWidth += 6; // Für abschließende Schräge
  };

  this.highlight = function (nElem) {
    var bChanged = (nElem != this.nHigh);
    if (bChanged) {
      this.nHigh = nElem;
      if (nElem == null)
        this.aLayers[1].clipp (0, 0, 0, 0);
      else
        this.aLayers[1].clipp (this.getElementOffset(nElem), 0, 6 + this.aElementWidth[nElem] + 6, this.nElementHeight);
    }
    return (bChanged);
  };

  this.getElementOffset = function (nElem) {
    var nOffset = 0 ;
    for (var i=0; i<nElem; i++) nOffset += 6 + this.aElementWidth[i] + 6;
    return (nOffset);
  }

  this.getChildPosition = function () {
    var aPos = [0, 0];
    aPos[0] = this.aPos[0] + this.getElementOffset(this.nSelected) - 8 - this.oChild.getStartOffset(0);
    aPos[1] = this.aLayers[0].get('top') + this.nElementHeight + this.nChildOffset;
    return (aPos);
  }

  this.getPosition = function () {
    var aPos = [this.aPos[0], this.aPos[1]];
    var aClipp = new Array (0, 0, this.nWidth, this.nElementHeight);
    return (aPos.concat (aClipp));
  };

  this.close = function () {
    this.highlight(null);
    if (this.oChild) this.oChild.close();
  };


  this.getContent = function (nLayer) {
    var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + CONFIG['Images']['Dir'];
    var cHtml = '<table border="0" cellspacing="0" cellpadding="0"><tr>';
    var bPreset, bHasChildren, cClass;

    for (var i=0; i<this.aElements.length; i++)
      if (!this.bFolded || i == this.nPreSelected || (this.nLevel == 0 && typeof(this.nPreSelected) != 'number' && i==0)) {
      var nElementWidth = this.aElementWidth[i];
      bHasChildren = (this.aElements[i][2] && this.aElements[i][2].length > 0);
      bPreset = (typeof(this.nPreSelected)=='number' && (i == this.nPreSelected));
      switch (nLayer) {
        case 0:
        case 1:
          var cMenuPath = cPath + 'hmenu/' + (bPreset && nLayer == 0 ? 'preset/' : '');
          cClass = 'menu' + (nLayer == 1 ? 'act' : (bPreset ? 'preset' : ''));
          cHtml += '<td><img src="' + cMenuPath + 'left' + (nLayer) + '.gif" width="6" height="20" alt=""></td>';
          cHtml += '<td class="' + cClass + '" width="'+ nElementWidth +'" nowrap><P class="' + cClass + '">' + this.aElements[i][1].replace (' ', '&nbsp;') + '</P></td>';
          cHtml += '<td><img src="' + cMenuPath + 'right' +(nLayer) + '.gif" width="6" height="20" alt=""></td>';
          break;
        case 2:
          cHtml += '<td><a ' + this.getLink(i) + ' onmouseover="return _aMs[' + this.nLevel + '].mo(' + i + ',1)" onmouseout="return _aMs[' + this.nLevel + '].mo(' + i + ')"><img src="' + cPath + 'leer.gif" width="' + (6 + nElementWidth + 6) + '" height="' + this.nElementHeight + '" border="0"></a></td>';
          break;
      }
    }
    // Schräge hinter letztem Menü-Eintrag
    if (nLayer == 0) cHtml += '<td><img src="' + cPath + 'hmenu/left' + (nLayer) + '.gif" width="6" height="20" alt=""></td>';

    cHtml += '</tr></table>';
    return (cHtml);
  };

  this.update (aMenuEntries);
}






function Menu (nLevel) {
  this.init = BTextMenu;
  this.init (nLevel);
  this.bFolded = null;
  this.nElementHeight = 21;
  this.nChildOffset = -5;
  this.nSelected = null;
  this.nPreSelected = null;
  this.nHigh = null;
  this.nOffset = 7;
  this.nStartImageWidth = 8;
  this.nEndImageWidth = 8;


  this.BMenu_getStringWidth = this.getStringWidth;
  this.getStringWidth = function (cText) {
    return (this.BMenu_getStringWidth (cText, 13));
  }

  this.calculateSize = function() {
    this.nElementsWidth = this.getElementsWidth();
    if (this.nLevel == 0) this.nElementsWidth = Math.max (this.nElementsWidth, 113);
    this.nWidth = this.nStartImageWidth + this.nEndImageWidth + this.nElementsWidth +  this.getStartOffset(0);
  };

  this.getStartOffset = function (nElement) {
    nOffset = (this.aElements.length - nElement - 1) * this.nOffset + 1;
    return (nOffset);
  }

/*
  Bestimmt die Position des aktuellen Untermenues
*/
  this.getChildPosition = function() {
    var aPos = [0, 0];
    aPos[0] = this.aLayers[0].get('left') + this.getStartOffset(this.nSelected) + this.nElementsWidth + this.nStartImageWidth + this.nEndImageWidth - this.oChild.getStartOffset(0) + this.nChildOffset;
    aPos[1] = (this.bFolded === true || this.bFolded === false ? _aMs[0].aPos[1] : this.aLayers[0].get('top') + this.nSelected * this.nElementHeight);
    //alert (aPos[0]);
    return (aPos);
  }



  this.getContent = function (nLayer) {
    var cPath = (window.getRelativeWebRoot ? window.getRelativeWebRoot() : '') + CONFIG['Images']['Dir'];
    var cHtml = '';
    var bPreset, bHasChildren, cClass;
    for (var i=0; i<this.aElements.length; i++) {
      bHasChildren = (this.aElements[i][2] && this.aElements[i][2].length > 0);
      bPreset = (typeof(this.nPreSelected)=='number' && (i == this.nPreSelected));
      cHtml += '<table border="0" cellspacing="0" cellpadding="0" width="' + (this.getStartOffset(i) + this.nElementsWidth + this.nStartImageWidth + this.nEndImageWidth) + '"><tr>';
      switch (nLayer) {
        case 0:
        case 1:
          var cMenuPath = cPath + 'menu/' + (bPreset && nLayer == 0 ? 'preset/' : '');
          cClass = 'menu' + (nLayer == 1 ? 'act' : (bPreset ? 'preset' : ''));
          cHtml += '<td><img src="' + cPath + 'leer.gif" width="' + this.getStartOffset(i) + '" height="' + this.nElementHeight + '"></td>';
          cHtml += '<td><img src="' + cMenuPath + (this.nLevel == 0 ? 'startpage_' : '') + 'left' + nLayer + '.gif" width="' + this.nStartImageWidth + '" height="' + this.nElementHeight + '" alt=""></TD>';
          cHtml += '<td class="' + cClass + '" width="' + (this.nElementsWidth) + '"><P class="' + cClass + '">' + this.aElements[i][1].replace (' ', '&nbsp;') + '</P></td>';
          cHtml += '<td><img src="' + cMenuPath + 'right' + (bHasChildren ? '_more' : '') + nLayer + '.gif" width="' + this.nEndImageWidth + '" height="' + this.nElementHeight + '" alt=""></TD>';
          break;
        case 2:
          if (this.oParent && ((this.oParent.nSelected + i) < this.oParent.aElements.length)) {
            cHtml += '<TD><a ' + this.oParent.getLink(this.oParent.nSelected + i) + ' onmouseover="return _aMs[' + this.oParent.nLevel + '].mo(' + (eval(this.oParent.nSelected + i)) + ',1)" onmouseout="return _aMs[' + this.oParent.nLevel + '].mo(' + i + ')"><IMG src="' + cPath + 'leer.gif" width="' + this.getStartOffset(i) + '" height="' + this.nElementHeight + '" alt="" border="0"></a></TD>';
          } else {
            cHtml += '<TD><IMG src="' + cPath + 'leer.gif" width="' + this.getStartOffset(i) + '" height="' + this.nElementHeight + '" alt=""></TD>';
          }

          cHtml += '<td height="' + this.nElementHeight + '" width="' + this.nWidth + '"><a ' + this.getLink(i) + ' onmouseover="return _aMs[' + this.nLevel + '].mo(' + i + ',1)" onmouseout="return _aMs[' + this.nLevel + '].mo(' + i + ')"><img src="' + cPath + 'leer.gif" width="' + this.nWidth + '" height="' + this.nElementHeight + '" border="0"></a></td>';
          break;
      }
      cHtml += '</tr></table>';
    }
    return (cHtml);
  };

  this.close = function () {
    if (this.aElements) {
      this.update (null);
      if (this.oChild) this.oChild.close();
      if (this.oParent) {
        this.oParent.highlight(null);
        this.oParent.close();
      }
    }
  };

this.BMenu_getLink = this.getLink;
this.getLink = function (nElem) {
  var cLink = this.BMenu_getLink(nElem);
  cLink = cLink.replace(/href="/,"href=\"/");
  return (cLink);
}

  if (this.nLevel == 0) {
    this.bSuspended = false;
    this.aPos = [148, 26];
    this.close = function() {}  // Korrekt? - ueberpruefen. Der oberste Level soll nicht geschlossen werden

    if (PageID == 1) {
      this.aPos = [71 - aMenuEntries.length * this.nOffset, 180];
      this.update (aMenuEntries);
    }
  }
}
