/* ------------------------------------------------------------------------------------- */
/*
   Autor   : Andreas Zierhut
   Stand   : 18.04.2000, V2.00
   Homepage: http://www.dhtml-now.de/
   E-Mail  : Andreas.Zierhut@t-online.de
   Hinweis : Das Script darf kostenlos weiterverwendet werden, solange dieser Kommentar
             im Script verbleibt. Evtl. Updates sind auf meiner Homepage zu finden.
             Bei Fehlern bitte ein E-Mail an mich schreiben.
                                                                                         */
/* ------------------------------------------------------------------------------------- */

function Menu(links, oben)
{
  mList[mList.length] = this.name;

  this.itemList = new Array();

  this.bgColor = '#00CCFF';
  this.aborderColor = '#00CCFF';
  this.aborderWidth = 1;

  this.iborderColor = this.bgColor;
  this.iborderWidth = 2;

  this.paddingLeft = 5;
  this.paddingRight = 5;
  this.paddingTop = 2;
  this.paddingBottom = 2;

  this.align = 'absmiddle';
  this.valign = 'top';
  this.alignTD = 'absmiddle';
  this.menuAlign = 'horizontal';
  this.submenuAlign = 'vertikal';

  this.color = '#000000';
  this.fontFamily = 'Verdana,Arial,Helvetica,Sans-Serif';
  this.fontSize = '75%';
  this.textDecoration = 'none';
  this.fontStyle = 'normal';
  this.fontWeight = '600';

  this.hoverOn = true;
  this.hoverColor = this.bgColor;
  this.hoverbgColor = this.color;

  if (links && oben) {
    this.left = links;
    this.top = oben;
  }
  else {
    this.left = 0;
    this.top = 0;
  }

  this.SP = '<img src="spacer.gif" width='+this.iborderWidth+' height='+this.iborderWidth+' alt="">';

  this.addMenu = paddMenu;
  this.addMenuItem = paddMenuItem;
  this.build = pbuild;
  this.create = pcreate;
}

function makeVars()
{
  with(window) {
    ns = document.layers ? true : false;
    ie = document.all ? true : false;
    mCount = 0;
    mList = new Array();
    HoverObj = null;
    HoverObj2 = null;
    offen = '0,';
    hoverMenuOn = -1;
    hoverMenuAktuell = -1;
  }
  Daten();
  if (ns) document.captureEvents(Event.CLICK);
  document.onclick = new Function ('hideHoverMenu(); checkMenu(0)');
}

function MenuInit()
{
  if (lMenu.align == 'center') {
    if (ns)
      document.Menue0.left = document.Menue0.pageX + (window.innerWidth - document.Menue0.pageX) / 2 - (document.Menue0.document.width / 2);
    else if (ie)
      document.all.Menue0.style.posLeft = document.all.MenuePosition.offsetLeft + (document.body.clientWidth - document.all.MenuePosition.offsetLeft) / 2 - (document.all.Menue0.offsetWidth / 2);
  }
  else if (ie)
    document.all.Menue0.style.posLeft = document.all.MenuePosition.offsetLeft;

  if (lMenu.valign == 'center') {
    if (ns)
      document.Menue0.top = document.Menue0.pageY + (window.innerHeight - document.Menue0.pageY) / 2 - (document.Menue0.document.height / 2);
    else if (ie)
      document.all.Menue0.style.posTop = document.all.MenuePosition.offsetTop + (document.body.clientHeight - document.all.MenuePosition.offsetTop) / 2 - (document.all.Menue0.offsetHeight / 2);
  }
  else if (ie)
    document.all.Menue0.style.posTop = document.all.MenuePosition.offsetTop;
}

function paddMenu(Name, Link, Target, Bezeichnung)
{
  window[Name] = new Menu();
  this.itemList[this.itemList.length] = window[Name];

  window[Name].link = Link;
  window[Name].target = Target;
  window[Name].bez = Bezeichnung;
}

function paddMenuItem(Link, Target, Bezeichnung)
{
  this.itemList[this.itemList.length] = Link + ';' + Target + ';' + Bezeichnung;
}

function pbuild()
{
  this.idx = mCount;
  this.name = 'Menue' + mCount;

  window['Menue' + mCount++] = this;

  if (!this.idx) {
    this.ModX = (ie ? document.all.MenuePosition.offsetLeft : document.MenuePosition.pageX);
    this.ModY = (ie ? document.all.MenuePosition.offsetTop : document.MenuePosition.pageY);
  }

  this.Style = '<style type="text/css">\n';

  this.Dok = '';
  this.create(-1);

  if (ns && this.hoverOn)
    for (var i=0; i < this.itemList.length; i++)
      this.create(i);

  this.Style += '  .L' + this.name + ' { color: ' + this.color + '; font-family: ' + this.fontFamily + '; font-size: ' + this.fontSize + '; text-decoration: ' + this.textDecoration + '; font-style: ' + this.fontStyle + '; font-weight: ' + this.fontWeight + '; }\n';
  this.Style += '  .H' + this.name + ' { color: ' + this.hoverColor + '; font-family: ' + this.fontFamily + '; font-size: ' + this.fontSize + '; text-decoration: ' + this.textDecoration + '; font-style: ' + this.fontStyle + '; font-weight: ' + this.fontWeight + '; }\n';
  this.Style += '</style>';

  document.write(this.Style + this.Dok);

}

function pcreate(Index)
{

  var LayerName = (Index == -1 ? this.name : this.name + 'Item' + Index);

  this.Style += '  #' + LayerName + ' { position: absolute; left: ' + (this.idx ? 0 : this.left + this.ModX) + '; top: ' + (this.idx ? 0 : this.top + this.ModY) + '; width: 1; visibility: ' + (this.idx || Index != -1 ? 'hidden' : 'visible') + '; z-Index: 2; }\n';

  var vm = (this.idx && this.submenuAlign=='vertikal') || (!this.idx && this.menuAlign=='vertikal');

  this.Dok += '<span id="' + LayerName + '">\n' +
              '<table border=0 cellspacing=0 cellpadding=' + this.aborderWidth + '><tr><td bgColor="' + this.aborderColor + '">\n' +
              '  <table border=0 cellspacing=0 cellpadding=0>\n' +
              '    <tr>\n' +
              (!vm ? '      <td colspan="' + (this.itemList.length*2+1) + '" bgColor="' + this.iborderColor + '">' + this.SP + '</td>\n' +
              '    </tr>\n' +
              '    <tr>\n' : '');

  for (var i=0; i < this.itemList.length; i++) {

    this.Dok += (vm ? '      <td bgColor="' + this.iborderColor + '">' + this.SP + '</td><td bgColor="' + this.iborderColor + '">' + this.SP + '</td><td bgColor="' + this.iborderColor + '" align="right"><a name="aM' + this.idx + 'Pos' + i + '">' + this.SP + '</a></td>\n' +
                '    </tr>\n' +
                '    <tr>\n' : '') +
                '      <td bgColor="' + this.iborderColor + '" valign="bottom">' + (!vm ? '<a name="aM' + this.idx + 'Pos' + i + '">' : '') + this.SP + '</a></td>\n';

    if (i != Index)
      this.Dok += '      <td align="' + this.alignTD + '" ' + (ns ? 'bgColor="' + this.bgColor + '"' : 'id="' + this.name + 'Hintergrund' + i + '" style="background-color: ' + this.bgColor + ';"') + '><nobr>';
    else
      this.Dok += '      <td align="' + this.alignTD + '" bgColor="' + this.hoverbgColor + '"><nobr>';

    this.Dok += sp(1,this.paddingTop)+'<br>'+sp(this.paddingLeft,1);

    if (typeof(this.itemList[i]) == 'string')
      this.Dok += '<a href="' + this.itemList[i].split(';')[0] + '" target="' + this.itemList[i].split(';')[1] + '" class="' + (i != Index ? 'L' : 'H') + this.name + '"' + (Index == -1 ? ' onMouseOver=" if (window.Menue' + this.idx + '.hoverOn) hoverMenu(' + this.idx + ', ' + i + ');checkMenu(' + this.idx + ')"' : '') + ' name="' + this.name + 'A' + i + '">' + this.itemList[i].split(';')[2] + '</a>';

    else {
      this.Dok += '<a href="' + this.itemList[i].link + '" target="' + this.itemList[i].target + '" class="' + (i != Index ? 'L' : 'H') + this.name + '"' + (Index == -1 ? ' onMouseOver="if (window.Menue' + this.idx + '.hoverOn) hoverMenu(' + this.idx + ', ' + i + ');checkMenu(' + this.idx + ');showMenu(' + this.idx + ', ' + i + ', ' + mCount + ')"' : '') + ' name="' + this.name + 'A' + i + '">' + this.itemList[i].bez + '</a>';
      if (Index == -1)
        this.itemList[i].build();
    }

    this.Dok += sp(this.paddingRight,1)+'<br>'+sp(1,this.paddingBottom)+'</nobr></td>\n' +
                (vm ? '      <td bgColor="' + this.iborderColor + '">' + this.SP + '</td>' +
                '    </tr>\n' : '');

  }

  this.Dok += (vm ? '    <tr>\n' +
              '      <td bgColor="' + this.iborderColor + '" colspan="3">' + this.SP + '</td>\n' : '<td bgColor="' + this.iborderColor + '">' + this.SP + '</td>') +
              (!vm ? '    <tr>\n' +
              '      <td colspan="' + (this.itemList.length*2+1) + '" bgColor="' + this.iborderColor + '">' + this.SP + '</td>\n' : '') +
              '    </tr>\n' +
              '  </table>\n' +
              '</td></tr></table>\n' +
              '</span>\n';

}

function hoverMenu(Aktuell, AnkerPos)
{
  if (hoverMenuOn != AnkerPos) {

    hideHoverMenu();

    hoverMenuAktuell = Aktuell;
    hoverMenuOn = AnkerPos;
    var Menue = window['Menue'+Aktuell];

    if (ns) {

      var LN = Menue.name + 'Item' + AnkerPos;

      with (document[LN]) {
        left = window.document['Menue'+Aktuell].pageX;
        top  = window.document['Menue'+Aktuell].pageY;
        visibility = 'visible';
      }

      HoverObj = document['Menue'+Aktuell].document.links[AnkerPos];
      HoverObj2 = document[LN].document.links[AnkerPos];

    }
    else if (ie) {
      document.all['Menue'+Aktuell+'Hintergrund'+AnkerPos].style.backgroundColor = Menue.hoverbgColor;
      document.all['Menue'+Aktuell+'A'+AnkerPos].style.color = Menue.hoverColor;
    }

    if (ns) document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = hideHoverMenu;

  }

}

function hideHoverMenu(evt)
{

  if ((ie && hoverMenuAktuell != -1 && event.srcElement.style.color != window['Menue'+hoverMenuAktuell].hoverColor.toLowerCase()) || (ns && hoverMenuAktuell != -1 && hoverMenuOn != -1 && (!evt || evt.target != HoverObj && evt.target != HoverObj2))) {

    if (ie) {

      var Menue = window['Menue'+hoverMenuAktuell];
      document.all['Menue'+hoverMenuAktuell+'Hintergrund'+hoverMenuOn].style.backgroundColor = Menue.bgColor;
      document.all['Menue'+hoverMenuAktuell+'A'+hoverMenuOn].style.color = Menue.color;

    }

    if (ns)
      document['Menue'+hoverMenuAktuell+'Item'+hoverMenuOn].visibility = 'hidden';

    document.onmousemove = null;

    hoverMenuAktuell = -1;
    hoverMenuOn = -1;
    HoverObj = null;
    HoverObj2 = null;

  }

}

function checkMenu(Vorgaenger)
{
  offen = offen.substring(0, offen.length-1);
  var offeneMenues = offen.split(',');

  for (var i=offeneMenues.length-1; i >= 0; i--) {

    if (Vorgaenger == parseInt(offeneMenues[i])) {

      offen = '';
      for (var j=0; j <= i; j++)
        offen += offeneMenues[j] + ',';
      break;

    }
    else
      with (ns ? document['Menue'+offeneMenues[i]] : document.all['Menue'+offeneMenues[i]].style)
        visibility = 'hidden';

  }
}

function showMenu(Vorgaenger, AnkerPos, Aktuell)
{
  var Menue = window['Menue'+Aktuell];
  var vm=(Vorgaenger && Menue.submenuAlign=='vertikal') || (!Vorgaenger && Menue.menuAlign=='vertikal');

  var ModX = (vm ? Menue.aborderWidth + Menue.iborderWidth : -1 * Menue.aborderWidth);
  var ModY = (vm ? -1 * Menue.aborderWidth : 2 * Menue.iborderWidth + Menue.aborderWidth);

  if (offen.indexOf(''+Aktuell) == -1)
    offen += Aktuell + ',';

  if (ns) {

    var anker = document['Menue'+Vorgaenger].document.anchors['aM'+Vorgaenger+'Pos'+AnkerPos];

    with (document['Menue'+Aktuell]) {
      left = anker.x + window.document['Menue'+Vorgaenger].pageX + ModX;
      top = anker.y + window.document['Menue'+Vorgaenger].pageY + ModY;
      visibility = 'visible';
    }

  }
  else if (ie) {

    var LinksWert = 0;
    var TopWert = 0;
    var AObj = 'document.all["aM'+Vorgaenger+'Pos'+AnkerPos+'"]';

    for ( ; eval(AObj); AObj += '.offsetParent') {
      LinksWert += eval(AObj).offsetLeft;
      TopWert += eval(AObj).offsetTop;
    }

    with (document.all['Menue'+Aktuell].style) {
      posLeft = LinksWert + ModX;
      posTop = TopWert + ModY;
      visibility = 'visible';
    }

  }

}
function sp(w,h){if(ns) return('<spacer type="block" width="'+w+'" height="'+h+'">'); else return('<img src="spacer.gif" width='+w+' height='+h+' alt="">'); return;}
