//menu
function menu_show(cParent, cChild) {
  var oParent = document.getElementById(cParent);
  var oChild = document.getElementById(cChild);

  oParent.className = "active";

  var top  = (oChild["menu_position"] == "y") ? oParent.offsetHeight+5 : 

0;
  var left = (oChild["menu_position"] == "x") ? oParent.offsetWidth +2 : 

0;

  for (; oParent; oParent = oParent.offsetParent)
  {
   if (oParent.style.position != 'absolute')
   {
     left += oParent.offsetLeft;
     top  += oParent.offsetTop;
  }
  }

  oChild.style.position   = "absolute";
  oChild.style.top        = top +'px';
  oChild.style.left       = left+'px'; 
  oChild.style.visibility = "visible";
}

function menu_hide(cParent, cChild)
{
  document.getElementById(cParent).className = "parent";
  document.getElementById(cChild ).style.visibility = "hidden"; 
}

function menu_show_parent()
{
  oChild = document.getElementById(this["menu_child" ]);
  menu_show(this.id, oChild.id);
  clearTimeout(oChild["menu_timeout"]); 
}

function menu_show_child()
{
  oParent = document.getElementById(this["menu_parent"]);
  menu_show(oParent.id, this.id);
  clearTimeout(this["menu_timeout"]); 
}

function menu_hide_parent()
{
  oChild = document.getElementById(this["menu_child" ]);
  oChild["menu_timeout"] = setTimeout("menu_hide('" + this.id + "', '" + oChild.id + "')", 100);
}

function menu_hide_child()
{
  oParent = document.getElementById(this["menu_parent"]); 
  this["menu_timeout"] = setTimeout("menu_hide('" + oParent.id + "', '" + this.id + "')", 100);
}

function menu_attach(cParent, cChild, cPos) { 

  oParent = document.getElementById(cParent);
  oChild = document.getElementById(cChild);

  oParent["menu_child"] = oChild.id;
  oChild["menu_parent"] = oParent.id;
  oChild["menu_position"] = cPos; 

  oParent.onmouseover = menu_show_parent;
  oParent.onmouseout  = menu_hide_parent;
  oChild.onmouseover = menu_show_child;
  oChild.onmouseout  = menu_hide_child;
}

function CreateMenuItem(cParent, cChild, cPos) { 
  document.getElementById(cParent).className = "parent";
  document.write('<div class="menu_v" id="' + cParent + '_child">');

  n = 0;
  for (var i in cChild) 
  {
    if (i == '-')
    {
      document.getElementById(cParent).href = cChild[i];
      continue;
    }

    if (typeof cChild[i] == "object")
    {
      document.write ('<a class="parent" id="' + cParent + '_' + n + '">' 

+ i + '</a>');
      CrearMenuItem(cParent + '_' + n, cChild[i], "x"); 
    }
    else document.write('<a id="' + cParent + '_' + n + '" href="' + 
cChild[i] + '">' + i + '</a>');
    n++;
  }

  document.write ('</div>');

  menu_attach(cParent, cParent + "_child", cPos);
}

function CreateMenu(aMenu) {
  for (var n in aMenu) CreateMenuItem(n, aMenu[n], "y");
}
