var menuOnLoadW = window.onload ? window.onload : function() {};

var currentElement = null;
var timeoutId = null;

function switchItem(li)
{
  if (timeoutId) {
    clearTimeout(timeoutId);
    timeoutId = null;
  }
  if (currentElement == li) return;
  if (currentElement) {
    currentElement.className = currentElement.className.replace(" hover", "");
  }
  if (li) {
    li.className += " hover";
  }
  currentElement = li;
}

function menuOnLoad()
{
  if (!document.getElementById) return;
  
  var menu = document.getElementById("page_menu");
  var children = menu.childNodes;
  for (var i = 0; i < children.length; i++) {
    var node = children[i];
    if (node.className && node.className.indexOf("menu_tab") != -1) {
      var onmouseoverW = node.onmouseover ? node.onmouseover : function() {};
      node.onmouseover = function() {
        onmouseoverW();
        switchItem(this);
      }

      var old_onmouseout = node.onmouseout ? node.onmouseout : function() {};
      node.onmouseout = function() {
        old_onmouseout();
        if (timeoutId) clearTimeout(timeoutId);
        timeoutId = setTimeout('switchItem(null);', 600);
      }
    }
  }
}

window.onload = function() {
  menuOnLoad();
  menuOnLoadW();
}
