

// ***** menu_show_aux *****

function menu_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = p.offsetHeight+4;
  var left = -21;  //This is the distance from the start of the main menu item

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }
  

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ***** menu_show *****

function menu_show()
{
  var p = document.getElementById(this["menu_parent"]);
  var c = document.getElementById(this["menu_child" ]);

  menu_show_aux(p.id, c.id);
  clearTimeout(c["menu_timeout"]);
}

// ***** menu_hide *****

function menu_hide()
{
  var p = document.getElementById(this["menu_parent"]);
  var c = document.getElementById(this["menu_child" ]);

  c["menu_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 100);
}

// ***** menu_click *****

function menu_click()
{
  var p = document.getElementById(this["menu_parent"]);
  var c = document.getElementById(this["menu_child" ]);

  if (c.style.visibility != "visible") menu_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** menu_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function menu_attach(parent, child, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["menu_parent"]     = p.id;
  c["menu_parent"]     = p.id;
  p["menu_child"]      = c.id;
  c["menu_child"]      = c.id;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;


      p.onmouseover = menu_show;
      p.onmouseout  = menu_hide;
      c.onmouseover = menu_show;
      c.onmouseout  = menu_hide;

}
