// Anzeige-Funktion - Parameter:
// parent    - id des sichtbaren elements ( --> punkt im hauptmenü)
// child     - id des unsichtbaren elements ( --> dropdown-bereich)
// direction - Bestimmt die Anzeigerichtung: 
//				 "x" = der dropdown-bereich wird rechts angezeigt
//               "y" = der dropdown-bereich wird unten angezeigt
// location  - Bestimmt dir Farbgesttitleung
//				 "top"  = Formatierung wie ein Menüpunkt im oberen Menü
//				 "left" = Formatierung wie ein Menüpunkt im linken Menü
function init_dd(parent, child, direction, location)  
{
  var menu_item = document.getElementById(parent);
  var sub_menu  = document.getElementById(child);

  menu_item["parent"]    = menu_item.id;
  sub_menu["parent"]     = menu_item.id;
  menu_item["child"]     = sub_menu.id;
  sub_menu["child"]      = sub_menu.id;
  menu_item["position"]  = direction;
  sub_menu["position"]   = direction;

  sub_menu.style.position   = "absolute";
  sub_menu.style.visibility = "hidden";
  
  menu_item.style.cursor    = "default";

  menu_item.onclick     = open_dd;
  switch (location)
  {
    case "top":
		menu_item.onmouseover = mitem_hover_top;
		menu_item.onmouseout  = mitem_mouseout_top;
		break;
    case "left":
		menu_item.onmouseover = mitem_hover_left;
		menu_item.onmouseout  = mitem_mouseout_left;
		break;
  }	
  sub_menu.onmouseover  = show_dd;
  sub_menu.onmouseout   = hide_dd;
}

function mitem_hover_top()
{
	var current_menu_item = document.getElementById(this["parent"]);
	current_menu_item.style.color = "#000000";
}

function mitem_mouseout_top()  
{
  // Mouseout > Farbe wird entsprechend geändert
  var current_menu_item = document.getElementById(this["parent"]);
  current_menu_item.style.color = "#FFFFFF";
  
  // Mouseout > Setzt Timer für ausblenden des DD-Bereichs
  var child = document.getElementById(this["child"]);
  child["timeout"] = setTimeout("document.getElementById('"+child.id+"').style.visibility = 'hidden'", 600);
}

function mitem_hover_left()
{
	var current_menu_item = document.getElementById(this["parent"]);
	current_menu_item.style.color = "#999999";
}

function mitem_mouseout_left()  
{
  // Mouseout > Farbe wird entsprechend geändert
  var current_menu_item = document.getElementById(this["parent"]);
  current_menu_item.style.color = "#000000";
  
  // Mouseout > Setzt Timer für ausblenden des DD-Bereichs
  var child = document.getElementById(this["child"]);
  child["timeout"] = setTimeout("document.getElementById('"+child.id+"').style.visibility = 'hidden'", 600);
  if (child.id == 'leftmenu_sub_bestellungen')
  {
	var spacer = document.getElementById("dropdown_spacer_bestellungen");
	spacer["timeout"] = setTimeout("document.getElementById('"+spacer.id+"').style.height = '"+2+"px'", 600);
  } 
}

function open_dd()  
{
  var parent = document.getElementById(this["parent"]);
  var child = document.getElementById(this["child" ]);

  if (child.style.visibility != "visible")
       pos_dd(parent.id, child.id);
  else child.style.visibility = "hidden";

  return false;
}

function pos_dd(parent, child)  
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["position"] == "y") ? p.offsetHeight+3 : 0;
  var left = (c["position"] == "x") ? p.offsetWidth+3 : 0;

  top  += p.offsetTop;
  left += p.offsetLeft;
  
  if (p.id == 'leftmenu_bestellungen')
  {
  	var spacer = document.getElementById("dropdown_spacer_bestellungen");
	spacer.style.height=22+'px';
	  if (navigator.appName.indexOf("Explorer") > -1) 
	  { 
		top += 15;
		left -= 1;
	  }
  } 
  
  c.style.position   = "absolute";
  c.style.top        = top+'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
  
}

function show_dd()  
{
  var parent = document.getElementById(this["at_parent"]);
  var child = document.getElementById(this["child" ]);

  clearTimeout(child["timeout"]);
  if (child.id == 'leftmenu_sub_bestellungen')
  {
	var spacer = document.getElementById("dropdown_spacer_bestellungen");
	clearTimeout(spacer["timeout"]);
  }  
  
  pos_dd(parent, child);
}

function hide_dd()  
{
  var child = document.getElementById(this["child"]);

  child["timeout"] = setTimeout("document.getElementById('"+child.id+"').style.visibility = 'hidden'", 600);
  
  if (child.id == 'leftmenu_sub_bestellungen')
  {
	var spacer = document.getElementById("dropdown_spacer_bestellungen");
	spacer["timeout"] = setTimeout("document.getElementById('"+spacer.id+"').style.height = '"+2+"px'", 600);
  } 
}
