/////////////////////////////////////////////////////////////

// Ensure that code is running under proper version of IE

/////////////////////////////////////////////////////////////

var menuBarActiveFlag;

if ( navigator.userAgent.indexOf( "MSIE" ) != -1 &&

     navigator.userAgent.indexOf( "Windows" ) != -1 && 

	  navigator.appVersion.substring(0,1) > 3 )

{

	menuBarActiveFlag = true;

}

else 

{ 

   menuBarActiveFlag = false; 

} 



/////////////////////////////////////////////////////////////

// Initialization block 

/////////////////////////////////////////////////////////////

if ( menuBarActiveFlag == true ) 

{

   // Constants 

	var CRLF = String.fromCharCode( 10 );

	var QUOTE = String.fromCharCode( 34 );

	var MAXITEMS = 40;

	

	// Vars 

	var menuBarObject;

	var menuBarLoaded = false;

	var menuBarCount = 0;

	var dropDownFlag = true;

	var currentMenuItem = "";  

	var xPos = 0;

	var x2Pos = 0;

	var yPos = 0;

	var y2Pos = 0;

	

   // Properties 

	var menuFont = "bold xx-small Verdana";

	var menuBgColor = "black";   

	var menuFontColor = "white";	 

	var menuMouseOverColor = "#FF9900";	



	var menuBarItems = new Array( 40 );  // This number needs to synch with MAXITEMS const

	var menuBarMinWidth;

	var menuBarHtmlCode;



	// Write stylesheet and menubar's span id 

	document.write("<SPAN ID='spanMenuBar' STYLE='display:none;'></SPAN>");



	// Build menubar 

	menuBarHtmlCode = 



		"<DIV ID='divMenuBar' STYLE='background-color:white;width:100%'>" + CRLF + 

           "<DIV ID='divSpacer1' STYLE='position:relative;height:0;'>" +

		         "<DIV ID='divTopBanner' STYLE='position:absolute;top:0;left:0;height:0;width:250;overflow:hidden;vertical-align:top;'<!--START_TOP_BANNER_AREA--><!--END_TOP_BANNER_AREA--></DIV>" +

		     "</DIV>" +

		     "<DIV ID='divSpacer2' STYLE='position:relative;left:250;height:0;'>" +

		         "<DIV ID='divFiller' STYLE='position:absolute;top:0;left:0;height:40;vertical-align:top;overflow:hidden;'></DIV>" +

		     "</DIV>" +

		     "<DIV ID='divSpacer3' STYLE='position:relative;height:20;width:100%'>" +

		          "<DIV ID='divMenuPane' STYLE='position:absolute;top:0;left:0;height:20;background-color:black;' NOWRAP><!--TOP_LEVEL_MENU_PROXY--></DIV>" +

		     "</DIV>" +

		"</DIV>" + CRLF +

		

		"<SCRIPT LANGUAGE='JavaScript'>" + 

		"   var menuBarObject = spanMenuBar;" + 

		"</SCRIPT>" + 

		"<DIV WIDTH=100%></DIV>";



	// Define event handlers

	window.onresize  = resizeMenubar;

}





/////////////////////////////////////////////////////////////

// menuItem object constructor 

/////////////////////////////////////////////////////////////

function menuItem( fID )

{

	this.id = fID;

	this.unit  = 0;

	this.width = 0;

	this.count = 0;

}



/////////////////////////////////////////////////////////////

// renderMenubar() 

/////////////////////////////////////////////////////////////

function renderMenubar()

{

	if ( menuBarActiveFlag == false ) return;



	document.write( menuBarHtmlCode );

	menuBarLoaded = true;

	menuBarMinWidth = 268; 



	divMenuBar.style.backgroundColor = menuBgColor;

	divMenuPane.style.backgroundColor = menuBgColor;



	resizeMenubar();



	for (i = 0; i < menuBarCount; i++) 

	{

		myMenu = document.all( menuBarItems[i].id );

		if ( myMenu != null ) { myMenu.style.width = menuBarItems[i].unit; }

	}

}





/////////////////////////////////////////////////////////////

// resizeMenubar() 

/////////////////////////////////////////////////////////////

function resizeMenubar()

{

	if ( menuBarActiveFlag == false ) return;



	divMenuPane.style.width = document.body.clientWidth; 

}





/////////////////////////////////////////////////////////////

// addMenu() 

/////////////////////////////////////////////////////////////

function addMenu( menuID, caption, menuUrl, target )

{ 	



   // Before adding, check count 

	if ( menuBarCount == MAXITEMS )

	{

		alert("Error. Unable to generate menubar. A maximum of " + MAXITEMS + " items has been reached.");

		return;

	}



   var s = CRLF; 



	if ( target == '' ) { target = '_top'; } 



	menuID = "MBAR_" + menuID; 



	proxyStr  = "<!--TOP_LEVEL_MENU_PROXY-->";



	s += "<A TARGET='" + target + "'" + " ID='aMBAR_" + menuID + "'" +

		  " STYLE='text-decoration:none;cursor:hand;font:" + menuFont 

		   + ";background-color:" + menuBgColor + ";color:" + menuFontColor + ";'";



	if ( menuUrl != "" )

 	  s += " HREF='" + menuUrl + "'";

	else

		s += " HREF='' onclick='window.event.returnValue=false;'";



	s += 	" onmouseout="  + QUOTE + "mouseState('out' ,'" + menuID + "'); hideDropDownMenu();" + QUOTE + 

				" onmouseover=" + QUOTE + "mouseState('over','" + menuID + "'); showDropDownMenu('"+ menuID + "');" + QUOTE + ">" +

				"&nbsp;" + caption + "&nbsp;</a>";



	s += proxyStr;

	

	menuBarHtmlCode = menuBarHtmlCode.replace( proxyStr, s );	



   // Do a check to see if its already there 

	var foundFlag = false;

	for ( i = 0; i < menuBarCount; i++ )

		if ( menuBarItems[i].id == menuID )

		{

			foundFlag = true;

			break;

		}



   // If not, then add 

	if ( foundFlag == false )

	{

		menuBarItems[i] = new menuItem( menuID );

		menuBarCount += 1;  // Update counter 

		menuBarItems[i].unit = 195; // **** width of submenu

	}



}



/////////////////////////////////////////////////////////////

// addMenuItem() 

/////////////////////////////////////////////////////////////

function addMenuItem( menuID, caption, menuUrl, target )

{	



   // Before adding, check count 

	if ( menuBarCount == MAXITEMS )

	{

		alert("Error. Unable to generate menubar. A maximum of " + MAXITEMS + " items has been reached.");

		return;

	}



	if ( target == '' ) { target = '_top'; } 

	

	menuID = "MBAR_" + menuID;

	

	var pos = menuID.toUpperCase().indexOf( "MENU" );

	if ( pos == -1) { pos = menuID.length; }



	iStr = menuID.substring( 0 , pos ) + caption; 

	uStr = menuUrl; 



	var tagLocator  = "<!--" + menuID + "-->";

	var sPos = menuBarHtmlCode.indexOf( tagLocator );



	// if not found, then add 

	if (sPos <= 0)

	{

		menuBarHtmlCode += CRLF + CRLF +

				"<SPAN ID='" + menuID + "'" +

				" STYLE='display:none;position:absolute;width:160;background-color:" + 

				  menuBgColor + ";padding-top:0;padding-left:0;padding-bottom:20;z-index:9;'" +

				" onmouseout='hideDropDownMenu();'>";



		menuBarHtmlCode += "<HR STYLE='position:absolute;left:0;top:0;color:" + menuFontColor + "' SIZE=1>";

		menuBarHtmlCode += "<DIV STYLE='position:relative;left:0;top:8;'>";

	}



	s = CRLF +

		"<A ID='aMBAR_" + menuID + "'" +

		" STYLE='text-decoration:none;cursor:hand;font:" + menuFont + ";color:" + menuFontColor + "'" +

		" HREF='" + uStr + "' TARGET='" + target + "'" +

		" onmouseout="  + QUOTE + "mouseState('out' ,'" + menuID + "');" + QUOTE + 

		" onmouseover=" + QUOTE + "mouseState('over','" + menuID + "');" + QUOTE + ">" +

		"&nbsp;" + caption + "</A><BR>" + tagLocator ;



   // if not found

	if ( sPos <= 0 )

		menuBarHtmlCode += s + "</DIV></SPAN>";

	else

	   // if found, then replace 

		menuBarHtmlCode = menuBarHtmlCode.replace( tagLocator, s );	

}



/////////////////////////////////////////////////////////////

// addMenuSeparator() 

/////////////////////////////////////////////////////////////

function addMenuSeparator( menuID )

{	

	menuID = "MBAR_" + menuID;

	var tagLocator = "<!--" + menuID + "-->";

	var pos = menuBarHtmlCode.indexOf( tagLocator );

	if ( pos > 0 )

	{

		s = CRLF + "<HR STYLE='color:" + menuFontColor + "' SIZE=1>" + tagLocator;

		menuBarHtmlCode = menuBarHtmlCode.replace( tagLocator, s );

	}

}



/////////////////////////////////////////////////////////////

// mouseState() 

/////////////////////////////////////////////////////////////

function mouseState( id ) 

{

	mouseoutFlag = ( id.toUpperCase().indexOf( "OUT" ) != -1 );



	if ( mouseoutFlag == true )

		c = menuFontColor;

	else

		c = menuMouseOverColor;



   window.event.srcElement.style.color = c;

}



/////////////////////////////////////////////////////////////

// showDropDownMenu()

/////////////////////////////////////////////////////////////

function showDropDownMenu( menuID ) 

{

	var myMenu = document.all( menuID );



	if (menuBarObject == null || myMenu == null || myMenu == menuBarObject ) 

	{

		window.event.cancelBubble = true;

		return false;

	}

	

	// Reset dropdown menu

	window.event.cancelBubble = true;

	menuBarObject.style.display = "none";

	menuBarObject = myMenu;



	// Set position of dropdown menu 

	xPos = ( window.event.srcElement.offsetLeft + window.event.srcElement.offsetParent.offsetLeft );

	x2Pos = xPos + window.event.srcElement.offsetWidth;

	yPos  = ( divSpacer1.offsetHeight + divSpacer2.offsetHeight + divSpacer3.offsetHeight );

	myMenu.style.top  = yPos;

	myMenu.style.left = xPos;

	myMenu.style.clip = "rect(0 0 0 0)";

	myMenu.style.display = "block";



	window.setTimeout( "showMenuPriv()", 3 );

	return true;

}



/////////////////////////////////////////////////////////////

// showMenuPriv()

/////////////////////////////////////////////////////////////

function showMenuPriv() 

{

	if ( menuBarObject != null ) 

	{ 

		y2Pos = yPos + menuBarObject.offsetHeight;

		menuBarObject.style.clip = "rect( auto auto auto auto )";

	}

}



/////////////////////////////////////////////////////////////

// hideDropDownMenu()

/////////////////////////////////////////////////////////////

function hideDropDownMenu()

{

	if ( menuBarObject != null && menuBarObject != spanMenuBar ) 

	{

		// Check to see if mouse is moving between the top menu and menu items; if so, don't hide 

		cY = event.clientY + document.body.scrollTop;

		if ( (event.clientX >= (xPos+5) && event.clientX <= x2Pos) &&

			 ((dropDownFlag == true  && cY > (yPos-10) && cY <= y2Pos)      ||

			  (dropDownFlag == false && cY >= yPos     && cY <= (y2Pos+10)) ))

		{

			window.event.cancelBubble = true;

			return; 

		}



		menuBarObject.style.display = "none";

		menuBarObject = spanMenuBar;

		window.event.cancelBubble = true;

	}

}



