 
var browser = navigator.appName.substr(0,2).toUpperCase() ;
var vmainmenutop = "88px" ;
var vsubmenutop = "108px" ;
var menuitemwidth = 120 ;

if(browser=="MI")   // Microsoft
{
	var vmainmenutop = "96px" ;
	var vsubmenutop = "114px" ;
}

var voutlinecolor = "#002222" ; 

// Arrays for the Main menu items
mainmenuarray = new Array("Home Page*0*/index.html",
			  "The Bearhawk*1* ",
			  "Kits*1* ",
			  "Parts*1* ",
			  "News & Articles*0*/News/NewsMain.html",
			  "Contact Us*0*/Contact/ContactMain.html" ) ;

// create the arrays of arrays that contain the submenu items
// each array item is a two element '*' separated string that contains
// 1. the display string  * 2. the location to direct the user to
submarray1 = new Array("") ;
submarray2 =  new Array("Specs*/Bearhawk/BearhawkMain.html",
			"Testimonials*/testimonials/index.html",
			"Photos*/Photos/PhotosMain.html" ) ;

submarray3 =  new Array("Kits & sub-assemblies*/Kits/KitsMain.html",
			"Bearhawk builders*/Builders/BuildersMain.html",
			"Online Plant Tour*/Tour/TourMain.html",
			"Assembly Manual*/assemblymanual/index.html" ,
			"Builders Tips*/usermanual/index.html",
			"Prices*/Pricing/PricingMain.html" ) ;

submarray4 = new Array("Online e-store*/estore/estoreMain_m.html",
			"Patrol parts*/estore/estore_patrol.html",
                	"Preferred Vendors*/vendors/preferredvendors.html" ) ;

//submarray4 = new Array(  "Submenu-4a*/index.html",
//                "Submenu-4b*/index.html",
//                "Submenu-4c*/index.html",
//                "Submenu-4d*/index.html"
//                        ) ;

var menutimer  ;

function rollin(obj)
{
        obj.style.color="#4444cc" ;
}
function rollout(obj)
{
        obj.style.color= voutlinecolor ;
}

function showpopup(obj, submenu_no)
{

	obj.style.color="#4444cc" ;
	//now stop the old  menu timer if any
	stopmenutimer() ;

	// get the position of the main menu item
	var objpos = obj.style.left ;
	// remove the 'px' at the end
	var regexp =/px/ ;
	objpos = parseInt( objpos.replace(regexp,"")) ;
	var subobjpos = objpos + 20 ;

	// now get the id of the submenu
	var vpop = eval("document.getElementById(\"submenu" +submenu_no + "\")") ;
	vpop.style.top =  vsubmenutop ;
	vpop.style.left= subobjpos + "px" ;
	// clear out the previous contents of this element
	vpop.innerHTML = "" ;
	// now dynamically add the individual submenu items
	// this will allow me to swap this stuff out at runtime
	// first find out if the appropriate array exists
	var varr = eval("submarray" + submenu_no) ;
	if(varr)
	{
		var vinner = "" ;
		for( ii=0 ;ii<varr.length ; ii++)
		{
			// get the first part of the array element
			var vsplit = varr[ii].split("*") ;	
			vinner= vinner +"&nbsp;<a href=\""+ vsplit[1]+"\"  >"+
						 vsplit[0]+ "</a><br>"  ;
		}
		vpop.innerHTML = vinner ;
	}

}

function setmenutimer(submenu)
{
	menutimer =setTimeout("stopmenutimer()",300) ;
}

function stopmenutimer()
{
	if(menutimer)
	{
		clearTimeout(menutimer) ;
	}

	// now clear out all the submenus
	var vindex = 1 ;
	var vpop = true ;
	while(vpop )
	{	
		// get the sub menu element
		vpop = eval("document.getElementById(\"submenu" +vindex + "\")") ;
		if(vpop)  vpop.style.top = "-140px" ;		
		vindex++ ;
	}
	// now get all the main menu elements
	vindex = 1 ;
	var vmain = true ;
	while(vmain)
	{
		vmain = eval("document.getElementById(\"mainmenu" + vindex + "\")") ;
		if(vmain)  vmain.style.color= voutlinecolor ;	
		vindex++ ;
	}
}

function holdpopup(obj)
{
	// this should hold this submenu up indefinitely
	clearTimeout(menutimer) ;

}

function closepopup(obj, submenu_no)
{
	//rollout(obj) ;
        obj.style.color= voutlinecolor ;
       // now get the id of the submenu
        var vpop = eval("document.getElementById(\"submenu" +submenu_no + "\")") ;
        vpop.style.top = "-140px" ;
}
// get the number of main menu items
var mainmenuitems = mainmenuarray.length ;
// find the main window width to align the nav menu

var vNavDiv = document.getElementById("navlogo") ;
//function winsize() 
//{
//  var mainwinWidth = 800 ; 
//   if( typeof( window.innerWidth ) == 'number' )  //Non-IE
//     mainwinWidth = window.innerWidth;
//   else if( document.documentElement &&  document.documentElement.clientWidth  ) 
//     mainwinWidth = document.documentElement.clientWidth;
//   else if( document.body && document.body.clientWidth ) 
//    mainwinWidth = document.body.clientWidth;
   // get the total width of all the main menu items and divide in half
//var vmenuleftedge = (mainmenuitems * menuitemwidth )/2;
// to center the menu I need to find the center of the main window
//var wincenter = mainwinWidth / 2 ;
// so the main menu should start at the center minus the left edge
//var mmstartleft = wincenter - vmenuleftedge ; 
//if(mmstartleft < 0) mmstartleft = 0 ;
  //window.alert( 'Width = ' + mainwinWidth );
//  return mmstartleft ;
//	return 162 ;
//}

//var mmstartleft = winsize() ;
var mmstartleft = 110 ;

// set all the menu divs with default values
var mmenustyle =  "border:1px; border-style:solid;"+
		  "background-color:#eeeeee;"+
		  "cursor:pointer;font-weight:bold ; " +
		  "width:"+menuitemwidth+"px; height:18px ;"+ 
		  "text-align:center; font-family:sans-serif;"+
		  "font-size:12px;color:"+ voutlinecolor + ";" +
		  "position:absolute; z-index:4 ;" +
		  "top:" + vmainmenutop  ;

var submenustyle = "border:1px;border-style:solid;padding:4px;"+
		   "background-color:#eeeeee;position:absolute;" +
		   "width:150px;top:-40;position:absolute;font-weight:bold ;" +
		   "font-family:sans-serif; font-size:12px;" +
		   "color:"+voutlinecolor+ ";z-index:7 " ;

var vbody = document.getElementById("Avbody") ;
vbody.setAttribute("link",voutlinecolor) ;

/////// main menu div creation here

for(xi=1 ; xi<=mainmenuitems ;xi++)
{
	// get the main menu array items and split it to get all the descriptions
	var vsplit = mainmenuarray[xi-1].split("*") ;	
	var menutext = vsplit[0] ;  // the main menu text 
	var vflag = vsplit[1] ;     // a flag to show whether there is a submenu
	var vlink = vsplit[2] ;     // a <a href... text 
	
	var onflag = "" ;
	if(vflag == "1")  onflag = " onMouseOver=\"showpopup(this,"+xi+")\" " +
				  " onMouseOut=\"setmenutimer()\" " ;

	if(vflag == "0")  onflag = " onClick=\"location='"+vlink+"'\" " ;

	var thismenustyle = mmenustyle + ";left:" + mmstartleft + "px" ;
	var writethis = "<div style=\"" + thismenustyle + "\" "+
		" id=\"mainmenu" + xi + "\" " + onflag +
		"> " + menutext +  " </div>" ;

	document.write(writethis) ;
	mmstartleft = mmstartleft + menuitemwidth  ;

	writethis = "<div style=\"" + submenustyle + "\" "+
		" id=\"submenu" + xi + "\" " +
		" onMouseOver=\"holdpopup(this)\" " +
		" onMouseOut=\"setmenutimer()\" " +
		">  </div>" ;
	document.write(writethis) ;

}


