var menu = new Array();
var tmr = new Array();
var adj = new Array();
var last_zIndex = 10000;
var lastOverId = '';
var div_ob_abst = 22;
var richt = 'bottom';

var adjustTop		= 2;			// move the submenu's some pixels. Positive number (10) for down, negative (-10) for up.
var adjustLeft		= 2;			// move the submenu's some pixels. Positive number (10) for right, negative (-10) for left.

menu['m']  = new Array();

menu['m'][0] = new Array("Startseite","","index.php","T");
menu['m'][1] = new Array("Neues","","d_neu.php","C");
menu['m'][2] = new Array("Speisen","","d_anhang/speise.pdf","B");
menu['m'][3] = new Array("Getränke","","d_anhang/getraenk.pdf","B");
menu['m'][4] = new Array("Desserts","","d_anhang/dessert.pdf","B");
var menu_len=5;		// Anzahl m0,m1,..

function iFramePatch()		//This function should be called onMouseOver of every iFrame that's under the menu structure
{if (!document.all && lastOverId)
     hideSubmenu(document.getElementById(lastOverId));
}
function buildSubmenu(obj,align)
{lastOverId = obj.id;
 menuPath = obj.id.split('_');
 x = "div";
 for (i=0; i<menuPath.length; i++)
     {x+='_'+menuPath[i];
      if (document.getElementById(x))
         {if (tmr[x]) window.clearTimeout(tmr[x]);
          document.getElementById(x).style.visibility = vis(1);}
     }
 if (menu[obj.id])		//check if we have a submenu of the obj...
    {d = obj;			//calc position of mouseover
     if(d)
       {if (align == 'bottom')
           {L_pos = d.offsetLeft - 1 + d.offsetWidth;	// div_ob_abst = 22; wegen IframePatch()
            T_pos = d.offsetTop + 3;} else
           {L_pos = d.offsetLeft + d.offsetWidth;	// ???
            T_pos = d.offsetTop;}
        while (d.offsetParent)
              {d = d.offsetParent;
               L_pos+= d.offsetLeft;
               T_pos+= d.offsetTop;}
       }
     if (obj.className.indexOf('menuItem') < 0 && align == 'bottom')	//patch first submenu to go right below the main buttons...
        {L_pos-= obj.offsetWidth;
         T_pos+= obj.offsetHeight;}
     if (obj.id.length==2)				// NEU - zur Positionierung!
        {L_pos+= adjustLeft;
         T_pos+= adjustTop;} else 
         T_pos+=1;
     if (L_pos > 0 && T_pos >0)		//Only parse when position is higher than 0,0... else we dont have the right position!
        {c = document.getElementById('div_' + obj.id);		//check if allready build...
         if (c)
            {c.style.visibility = vis(1);					//unhide...
             c.style.zIndex = last_zIndex++;
             c.style.top = (T_pos - 1) + "px";				//hard replace
             c.style.left = (L_pos - 1) + "px";} else		//
            {subObj = document.createElement('div');		//build new div
             subObj.id = 'div_' + obj.id;
             subObj.className = 'menu';
             subObj.style.position = 'absolute';
             subObj.style.zIndex = last_zIndex++;
             subObj.style.top = (T_pos - 1) + "px";
             subObj.style.left = (L_pos - 1) + "px";
             document.getElementsByTagName('body')[0].appendChild(subObj);		//write div to the body...
             content = "";				//build html for submenu
             m = menu[obj.id];			//document.getElementById('dum').innerHTML='<p>'+m[1][2]+'</p>';
             for (i=0; i<m.length; i++)
                 {if (menu[obj.id][i][3]=="T")
                      var act="top.location.href='"+menu[obj.id][i][2]+"'"; else
                      var act="top.location.href='d_sub.php?m="+menu[obj.id][i][1]+"&t="+menu[obj.id][i][3]+"&i="+menu[obj.id][i][2]+"'";
                  var s_top=subObj.style.top;
                  var t_top=eval(s_top.substr(0,eval(s_top.Length-2))+i*div_ob_abst);
                  content+= "<div style=\"position:absolute; top:"+t_top+"px\" onmouseout=\"hideSubmenu(this)\" onmouseover=\"buildSubmenu(this,align)\" onclick=\""+ act + "\" class=menuItem id=\"" + obj.id + "_" + i +"\">" + m[i][0] +"</div>";
                  adj[i] = obj.id + "_" + i;
                 }
             subObj.innerHTML = content;				//insert new menu
            }
        }
    }
}
function hideSubmenu(obj)
{closePath = obj.id.split('_');		//get common part of div id
 x = "div";							//hide path
 for (i=0; i<closePath.length; i++)
     {x+= '_' + closePath[i];
      if (document.getElementById(x))
          tmr[x] = window.setTimeout("document.getElementById('"+x+"').style.visibility = vis(0);",100);}
}
document.onmouseover = function(e)		//change div's on mouse over and out...
{obj = document.all ? event.srcElement : e.target;
 if (obj.className.substring(0,4) == 'menu' || obj.className.substring(0,4) == 'main')
     obj.className+='Over';

}
document.onmouseout = function(e)
{obj = document.all ? event.srcElement : e.target;
 if (obj.className.substr((obj.className.length - 4),4) == 'Over')
     obj.className = obj.className.substr(0,(obj.className.length - 4));
}
function h_v_menu(max,li,t1,menu,richt)
{var h=0; var w=0;
 if (max==0) max=menu_len;
 for (var i=0; i<max; i++)
     {var brows='MF'; if (isIE) brows='IE';
      if (isIE) brows+='180'; else brows+='174';
      document.write('<div valign=center class=main'+brows+' id="m'+i+'" ');	// HAUPTMENÜ ... m1,m2,..
      if (richt=="bottom")
          document.write('style="position:absolute; left:'+eval(li+i*(180+3)+w-h*688)+'px; top:'+eval(t1+h*288)+'px" '); else
          document.write('style="position:absolute; left:'+li+'px; top:'+eval(t1+i*div_ob_abst)+'px" ');
      if (i>=7) h=1;
      if (menu["m"+i])
          if (menu["m"+i].length>1)			// Submenü existiert
              document.write('onMouseout=hideSubmenu(this) onMouseover=buildSubmenu(this,richt) ');
          if (menu["m"][i][3]=="T")
              var act="top.location.href='"+menu["m"][i][2]+"'"; else
          if (menu["m"][i][3]=="C")
              var act="top.frames['cfr'].location.href='"+menu["m"][i][2]+"'"; else
              var act="top.location.href='d_sub.php?i="+menu["m"][i][2]+"'";
      document.write('onClick=\"'+act+'\">'+menu["m"][i][0]+'</div>');
     }
}

