/** 
 *
 * Some notes on the menu object
 * Rollover images are referenced by id = "{@menu_name}_img"
 * Sub Menus are references by id = "{@menu_name}_img"
 * extensions to the images are set upon construction
 * path_name to the images location should also be set, but not done yet
 *
 **/

/**
 *
 * menu_names : comma seperated list of names of each menu
 *              e.g index, products, aboutus 
 * IMG extension type is .jpg or .png
 * IMG path ; path to images for rollovers
 **/
function initMenu (number_Menus, menu_Names,img_Path, img_extension_Type)
{
  this.img_extension_type = img_extension_Type ;
  this.number_menus = number_Menus ;
  this.img_path = img_Path ;

  //methods
  this.initMenu = initMenu ;
  this.display_subMenu = display_subMenu ;

  this.menu_names = new Array() ;
  var count = 0 ;
  var index = 0 ; //number of characters into string
  var temp_menu_name = "" ;
  while (count < number_Menus){
    
    index = menu_Names.indexOf(",")
      if (index == -1)
	 temp_menu_name = menu_Names;
      else
	temp_menu_name = menu_Names.substring(0, index);
    
    if (index == -1)
      break; 
    
    this.menu_names[count] = temp_menu_name ;
    menu_Names = menu_Names.substring(index + 1 ) ;
    count ++ ;  
  }
}
    

function display_subMenu (id,  display)
{
  // hide all other menus first
  // also reset any roll over images
  // now display roll over and submenu
  //also make sure that a menu of that id exists first
  
  var sub_menu, menu_img ;
  for (i=0 ; i < this.number_menus ; i++){
    sub_menu = document.getElementById(this.menu_names[i] + "_submenu") ;
    menu_img = document.getElementById(this.menu_names[i] + "_img") ;
    //see if a sub_menu exists
    if (sub_menu){
      if ((this.menu_names[i] == id ) && (display=="true")){
	//display
	sub_menu.style.visibility = "visible" ;
	sub_menu.style.display = "block" ;
	menu_img.src = this.img_path + this.menu_names[i] + "_rollover" + this.img_extension_type ;
	
      }	
      else { 
	//hide
	sub_menu.style.visibility = "hidden" ;
	sub_menu.style.display = "none" ;
	menu_img.src = this.img_path + this.menu_names[i] + this.img_extension_type ;
      }
    }
  }	
  return true ;
}

var timerID = 0 ;
function setTimeOut(time)
{
  if (timerID) clearTimeout(timerID);
  timerID = setTimeout("menu.display_subMenu('index','false')" ,time);
  
}

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/index.html";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

if (!((browser.isIE && (browser.version >= 5)) 
      || (browser.isNS && browser.version >= 6))) {
  if (document.cookie != "browser_detect=yes"){
    //set the cookie after the alert
    alert ("Your web browser version may not display this page correctly.\nPlease upgrade your browser.") ;
    document.cookie = "browser_detect=yes" ;
  }	
}

/**
 *
 * Function: loadElementIntoContainer
 * This function will load an element given by an ID
 * into a container given by another ID.
 *
 **/

function loadElementIntoContainer (element_id, container_id)
{
  // removes original element (given by FirstChild)
  // then adds element as first child.
  // based on CSS styles of visibility
  
  var element = document.getElementById(element_id) ;
  var container = document.getElementById(container_id) ;
  var clone = element.cloneNode (true) ; //deep clone
  
  while (container.hasChildNodes()){
    var childNode = container.firstChild ;
    container.removeChild (childNode) ;
  }
  clone.style.visibility = "visible" ;
  clone.style.display = "block" ;
  container.appendChild (clone) ;
}

function hideElement (element_id)
{
  var element = document.getElementById(element_id) ;
  element.style.visibility = "hidden" ;
  element.style.display = "none" ;
}
