var mnu_idx = 0
var curr_hide_timer = null
var curr_submenumenu	= null
var strSite = "";
function appendHost(path) 
{
	var out
	if(path.replace == null){
		return path;
	}
	// HACK: Links with a value of ??? were causing problems  
	 
	if (path.substring(0,1) == "?"){
		return ""
	} 
	 
	// HACK: Some links came with a javascript: appended.  Superfluous.
	path = path.replace("javascript:","")
	
	if (/goTo\(\"/.test(path)){
		path = path.replace("goTo(\"","");	//sometimes this is being passed in. post-launch fix
		path = path.replace("\")","");		//sometimes this is being passed in. post-launch fix/
		path = path.replace(";","");		//sometimes this is being passed in. post-launch fix
 	}
 
/*
	Change /-rooted URLs to goTo() with server host prefixed to ensure 3rd party partner sites work properly
	strSite is defined in Browser.asp
*/
	if (path.substring(0,1) == "/"){
		out = 'goTo("'+strSite + path+'");'
	}
	else if (path.substring(0,4) == "http"){
		out = 'goTo("'+path+'");';			  	
	}
	else{
  	  // Pass it on through (assume a JS function call or something)
		out = path
	}

	return out
}

function swapSubmenu(name) {
	clearSubmenu()
	showE(name)
	curr_submenumenu = name
	window.clearTimeout(curr_hide_timer)
}

function scheduleClearSubmenu() {
	if (curr_hide_timer){
		window.clearTimeout(curr_hide_timer)
	}
	curr_hide_timer = window.setTimeout('clearSubmenu()', 1000)
}


function clearSubmenu() {
	if (curr_submenumenu) hideE(curr_submenumenu);	
	
	if (curr_hide_timer){
		window.clearTimeout(curr_hide_timer)
		curr_hide_timer = null
	}
}


function HorizMenu(strStyle,root_left, root_top, submenu){
	this.menustyle = strStyle
	this.left	 = root_left
	this.top	  = root_top
	this.submenu = submenu
}


HorizMenu.prototype.render = function() {
	if (this.submenu != null){
		document.write('<div id="mainnav_root'+(mnu_idx)+'" name="mainnav_root'+(mnu_idx)+'" style=" position: absolute; top: '+this.top+'px; left: '+this.left+'px"; z-index: 999 >')
		for (var i=0; i<this.submenu.length; i++){
			if (!this.submenu[i])
				continue
			this.submenu[i].render()
		}

		document.write('</div>')
		
		MenuBG = "#587ca8"; //BG Color of menu
		LineBG = "#7d7d7d";	//Divider Line Color
		if(this.menustyle == "global"){
			MenuBG = "#587ca8"
			LineBG = "#8ea9c8"
		}

		var str = ''
	 
		for (var i=0; i<this.submenu.length; i++){
			var child = this.submenu[i]
			if (!this.submenu[i]){
				continue
			}
			
			if (child.submenu != null){
				str += '<div id="mainnav_'+child.id+'" style="cursor:pointer;display: hidden; visibility: hidden; position: absolute; top: '+child.submenu_top+'px; left: '+child.submenu_left+'px; ; z-index: 999">'
				str += '<table border="0" cellspacing="0" cellpadding="0">'
				str += '<tr><td style="background-color:' + LineBG + '" colspan=3><img src="' + strSite + '/images/sp.gif" width=1 height=1/></td></tr>';		
				for (var j=0; j<child.submenu.length; j++) 
				{
					var submenu_child = child.submenu[j]
					if (!submenu_child)
					{
						continue
					}
					
					if (submenu_child.link !=''){	
								
								if(submenu_child.metrics ==null){
									str += "<tr><td style='background-color:" + LineBG +"'><img src='" + strSite + "/images/sp.gif' height=19 width=1 /></td><td class='navitem" + this.menustyle + "' onmouseover='NavOn(this, \"" + this.menustyle + "\");' onclick='" +  appendHost(submenu_child.link) + "' onmouseout='NavOff(this, \"" + this.menustyle + "\");' >"								 
								}else{
									str += "<tr><td style='background-color:" + LineBG +"'><img src='" + strSite + "/images/sp.gif' height=19 width=1 /></td><td class='navitem" + this.menustyle + "' onmouseover='NavOn(this, \"" + this.menustyle + "\");' onclick='" + submenu_child.metrics + appendHost(submenu_child.link) + "' onmouseout='NavOff(this, \"" + this.menustyle + "\");' >"								 
								
								}
								str +=  "&nbsp;&nbsp;" + submenu_child.label + "&nbsp;&nbsp;"
								str += "</td><td style='background-color:" + LineBG +";' ><img src='" + strSite + "/images/sp.gif' width=1 height=1/></td></tr>"
								str += "<tr><td style='background-color:" + LineBG +"' colspan=3><img src='" + strSite + "/images/sp.gif' width=1 height=1/></td></tr>";	 
			
					} else {
						str += "<tr><td style='background-color:" + LineBG +"'><img src='" + strSite + "/images/sp.gif' height=19 width=1 /></td><td class='navitemheader'>&nbsp;&nbsp;" + submenu_child.label	+"&nbsp;&nbsp;</td><td style='background-color:" + LineBG +";' ><img src='" + strSite + "/images/sp.gif' width=1 height=1/></td></tr>"
						str += "<tr><td style='background-color:" + LineBG +"' colspan=3><img src='" + strSite + "/images/sp.gif' width=1 height=1/></td></tr>"
					}				
				
				
				
				}
		
				str += '</table>'
				str += '</div>'
			}
		} 
		document.write( str  )
	}
}

function NavOn(obj, strStyle){
	obj.className = "navitemroll" + strStyle
	window.clearTimeout(curr_hide_timer)
}

function NavOff(obj, strStyle){
	obj.className = "navitem" + strStyle
	scheduleClearSubmenu()
}


function MenuItem(metrics, label, img_off, img_on, link, submenu_left, submenu_top, dividerimage, submenu){
	 if(metrics == null){
		this.metrics = null;
	 }else{
	 
		this.metrics = metrics.replace("javascript:","")
		 
	}
	this.id	   = "mnu_"+(mnu_idx++)
	this.label	= label
	this.img_on   = img_on
	this.img_off  = img_off
	this.link	 = link
	this.submenu = submenu
	this.submenu_left = submenu_left
	this.submenu_top  = submenu_top
	this.divider = dividerimage 
	
}


// Top Level Menu
MenuItem.prototype.render = function (){
	 var str = ''
	 var show_submenu = ''
	 var hide_submenu = ''
	
	 if (this.submenu != null){
		show_submenu = "swapSubmenu('mainnav_" + this.id + "'); "
		hide_submenu = ""
	 }
	
	if (this.img_off != null){
		var roll_on  = ""
		var roll_off = ""
	
		 if (this.img_on != null){
			roll_on  = "MM_swapImage('"+this.id+"','','" + strSite + "/images/news/"+this.img_on+"',1);"
			roll_off = "MM_swapImgRestore();"
		 }
		 if(this.metrics == null){
			 str += '<a href=\'javascript:' + appendHost(this.link)+'\' target="_top"'
		 }else{
			 
			 str += '<a href=\'javascript:' + this.metrics + appendHost(this.link)+'\' target="_top"'
		 
		 }
		 str += 'onmouseover="NavOn(this);'+roll_on+show_submenu+'"'
		 str += 'onmouseout="NavOff(this);'+roll_off+hide_submenu+'">'
		 str += '<img id="'+this.id+'" name="'+this.id+'" src="' + strSite + '/images/news/'+this.img_off+'" border="0" />'
		 
		if(this.divider){
			str += '<img src="' + strSite + '/images/news/' + this.divider + '" border=0>'
		} 
		str += '</a>'
	}
	document.write( str  )
}

function MenuDecoration(label, img){
	this.id	   = "submenumnu_"+(mnu_idx++)
	this.img	  = img
	this.label	= label
}

MenuDecoration.prototype.render = function (){
	if (this.img != null){
		document.writeln('<img src="'+this.img+'" /><br />')
	}
	else{
		document.writeln(this.label+'<br />')
	}
}


function sideNavOn(obj, bgN){
	obj.className = "sideNavOn" + bgN
}

function sideNavOff(obj,bgN){
	obj.className = "sideNavOff" + bgN
}

function SideNavMenu(head_src, foot_src, submenu){
	this.head_src  = head_src
	this.foot_src  = foot_src
	this.submenu	= submenu
	this.menustyle  = 'global'
}


 



 