/* --------------------------------- */
/* Created:      2000-10-21          */
/* Issued:       2001-01-11          */
/* Modified:     2001-07-14          */
/* Copyright (c) 2001-2004 by        */
/* Philip Shaw, all rights reserved. */
/* --------------------------------- */

// Global menu element handle:
///////////////////////////////////////
var LiveMenu = null;

// Global menu timeout handle:
///////////////////////////////////////
var Hide_Timeout_ID = null;
var Show_Timeout_ID = null;

// Opens or keeps open a given menu
// and shuts any previous menu:
///////////////////////////////////////
function menuOver(node){
  // If DOM1 supported and element exists ...
  var MenuID = node;
  //alert(MenuID);
  if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
    //alert(document.getElementById(MenuID));
    // If this menu is already open ...
    if(LiveMenu==document.getElementById(MenuID)){
      // Do not close it
      clearTimeout(Hide_Timeout_ID);
    }
    // Another might still be open ...
    else{
      // If another menu is open ...
      if(LiveMenu!=null){
        // Do not wait, shut it now
        clearTimeout(Hide_Timeout_ID);
        hideNow();
      }
    }
    // This is the new 'live' menu, make it visible
    LiveMenu = document.getElementById(MenuID);
    //alert(LiveMenu);
    // LiveMenu.style.visibility is
    // initially empty in IE5 until
    // it is assigned by these
    // functions, so must check that
    // it's not null before proceeding...
    // Prepare to shut it in 250 milliseconds
    Show_Timeout_ID = window.setTimeout('showNow();',500);
    //if((LiveMenu.style)&&(LiveMenu.style.visibility!=null)){
    //  LiveMenu.style.visibility = 'visible';
    //}
  }
}

// Stops menu links from opening menu
// onmouseover when shut to
// workaround mouse events which are
// not hidden by z-index in Opera 4!
///////////////////////////////////////
function stayOpen(MenuID){
  // If menuOver has not been called or the menu is hidden, do nothing
  if((LiveMenu==null)||((LiveMenu.style)&&(LiveMenu.style.visibility)&&(LiveMenu.style.visibility=='hidden')))return;
  else menuOver(MenuID);
}

// Shuts a given menu in 250
// milliseconds, unless timeout is
// cleared by menuOver()
///////////////////////////////////////
function menuOut(node){
  var MenuID = node;
  // If DOM1 supported and a menu is open ...
  if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
    // Get the current live menu
    LiveMenu = document.getElementById(MenuID);
    // Prepare to shut it in 250 milliseconds
    clearTimeout(Show_Timeout_ID);
    Hide_Timeout_ID = window.setTimeout('hideNow();',250);
  }
}

// Called by menu handlers to open
// current menu immediately
///////////////////////////////////////
function showNow(){
    // LiveMenu.style.visibility is
    // initially empty in IE5 until
    // it is assigned by these
    // functions, so must check that
    // it's not null before proceeding...
	//alert("In showNow()");
	if((LiveMenu.style)&&(LiveMenu.style.visibility!=null)){
		LiveMenu.style.visibility = 'visible';
	}
}

// Called by menu handlers to shut
// previous menu immediately
///////////////////////////////////////
function hideNow(){
    // LiveMenu.style.visibility is
    // initially empty in IE5 until
    // it is assigned by these
    // functions, so must check that
    // it's not null before proceeding...
	if((LiveMenu.style)&&(LiveMenu.style.visibility)){
		LiveMenu.style.visibility = 'hidden';
	}
}
