var menu_hover_old_onload = window.onload ? window.onload : function() {};

var menu_hover_current = null;
var menu_hover_timeout = null;

function menu_hover_change(dest)
{
  if (menu_hover_timeout) {
    clearTimeout(menu_hover_timeout);
    menu_hover_timeout = null;
  }
  if (menu_hover_current == dest) return;
  if (menu_hover_current) {
    menu_hover_current.className = menu_hover_current.className.replace(" hover", "");
  }
  if (dest) {
    dest.className += " hover";
  }
  menu_hover_current = dest;
}

function menu_hover_onload()
{
  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 old_onmouseover = node.onmouseover ? node.onmouseover : function() {};
      node.onmouseover = function() {
        old_onmouseover();
        menu_hover_change(this);
      }

      var old_onmouseout = node.onmouseout ? node.onmouseout : function() {};
      node.onmouseout = function() {
        old_onmouseout();
        if (menu_hover_timeout) clearTimeout(menu_hover_timeout);
        menu_hover_timeout = setTimeout('menu_hover_change(null);', 2000);
      }
    }
  }
}



var panes = new Array();


function setupPanes(containerId, defaultTabId) {
  // go through the DOM, find each tab-container
  // set up the panes array with named panes
  // find the max height, set tab-panes to that height
  panes[containerId] = new Array();
  var maxHeight = 0; var maxWidth = 0;
  var container = document.getElementById(containerId);
  var paneContainer = container.getElementsByTagName("div")[0];
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
    if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
    paneContainer.style.height = maxHeight + "px";
    paneContainer.style.width  = maxWidth + "px";
    document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {
  // make tab active class
  // hide other panes (siblings)
  // make pane visible

    for (var con in panes) {
    activeTab.blur();
    activeTab.className = "tab-active";
    if (panes[con][paneId] != null) { // tab and pane are members of this container
      var pane = document.getElementById(paneId);
      pane.style.display = "block";
      var container = document.getElementById(con);
      var tabs = container.getElementsByTagName("ul")[0];
      var tabList = tabs.getElementsByTagName("a")
      for (var i=0; i<tabList.length; i++ ) {
        var tab = tabList[i];
        if (tab != activeTab) tab.className = "tab-disabled";
      }
      for (var i in panes[con]) {
        var pane = panes[con][i];
        if (pane == undefined) continue;
        if (pane.id == paneId) continue;
        pane.style.display = "none"
      }
    }
  }
  return false;
}

window.onload = function() {
  menu_hover_onload();
  menu_hover_old_onload();

}

