var prefix = '/';

//  browser sniffer
var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var N6 = (document.getElementById && !document.all) ? true : false;

//  This function swaps images, using the "img" array, defined below.
function menuHi(num, imgname) 
{
	if (menusReady === false) return; 
	
	//  do nothing if highlight is for current section
	if (num/2 === currentSection) return; 
	
	var numIsEven = num % 2 === 0;
	if (numIsEven
	&& currMenu !== -1) 
	{  
		//  hide current menu after 1 sec.
		del = (menus[currMenu].length > 0) ? 1000 : 1;
		menuTimeout = setTimeout('hideMenu()',del);
	}
	if (numIsEven
	&& num/2 === currMenu 
	&& menus[currMenu].length > 0) 
	{
		//  leave highlight on if it's the current menu and menu has items
		return;
	}
	
	if (prefix !== '' && num>=menus.length*2) 
	{  
		//  rollover swap for non-menu nav items
		var navImg = document.images['navImg'+currentSection];
		if (numIsEven)
		{
			navImg.src = img[1+currentSection*2].src;
		}
		else 
		{
			navImg.src = img[currentSection*2].src;
		}
	}
	imgname.src = img[num].src;
}

//  Define on and off menu IMG SRC here.  "off" state first, "on" state second
imgsrc = new Array(
	'images/navHomeOff.gif','images/navHomeOn.gif',
	'images/navPlansOff.gif','images/navPlansOn.gif',
	'images/navSignupOff.gif','images/navSignupOn.gif',
	'images/navLoginOff.gif','images/navLoginOn.gif',
	'images/navContactusOff.gif','images/navContactusOn.gif',
	'images/navHelpOff.gif','images/navHelpOn.gif',
	'images/navAboutOff.gif','images/navAboutOn.gif',
	'images/navNewsOff.gif','images/navNewsOn.gif'
);

//  This loop converts the "imgsrc" array into IMG objects.
img = new Array();
for (i = 0; i < imgsrc.length; i++) {
	img[i] = new Image();
	img[i].src = prefix + imgsrc[i];
}

//  This function is called when the page loads.  It writes the dHTML menus using the "menus" array, defined below.
//  The "prefix" variable is defined in the HEAD of each page.  See "menus" array (below) for more info.
function drawMenus() {
	for (i=0;i<menus.length;i++) 
	{
		if (NS4) 
		{
			// do nothing
		} 
		else 
		{
			if (!document.getElementById 
			&& !document.layers)
			{
				return; //This is Netscape 3, so abort.
			}
		}
		if (menus[i].length>0) 
		{
			if (NS4) 
			{
				// find widest menu item
				for (j=0;j<menus[i].length;j+=2) 
				{
					var d = document.widthcheck.document;
					d.open();
					d.write('<SPAN CLASS="menuItemNS4">'+menus[i][j]+'<\/SPAN>');
					d.close();
					tempwidth = document.widthcheck.clip.width + 16;
					if (tempwidth > menuWidth[i])
					{
						menuWidth[i] = tempwidth;
					}
				}
		
				// write menu rectangle and rollover highlights	
				htmlStr = '';
				htmlStr += '<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">\r';
				htmlStr += '<TR><TD BGCOLOR="#333366" COLSPAN="3"><IMG class="n4img" SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="1"><\/TD><\/TR>\r';
				for (j=0;j<menus[i].length;j+=2) 
				{
					htmlStr += '<TR>\r';
					htmlStr += '<TD BGCOLOR="#333366"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="1"><\/TD>\r';
					htmlStr += '<TD BGCOLOR="#FFFFFF"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="'+menuWidth[i]+'" HEIGHT="20" BORDER="0" NAME="menu'+i+'itemblock'+j+'"><\/TD>\r';
					htmlStr += '<TD BGCOLOR="#333366"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="1"><\/TD>\r';
					htmlStr += '<TD><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="4" HEIGHT="20" NAME="menu'+i+'right'+j+'"><\/TD>\r';
					htmlStr += '<\/TR>\r';
				}
				htmlStr += '<TR><TD BGCOLOR="#333366" COLSPAN="3"><IMG class="n4img" SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="1"><\/TD><\/TR>\r';
				htmlStr += '<\/TABLE>\r';
				menuObj = eval('document.menu'+i+'blocks.document');
				menuObj.open();
				menuObj.write(htmlStr);
				menuObj.close();
				menuObj = eval('document.menu'+i+'blocks');
				menuObj.left = menuPlace[i] + 2;
				menuObj.top += 4;

				// write menu items		
				htmlStr = '';
				htmlStr += '<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">\r';
				for (j=0;j<menus[i].length;j+=2) 
				{
					htmlStr += '<TR>\r';
					htmlStr += '<TD><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="20"><\/TD>\r';
					htmlStr += '<TD><A HREF="'+prefix+menus[i][j+1]+'" onMouseOver="highlight('+j+',true)" onMouseOut="highlight('+j+',false)" CLASS="menuItemNS4" target="_top">'+menus[i][j]+'<\/A><\/TD>\r';
					htmlStr += '<\/TR>\r';
				}
				htmlStr += '<\/TABLE>\r';
				menuObj = eval('document.menu'+i+'.document');
				menuObj.open();
				menuObj.write(htmlStr);
				menuObj.close();
				menuObj = eval('document.menu'+i);
				menuObj.left = 8 + menuPlace[i];
				menuObj.top += 4;

			} 
			else 
			{
				htmlStr = '';
				htmlStr += '<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">\r';
				htmlStr += '<TR><TD BGCOLOR="#333366" COLSPAN="5"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="1"><\/TD><\/TR>\r';

				for (j=0;j<menus[i].length;j+=2) 
				{
					htmlStr += '<TR>\r';
					htmlStr += '<TD BGCOLOR="#333366"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="1"><\/TD>\r';
					htmlStr += '<TD BGCOLOR="#FFFFFF" ID="menu'+i+'padleft'+j+'"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="5" HEIGHT="1"><\/TD>\r';
					htmlStr += '<TD BGCOLOR="#FFFFFF" NOWRAP ID="menu'+i+'item'+j+'" onMouseOver="highlight('+j+',true)" onMouseOut="highlight('+j+',false)" onClick="document.location=\''+prefix+menus[i][j+1]+'\'" STYLE="cursor:hand"><A HREF="'+prefix+menus[i][j+1]+'" CLASS="menuItem" target="_top">'+menus[i][j]+'<\/A><\/TD>\r';
					htmlStr += '<TD BGCOLOR="#FFFFFF" ID="menu'+i+'padright'+j+'"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="5" HEIGHT="1"><\/TD>\r';
					htmlStr += '<TD BGCOLOR="#333366"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="1"><\/TD>\r';
					htmlStr += '<TD ID="menu'+i+'right'+j+'"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="4" HEIGHT="20"><\/TD>\r';
					htmlStr += '<\/TR>\r';
				}
				htmlStr += '<TR><TD BGCOLOR="#333366" COLSPAN="5"><IMG SRC="'+prefix+'images/dot-tran.gif" WIDTH="1" HEIGHT="1"><\/TD><\/TR>\r';
				htmlStr += '<\/TABLE>\r';
				menuObj = (IE4) ? eval('document.all.menu'+i) : document.getElementById('menu'+i);
				menuObj.innerHTML = htmlStr;
				menuObj.style.left = menuPlace[i] + 3;
			}
		}
	}
	menusReady = true;
}

//  This function is called when the mouse rolls over menu IMGs.  It hides/unhides the appropriate menu.
function showMenu(men,isVisible) {
	if (menusReady === false) return;
	
	//  hide last menu if new menu is activated;
	if (men !== currMenu) 
	{
		hideMenu();
	}
	
	var isVisible = isVisible === true;
	
	currMenu = men;
	if (NS4) 
	{
		menuDiv = eval('document.menu'+men);
		menublockDiv = eval('document.menu'+men+'blocks');
		menuDiv.visibility = isVisible ? 'visible' : 'hidden';
		menublockDiv.visibility = menuDiv.visibility;
	} 
	else 
	{
		menuDiv = (IE4) ? eval('document.all.menu'+men) : document.getElementById('menu'+men);
		menuDiv.style.visibility = isVisible ? 'visible' : 'hidden';
	}
	if (currentSection !== -1) 
	{
		//  turn on/off menu highlight depending on mouse location
		var navImg = document.images['navImg'+currentSection];
		if (isVisible 
		&& men !== currentSection) 
		{
			navImg.src = img[currentSection*2].src;
		}
		else 
		{
			navImg.src = img[1+currentSection*2].src;
		}
	}
	clearTimeout(menuTimeout);
}


//  This function makes the current menu item highlight.
//  It is called when the mouse rolls over a HREF, written in "drawMenus()"
function highlight(itm, isOn) 
{
	var isOn = isOn === true;
	if (NS4) {
		itemBlock = eval('document.menu'+currMenu+'blocks.document.images["menu'+currMenu+'itemblock'+itm+'"]');
		if (isOn) 
		{
			clearTimeout(menuTimeout);
			itemBlock.src = prefix+'images/dot-gray.gif';
		} 
		else 
		{
			del = (menus[currMenu].length > 0) ? 1000 : 1;
			menuTimeout = setTimeout('hideMenu()',del);
			itemBlock.src = prefix+'images/dot-tran.gif';
		}
	} 
	else 
	{
		leftPad = (IE4) ? eval('document.all.menu'+currMenu+'padleft'+itm) : document.getElementById('menu'+currMenu+'padleft'+itm);
		rightPad = (IE4) ? eval('document.all.menu'+currMenu+'padright'+itm) : document.getElementById('menu'+currMenu+'padright'+itm);
		itemTD = (IE4) ? eval('document.all.menu'+currMenu+'item'+itm) : document.getElementById('menu'+currMenu+'item'+itm);
		
		if (isOn) 
		{
			clearTimeout(menuTimeout);
			leftPad.bgColor = '#DDDDDD';
			rightPad.bgColor = '#DDDDDD';
			itemTD.bgColor = '#DDDDDD';
		} 
		else 
		{
			del = (menus[currMenu].length > 0) ? 1000 : 1;
			menuTimeout = setTimeout('hideMenu()',del);
			leftPad.bgColor = '#ffffff';
			rightPad.bgColor = '#ffffff';
			itemTD.bgColor = '#ffffff';
		}
	}
}

//  This function hides the current menu.
function hideMenu() {
	if (menusReady === false) return;
	
	if (currMenu>-1) 
	{
		showMenu(currMenu,false);
		divprefix = document;
		if (currMenu !== currentSection)
		{
			divprefix.images['navImg'+currMenu].src = img[currMenu*2].src;
		}
	}
	clearTimeout(menuTimeout);
}

//  This function removes the marquee around Windows IE HREFs, which appear when a link is clicked but the page does not refresh.
function blurry(obj)
{
	if (IE4 || IE5) obj.blur();
}

menusReady = false;  //  flag to prevent script activation before the page has initialized
currentSection = -1;  //  tracks what section the user is in
currMenu = -1;  //  tracks what menu is currently active
menuTimeout = -1;  //  initializes the menuTimeout object

/*
The following two-dimensional array holds all the menu information, from left (menus[0]) to right (menus[5]).

All menu-based HREF definitions are done here.

The syntax is [menu item as displayed on screen],[relative location from root directory]
The "prefix" variable, which is defined in the HEAD of each page, allows pages contained in subdirectories to access these relative locations correctly.

Even though a menu-bar items has no menu items, it must have an empty array associated to it.
*/
menus = new Array();
menus[0] = new Array();
menus[1] = new Array();
menus[2] = new Array();
menus[3] = new Array();
menus[4] = new Array();
menus[5] = new Array(
	'FAQs','faqs.html',
	'New Features','faqs/faq_whats_new.html',
	'What is PicoSearch?','whatis.html',
	'PicoSearch Glossary','glossary.html',
	'Sample Customers','examplesearch.html',
	'License','license.html'
);
menus[6] = new Array(
	'What is PicoSearch?','whatis.html',
	'What People Say about Us','whatpeoplesay.html',
	'Sample Customers','examplesearch.html',
	'New Features','faqs/faq_whats_new.html',
	// 'Press Releases','pressreleases.html',
	'Tell a Friend','tell.html',
	'Link to Us','linktous.html',
	'Jobs at PicoSearch','jobs.html',
	'License','license.html'
);
/*
menus[7] = new Array(
	'Press Releases','news.html',
	'In The Press','press.html'
);
*/

menuWidth = new Array();  //  initialize menuWidth array to minimum 2 pixels
for (i=0;i<menus.length;i++) 
{
	menuWidth[i]=2;
}

// see nav.css if you need to add another object
// array contains the x-position of each menu item image
menuPlace = new Array(189,231,274,330,373,439,477,584); 

function showNav(pg) 
{
	obj = eval('document.images.navImg'+pg)
	tmp = obj.src.substring(0,obj.src.indexOf('Off.gif')); // Extract the body of the src string
	tmp += 'On.gif'; // Append the '-on' component;
	obj.src = tmp; // Reset the src to highlight the nav image
	currentSection = pg; // Set the variable that records what section we're currently viewing
}

