var tmr = new Array();
var adj = new Array();
var last_zIndex = 10000;
var lastOverId = '';
var richt = 'bottom';

var adjustTop		= 1;			// 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.
var div_ob_abst = 23;

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);}
}
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)
//       {L_pos = d.offsetLeft + d.offsetWidth;
//        T_pos = d.offsetTop;
       {if (align == 'bottom')
           {L_pos = d.offsetLeft - 1;				div_ob_abst = 22;	// wegen IframePatch()
            T_pos = d.offsetTop + d.offsetHeight + 3;} else
           {L_pos = d.offsetLeft + d.offsetWidth;	div_ob_abst = 23;
            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 (m[i][2])
                     {if (m[i][2] == 'S')
                          act = "top.location.href='o_sub.php?mep="+m[i][1]+"';"; else
                          act = "top.location.href='o_out.php?mep="+m[i][1]+"&scr="+scr+"';";
                     }
                  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
            }
        }
    }
}
document.onmouseover = function(e)		//change div's on mouse over and out...
{obj = document.all ? event.srcElement : e.target;
 if (obj.className == 'menuItem')
     obj.className+='Over';
}
document.onmouseout = function(e)
{obj = document.all ? event.srcElement : e.target;
 if (obj.className == 'menuItemOver')
     obj.className = obj.className.substring(0,(obj.className.length - 4));
}
function h_v_menu(max,li,t1,menu,richt)
{if (max==0) max=menu_len;
 for (var i=0; i<max; i++)
     {document.write('<div class=menuItem id="m'+i+'" ');	// HAUPTMENÜ ... m1,m2,..
      if (richt=="bottom")
          document.write('style="position:absolute; left:'+eval(li+i*(120+8))+'px; top:'+eval(t1)+'px" '); else
          document.write('style="position:absolute; left:'+li+'px; top:'+eval(t1+i*div_ob_abst)+'px" ');
      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][2]=='O')
          document.write('onClick=top.location.href=\"o_out.php?mep='+menu["m"][i][1]+'&scr='+scr+'\">'+menu["m"][i][0]+'</div>'); else
          document.write('onClick=top.location.href=\"o_sub.php?mep='+menu["m"][i][1]+'\">'+menu["m"][i][0]+'</div>');
     }
}
