/*
FILE NAME: navbar.js
WRITTEN BY: Hyelin Lee
WHEN: April 2009
PURPOSE: javascript for the website's drop down menu
		 Hyelin - with the permission so Sohie Lee, she copied the js code for drop down menu
				  from the cs' website page with "newer drop down menu" example
				  formatted all the codes to look neat
*/

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

// Global menu timeout handle:
///////////////////////////////////////
var Timeout_ID = null;

var debug = '';

/* This function is called to open a drop-down menu if it's not already
open, closing any other menus that might be open. */

function menuOver(MenuID) {
  // debug = debug+'menuOver'+MenuID+"\n";
  // If DOM1 supported and element exists ...
  if((document.getElementById)&&(document.getElementById(MenuID)!=null)){
    // If this menu is already open ...
    if(LiveMenu==document.getElementById(MenuID)){
      // Do not close it
      clearTimeout(Timeout_ID);
    }
    // Another might still be open ...
    else{
      // If another menu is open ...
      if(LiveMenu!=null){
        // Do not wait, shut it now
        clearTimeout(Timeout_ID);
        hideNow();
      }
    }
    // This is the new 'live' menu, make it visible
    LiveMenu = document.getElementById(MenuID);
    // 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!=null)){
      LiveMenu.style.visibility = 'visible';
    }
  }
}

/* This function keeps a menu it open if it's already open, but does
nothing if there's no menu open. The idea is that when you move down from
the link to the menu that has just been opened, this is called to keep it
open. */

function stayOpen(MenuID){
  // debug = debug+'stayOpen'+MenuID+"\n";
  // 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);
}

function menuOut(MenuID){
  // debug = debug+'menuOut'+MenuID+"\n";
  // 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
    Timeout_ID = window.setTimeout('hideNow();',250);
  }
}

// Called by menu handlers to shut
// previous menu immediately
///////////////////////////////////////
function hideNow(){
  // debug = debug+'hideNow'+"\n";
  if((LiveMenu.style)&&(LiveMenu.style.visibility)){
    LiveMenu.style.visibility = 'hidden';
  }
}   
