var alea_menus = new Array();
var alea_timer = 0;
var alea_lastMenu = null;
var alea_offsetTop = 247;
var alea_offsetLeft = 273;


function alea_getImage(node) {
  if (node && node.hasChildNodes()) {
    for (var i = 0; i < node.childNodes.length; i++) {
      if (node.childNodes[i].nodeType == 1 && node.childNodes[i].nodeName == "IMG") {
        return node.childNodes[i];
      }
    }
  }

  return null;
}

function alea_getTop(l) {
  return l.offsetTop + (l.offsetParent ? alea_getTop(l.offsetParent) : 0);
}
function alea_getLeft(l) {
  return l.offsetLeft + (l.offsetParent ? alea_getLeft(l.offsetParent) : 0);
}

function alea_menuObj(top_id, top_on, top_off, sub_id) {
  this.top_item = document.getElementById(top_id);
  this.top_on = top_on;
  this.top_off = top_off;
  this.top_img = alea_getImage(this.top_item);

  if (this.top_item) {
    this.top_item.menu = this;
    this.top_item.onmouseover = alea_topOn;
    this.top_item.onmouseout = alea_topOff;
  }

  this.sub_item = null;
  if (sub_id) {
    this.sub_item = document.getElementById(sub_id);
    if (this.sub_item) {
      this.sub_item.menu = this;
      this.sub_item.onmouseover = alea_subOn;
      this.sub_item.onmouseout = alea_subOff;
    }
  }

  this.menuOn = alea_menuOn;
  this.menuOff = alea_menuOff;
}

function alea_menuOn() {
  this.top_img.src = this.top_on;
  if (this.sub_item) {
    this.sub_item.style.top = alea_getTop(document.getElementById("holder")) + alea_offsetTop + "px";
    this.sub_item.style.left = alea_getLeft(document.getElementById("holder")) + alea_offsetLeft + "px";
    this.sub_item.style.display = "block";
  }
}

function alea_menuOff() {
  this.top_img.src = this.top_off;
  if (this.sub_item) {
    this.sub_item.style.display = "none";
  }
}

function alea_setTimer() {
  alea_resetTimer();
  alea_timer = setTimeout("alea_hideMenu()", 850);
}

function alea_resetTimer() {
  if (alea_timer > 0) {
    clearTimeout(alea_timer);
    alea_timer = 0;
  }
}

function alea_topOn() {
  alea_resetTimer();

  if (alea_lastMenu && alea_lastMenu != this.menu) {
    alea_lastMenu.menuOff();
  }

  alea_lastMenu = this.menu;
  this.menu.menuOn();
}

function alea_topOff() {
  alea_setTimer();
}

function alea_subOn() {
  alea_resetTimer();
}

function alea_subOff() {
  alea_setTimer();
}

function alea_hideMenu() {
  if (alea_lastMenu) {
    alea_lastMenu.menuOff();
    alea_lastMenu = null;
  }
}

function addMenu(top_id, top_on, top_off, sub_id) {
  alea_menus[alea_menus.length] = new alea_menuObj(top_id, top_on, top_off, sub_id);
}
