function gel(a) {
  return document.getElementById(a);
}

var lastShown = 0;
var Menus = Array();

Menus[2] = Array();
Menus[2][0] = Array();
Menus[2][1] = Array();
Menus[2][2] = Array();
Menus[2][3] = Array();
Menus[2][4] = Array();
Menus[2][5] = Array();
Menus[2][0]["Title"] = "Overview";
Menus[2][0]["Link"] = "/products/index.shtml";
Menus[2][1]["Title"] = "Robot Learning";
Menus[2][1]["Link"] = "/products/robot-learning.shtml";
Menus[2][2]["Title"] = "Robot Vision";
Menus[2][2]["Link"] = "/products/computer-vision.shtml";
Menus[2][3]["Title"] = "Visual Localization";
Menus[2][3]["Link"] = "/products/robot-navigation.shtml";
Menus[2][4]["Title"] = "Documents";
Menus[2][4]["Link"] = "/products/downloads.shtml";
Menus[2][5]["Title"] = "FAQ";
Menus[2][5]["Link"] = "/products/faq.shtml";

Menus[4] = Array();
Menus[4][0] = Array();
Menus[4][1] = Array();
Menus[4][2] = Array();
Menus[4][0]["Title"] = "About";
Menus[4][0]["Link"] = "/company/index.shtml";
Menus[4][1]["Title"] = "News";
Menus[4][1]["Link"] = "/news/index.shtml";
Menus[4][2]["Title"] = "Careers";
Menus[4][2]["Link"] = "/company/careers.shtml";

Menus[5] = Array();
Menus[5][0] = Array();
Menus[5][1] = Array();
Menus[5][0]["Title"] = "Online Feedback";
Menus[5][0]["Link"] = "/contacts/index.php";
Menus[5][1]["Title"] = "Contact Information";
Menus[5][1]["Link"] = "/contacts/offices.shtml";

gel('menu1').onclick = show;
gel('menu1').onmouseover = show;
gel('menu1').onfocus = bl;
gel('menu2').onclick = show;
gel('menu2').onmouseover = show;
gel('menu2').onfocus = bl;
gel('menu3').onclick = show;
gel('menu3').onmouseover = show;
gel('menu3').onfocus = bl;
gel('menu4').onclick = show;
gel('menu4').onmouseover = show;
gel('menu4').onfocus = bl;
gel('menu5').onclick = show;
gel('menu5').onmouseover = show;
gel('menu5').onfocus = bl;

_win = gel('win');

function bl() {
  this.blur();
}

function show() {
  xy = getXY(this.parentNode);
  _win.style.left = xy[0] + 1;
  _win.style.top = xy[1] + 37;
  _win.zIndex = 1000;
  
  if(lastShown == this.id && _win.style.visibility != 'hidden') {
    _win.style.visibility = 'hidden';
    return;
  }
  
  menuIndex = this.id.substring(4);
  
  ih = "";
  if(Menus[menuIndex]) {
    if(Menus[menuIndex].length > 0) {
      for(i = 0; i < Menus[menuIndex].length; i++) {
        ih += '<div onmouseover="view(_win, 1)" onmouseout="view(_win, 0)"><a onfocus="this.blur()" onmouseout="view(_win, 0)" onmouseover="view(_win, 1)" href="' + Menus[menuIndex][i]["Link"] + '">' + Menus[menuIndex][i]["Title"] + '</a></div>';
      }
    }
  }
  _win.innerHTML = ih;
  _win.style.visibility = ih == "" ? 'hidden' : 'visible';
  lastShown = this.id;
}

function getXY(el) {
  var x = 0, y = 0;
  while(el) {
    x += el.offsetLeft;
    y += el.offsetTop;
    el = el.offsetParent;
  }
  return Array(x, y);
}

