/*
	Menu Controls v 1.0
	by Cary Clayton <cclayton@epierce.com>
	and Matt Cannon <mcannon@epierce.com>
*/

var DEBUG_MENU = false;
//=========================commented until pop up menu is done===================================
//var MENUS_ACTIVE = (is.version4);
var MENUS_ACTIVE = true;
//=========================commented until pop up menu is done===================================

var POPPED = false;
var ON_MENU = false;
var CURRENT_MENU = "";
var CURRENT_LEVEL1 = "";
var CURRENT_LEVEL2 = "";  
var CURRENT_TOP = ""; 
var thisagt=navigator.userAgent.toLowerCase();
	
setInterval("cleanUpMenus()",30000);
showGlobals();

function getMenuObject(id){
	var o = null;
	
		if (document.getElementById) { //W3C
			o = document.getElementById(id); 				
		}
		else if(document.all) { //IE4
			o = document.all[id];			
		}
		else if(document.layers) { //NN4
			o = document.layers[id];			
		}
	return o;
}

function showGlobals(){
	if (DEBUG_MENU) {
		var global_variables = "Global Variables:\n";
		global_variables += "\nMENUS_ACTIVE - "+MENUS_ACTIVE;
		global_variables += "\nPOPPED - "+POPPED;
		global_variables += "\nON_MENU - "+ON_MENU;
	}
}

function mouseOver(object) {
	if (MENUS_ACTIVE) {
   	ON_MENU = true;
	CURRENT_MENU = object;
		if (CURRENT_LEVEL1 != '' && CURRENT_LEVEL1 != CURRENT_MENU) {
			menuDown(CURRENT_LEVEL1);
		}	
		CURRENT_LEVEL1 = CURRENT_MENU;
		return popUp(object);
	}
	return false;
}

function mouseOut(object) {
	//if (DEBUG_MENU) {alert("mouseout()");}
	if (MENUS_ACTIVE) {
		ON_MENU = false;
		setTimeout('cleanUpMenus()',3000);
	}
	return false;
}

function popUp(object){
	if (MENUS_ACTIVE) {
	//if (DEBUG_MENU) {alert("popUp('"+object+"')");}
		return menuUp(object);
	}
	return false;
}

function popDown() {
	if (MENUS_ACTIVE) {
	if (CURRENT_LEVEL1 != '') {
			menuDown(CURRENT_LEVEL1);
			CURRENT_LEVEL1 = '';
		}	
	}
	return false;
}

function menuUp(object) {
	if (MENUS_ACTIVE) {
		//if (DEBUG_MENU) {alert("menuUp('"+object+"')");}
		var span = getMenuObject("span_"+object);
		var div = getMenuObject("div_"+object);
		var divUP = false;
		var spanUP = false;
		if (div != null) {show(div,"div",object);divUP = true;}
		if (span != null) {show(span,"span",object);spanUP = true;}
		
		POPPED = (spanUP && divUP);
		
	}
	return false;
}

function menuDown(object) {
	if (MENUS_ACTIVE) {
	//	if (DEBUG_MENU) {alert("menuDown('"+object+"')");}
		var span = getMenuObject("span_"+object);
		var div = getMenuObject("div_"+object);
		if (div != null) {hide(div);}
		if (span != null) {hide(span);}
	}
	return false;
}

function cleanUpMenus() {
	if (MENUS_ACTIVE) {
		if (!ON_MENU) {
			popDown();
			}
	}
	return true;
}

function show(o,type,id){
	var span = getMenuObject("span_"+id);
	if (document.layers) {
		if((span != null) && type == "div"){//box
			if(id == "hcp"){
				o.pageY = getMenuObject("span_"+id).pageY - 28;			
			}else{
				o.pageY = getMenuObject("span_"+id).pageY - 22;
			}		
		}
		//alert(o.pageY);
		o.visibility = 'show';
		o.zIndex = '100';	//need to set zIndex for NS 4.x			
	}
	else {
		//alert(type + " =f " + findPosY(o));
		if((span != null) && type == "div"){//box
			if(id == "hcp"){
				o.style.top = findPosY(getMenuObject("span_"+id)) - 28;			
			}else if ((id == "ss_care_message1") && (thisagt.indexOf("mac")==-1) && (thisagt.indexOf("msie") != -1)){//hack for ss message (PC/IE only)
				o.style.top = findPosY(getMenuObject("span_"+id)) - 71;
			}else{
				o.style.top = findPosY(getMenuObject("span_"+id)) - 22;
			}
		}
		o.style.visibility = 'visible';		
		if ((thisagt.indexOf("mac")!=-1) && (thisagt.indexOf("msie") != -1) && (thisagt.indexOf("opera") == -1)){
			o.style.zIndex = '100';		//need to set zIndex for MAC IE!!!	
		}
	}
}

function hide(o){
	var toClass = (o.id.indexOf("span") >= 0) ? "menulineoff" : "menupopupoff";
	if (document.layers) {
		o.visibility = "hide";		
	}
	else {
		o.style.visibility = "hidden";	
	}
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{			
			curtop += obj.offsetTop;
			//alert(obj.id + " y = " + curtop);
			obj = obj.offsetParent;
		}
	}
	else if (obj.y){
		curtop += obj.y;}
	return curtop;
}
