// DHTML initialisieren
var init = false;
var DHTML = false;
var DOM = false;
var IE = false;
var NC = false;
var OP = false;
function initDHTML()
{
   if (window.opera) {OP = true;}
   if (document.getElementById) {DHTML = true; DOM = true;}
   if (document.all && !OP) {DHTML = true; IE = true;}
   if (window.netscape && window.screen && !DOM && !OP) {DHTML = true; NC = true;}
   init = true;
}

// Element (DHTML-abhängig zurückliefern)
function getE(p)
{
   if (DOM) {if (typeof document.getElementById(p) == "object") {return document.getElementById(p);} else {return void(0);}}
   else if (IE) {if (typeof document.all[p] == "object") {return document.all[p];} else {return void(0);}}
   else if (NC) {if (typeof document[p] == "object") {return document[p];} else {return void(0);}}
   else return void(0);
}

// Event (DHTML-abhängig)
function initEvent()
{
   if (DOM && !IE && !OP) {if (typeof document.getElementsByTagName("body") == "object" || typeof document.getElementsByTagName("body") == "function") {document.getElementsByTagName("body")[0].addEventListener("mousemove", move, true);}}
   if (NC) {document.captureEvents(Event.MOUSEMOVE); document.onmousemove = move;}
   if (DOM && OP) {document.onmousemove = move;}
   if (IE) {if (typeof document.all.tags("body") == "object") {document.all.tags("body")[0].onmousemove = move;}}
}

// Menu, positionieren
var amnu = new Array();
var ax1 = new Array();
var ax2 = new Array();
var ax3 = new Array();
var ax4 = new Array();
var menuL = 232;
var menuT = 60;
var menuW = 496;
var menuH = 22;
var menuS = 22;
var mnuBG = "#eeeeee";
var mnuBGH = "#cccccc";
var subBG = "#eeeeee";
var subBGH = "#cccccc";
var border = "#333366";
function initKoord()
{
   // verbleibende Gesamt-Breite zwischen nav's berechnen
   var xMax = menuW;
   for (var i = 0; i < menuNr; i++)
   {
      if (DOM || IE) {xMax -= getE('nav'+i).offsetWidth;}
      if (NC) {xMax -= getE('nav'+i).clip.width;}
      amnu[i] = false;
   }

   // Schlaufe durch nav und Positionierung
   var x = menuL;
   for (var i = 0; i < menuNr; i++)
   {
      // Breite von sub berechnen
      var xSub = 0;
      for (var j = 0; j < asub[i]; j++)
      {
         xSub = Math.max(xSub,(DOM || IE ? getE('nav'+i+'sub'+j).offsetWidth : getE('nav'+i+'sub'+j).clip.width));
      }

      // Richtung von sub bestimmen (links oder rechts aufklappen)
      var xDir;
      if (x + xSub > menuL + menuW)
      {
         xDir = x + (DOM || IE ? getE('nav'+i).offsetWidth : getE('nav'+i).clip.width) - xSub;
      }
      else {xDir = x;}

      // sub anpassen
      for (var j = 0; j < asub[i]; j++)
      {
         if (DOM || IE)
         {
            getE('nav'+i+'sub'+j).style.top = menuT + menuH + 1 + menuS * j;
            getE('nav'+i+'sub'+j).style.left = xDir;
            getE('nav'+i+'sub'+j).style.height = menuS;
            getE('nav'+i+'sub'+j).style.width = xSub;
            getE('nav'+i+'sub'+j).style.backgroundColor = subBG;
         }
         if (NC)
         {
            getE('nav'+i+'sub'+j).top = menuT + menuH + 1 + menuS * j;
            getE('nav'+i+'sub'+j).left = xDir;
            getE('nav'+i+'sub'+j).clip.height = menuS;
            getE('nav'+i+'sub'+j).clip.width = xSub;
            getE('nav'+i+'sub'+j).bgColor = subBG;
         }
      }

      // nav anpassen
      if (DOM || IE)
      {
         getE('sub'+i).style.top = menuT + menuH;
         getE('sub'+i).style.left = xDir - 1;
         getE('sub'+i).style.width = xSub + 2;
         getE('sub'+i).style.height = menuS * asub[i] + 2;
         getE('sub'+i).style.backgroundColor = border;
         getE('nav'+i).style.top = menuT;
         getE('nav'+i).style.left = x;
         ax1[i] = x;
         ax2[i] = x + getE('nav'+i).offsetWidth;
         ax3[i] = xDir;
         ax4[i] = xDir + xSub;
         getE('nav'+i).style.backgroundColor = mnuBG;
         getE('nav'+i).style.visibility = 'visible';
         x += getE('nav'+i).offsetWidth;
         x += xMax / 5;
      }
      if (NC)
      {
         getE('sub'+i).top = menuT + menuH;
         getE('sub'+i).left = xDir - 1;
         getE('sub'+i).clip.width = xSub + 2;
         getE('sub'+i).clip.height = menuS * asub[i] + 2;
         getE('sub'+i).bgColor = border;
         getE('nav'+i).top = menuT;
         getE('nav'+i).left = x;
         ax1[i] = x;
         ax2[i] = x + getE('nav'+i).clip.width;
         ax3[i] = xDir;
         ax4[i] = xDir + xSub;
         getE('nav'+i).bgColor = mnuBG;
         getE('nav'+i).visibility = 'show';
         x += getE('nav'+i).clip.width;
         x += xMax / 5;
      }
   }
}

// Menu, Rollover und Aufklappen
function move(event)
{
   // Mauskoordinaten
   if (init)
   {
      if (IE) {var x = window.event.clientX + document.body.scrollLeft; var y = window.event.clientY + document.body.scrollTop;}
      else if (OP) {var x = window.event.clientX;var y = window.event.clientY;}
      else {var x = event.pageX; var y = event.pageY;}

      // Schlaufe durch nav
      for (var i = 0; i < menuNr; i++)
      {
         // Maus über nav
         if (x >= ax1[i] && x <= ax2[i] && y >= menuT && y <= menuT + menuH)
         {
            if (!amnu[i])
            {
               for (var j = 0; j < asub[i]; j++)
               {
                  if (DOM || IE) {getE('nav'+i+'sub'+j).style.backgroundColor = subBG;} else {getE('nav'+i+'sub'+j).bgColor = subBG;}
               }
               if (DOM || IE)
               {
                  for (j = 0; j < asub[i]; j++) {getE('nav'+i+'sub'+j).style.visibility = 'visible';}
                  if (asub[i] > 0) {getE('sub'+i).style.visibility = 'visible';}
                  getE('nav'+i).style.backgroundColor = mnuBGH;
               }
               if (NC)
               {
                  for (j = 0; j < asub[i]; j++) {getE('nav'+i+'sub'+j).visibility = 'show';}
                  if (asub[i] > 0) {getE('sub'+i).visibility = 'show';}
                  getE('nav'+i).bgColor = mnuBGH;
               }
            amnu[i] = true;
            }
        }

         // Maus über sub
         else if (amnu[i] && x >= ax3[i] && x <= ax4[i] && y >= menuT + menuH + 1 && y <= menuT + menuH + 1 + menuS * asub[i])
         {
            for (var j = 0; j < asub[i]; j++)
            {
               if (y >= menuT + menuH + 1 + j * menuS && y < menuT + menuH + 1 + j * menuS + menuS)
               {
                  if (DOM || IE) {getE('nav'+i+'sub'+j).style.backgroundColor = subBGH;}
                  if (NC) {getE('nav'+i+'sub'+j).bgColor = subBGH;}
               }
               else
               {
                  if (DOM || IE) {getE('nav'+i+'sub'+j).style.backgroundColor = subBG;}
                  if (NC) {getE('nav'+i+'sub'+j).bgColor = subBG;}
               }
            }
         }

         // Maus ausserhalb
         else
         {
            if (amnu[i])
            {
               if (DOM || IE)
               {
                  for (j = 0; j < asub[i]; j++) {getE('nav'+i+'sub'+j).style.visibility = 'hidden';}
                  getE('nav'+i).style.backgroundColor = mnuBG;
                  if (asub[i] > 0) {getE('sub'+i).style.visibility = 'hidden';}
               }
               if (NC)
               {
                  for (j = 0; j < asub[i]; j++) {getE('nav'+i+'sub'+j).visibility = 'hide';}
                  getE('nav'+i).bgColor = mnuBG;
                  if (asub[i] > 0) {getE('sub'+i).visibility = 'hide';}
               }
               amnu[i] = false; 
            }
         }
      }
   }
}
