// JavaScript Document

//----------------------------------------------------------------------------
// Code to determine the browser and version. www.brainjar.com
//----------------------------------------------------------------------------

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.isFF    = false;  //FireFox
  this.version = null;

  ua = navigator.userAgent;

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

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

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

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

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

var browser = new Browser();

/* ---------------------------------------------- */

var timeOn = null;
var activeMenu = "";
var menuActive = 0;

/**
* This function will display the submenu layers
*
* @param layer_ref 	The name of the layer to show
* @param menu_num 	The menu number to show - refrences a sub-menu array
*/
function showMenu(layer_ref,menu_obj) { 
	/**
	* If a menu/layer is to be shown I must check to see if it is 
	* already visible. If it is I just want to change the content
	*/
	
	//clear the timer
	if(timeOn != null){
		clearTimeout(timeOn);
		//hide activeMenu
		hideMenu(activeMenu);
	}
	
	var targ;
	if (!menu_obj) var menu_obj = window.event;
	if (menu_obj.target) targ = menu_obj.target;
	else if (menu_obj.srcElement) targ = menu_obj.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode;
	
	//alert("target: " + targ);
	
	var objX = findPosX(targ);
	var objY = findPosY(targ) + targ.offsetHeight;
	
	if (browser.isIE || browser.isOP) { //IS IE 4 or 5 (or 6 beta)
		var layer = eval("document.all."+layer_ref);
	}
	
	if (browser.isNS || browser.isFF) {
		var layer = document.getElementById(layer_ref); 
	}
	
	layer.style.top = objY+"px";
	layer.style.left = objX+"px";
	layer.style.visibility = "visible";
	
	activeMenu = layer_ref;

}


/* 
* btnTimer()
* This function waits the set amount of time before calling the function that call the function
* to close the menu contained in 'activeMenu'. This function is called by the root (first) menu item
* when the mouse leaves the rollover.
*/
function btnTimer(){
	timeOn = setTimeout("btnOut()",100);
}

/*
* This function checks to see if menuActive is 0, if true it calls the function 'hideMenu' and passes
* the menu to close 'activeMenu'
*/
function btnOut(){
	if(menuActive == 0){
		hideMenu(activeMenu);
	}
}

/** ---------------------------------------- Menu Functions ----------------------------- **/

/*
* This will hide the activeMenu after 1000 ms
*
* @param mName This is the name of the menu to hide - not implemented
*/
function menuOut(mName) {
	menuActive = 0;
  	timeOn = setTimeout("hideMenu('"+activeMenu+"')", 1000);
}

/*
* This will activate and position third+ menus
*
* @param menuName The name/id of the menu to view
*/
function showItemMenu(menuName,e){
	//clear the timer
	if(timeOn != null){
		clearTimeout(timeOn);
		//hide activeMenu
		hideMenu(activeMenu);
	}
	
	//find the target that initiated the event
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode;
	
	
	
	var objX = findPosX(targ) + targ.offsetWidth;
	var objY = findPosY(targ);
	
	if (browser.isIE || browser.isOP) { //IS IE 4 or 5 (or 6 beta)
		var layer = eval("document.all."+layer_ref);
	}
	
	if (browser.isNS || browser.isFF) {
		var layer = document.getElementById(layer_ref); 
	}
}
/** -------------------------------------- Utility Functions ------------------------------ **/

function menuOver(){
	clearTimeout(timeOn);
	menuActive = 1
}

function hideMenu(mID){
	//alert("menu id: "+mID);
	if(mID){
		if(document.all){
			var hMen = eval("document.all."+mID);
			//hide the div
			hMen.style.visibility = "hidden";
			//clear the value of activeMenu
			activeMenu = "";
		}
		if (document.getElementById &&!document.all) { 
			//alert("getElementById");
			var hza = document.getElementById(mID); 
			
			hza.style.visibility = "hidden";
			
			activeMenu = "";
		} 
	}
}

function hideAllMenus(mObj){
	
	if(document.all){
		var vMenu = document.all.top_menu.childNodes;
		//var vMenu = mObj.childNodes;
		var rstr = "";
		for(var i=0;i<vMenu.length;i++){
			rstr+= "nodeType: "+vMenu[i].nodeType;
			if(vMenu[i].nodeType == 1){
				
				//check for DIV nodes
				if(vMenu[i].nodeName === "DIV"){
					//check for childNodes
					var cNod = vMenu[i].childNodes;
					if(cNod != undefined || cNod != null){
						//there are childNodes
						rstr+="\n";
						for(var c =0;c<cNod.length;c++){
							rstr+="  childNodeType: "+cNod[c].nodeType;
							if(cNod[c].nodeType == 1){
								rstr+=" childNodeName: "+cNod[c].nodeName+"\n";
								//check for DIV
								if(cNod[c].nodeName === "DIV"){
									//now use the object reference to turn visibility off
									cNod[c].style.visibility = "hidden";
								}
							}
						}
					}
				}else{
					rstr+=" no children";
				}
				rstr+="nodeName: "+vMenu[i].nodeName+"\n";
			}else{			
				rstr+=" nodeValue: "+vMenu[i].nodeValue+"\n";
			}
		}
		//alert("childnodes info\n"+rstr);
		//vMenu.style.display = "none";
	}
}

/**
* This function will return the X postion of the passed object
*
* @param obj The object whose postion we're looking for
*/
function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

/**
* This function will return the Y position of the passed object
*
* @param obj The object
*/
function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent){
		
	  curtop += obj.offsetTop;
	  
	  if(obj.offsetParent != null){
		curtop += findPosY(obj.offsetParent);
	  }
		
	}
	else if(obj.y){
		curtop += obj.y;
	}
	return curtop;
}