var bGlobalJSLoaded = false;	// Flag for keeping track of loading status of this file

var HIDE_DELAY = 700;		// Delay in miliseconds before hiding submenus when the mouse leaves

var iHideTimer = null;		// Handle for the timer that prevents the submenu from hiding on short mouse exits

var sLastShowing = null;	// Keeps track of last showing submenu

var sCurrent = null;		// Keeps track of currently showing submenu



var sStyleObj = (document.layers) ? "" : "style.";



var sSubMenu = new Array();

sSubMenu["nf_factsfigures"] = "m1s0";

sSubMenu["nf_background"] = "m1s1";

sSubMenu["nf_peopleatnesta"] = "m1s2";

sSubMenu["nf_jobopportunities"] = "m1s3";

sSubMenu["nf_publications"] = "m1s4";



sSubMenu["fp_inventioninnovation"] = "m2s0";

sSubMenu["fp_fellowship"] = "m2s1";

sSubMenu["fp_education"] = "m2s2";

sSubMenu["fp_projects"] = "m2s3";



sSubMenu["awardeefinder"] = "m3s0";

sSubMenu["aw_newsevents"] = "m3s1";

sSubMenu["aw_features"] = "m3s2";



sSubMenu["r_inventorshandbook"] = "m4s0";

sSubMenu["r_usefullinks"] = "m4s1";

sSubMenu["r_howto"] = "m4s2";



sSubMenu["mr_newsarchive"] = "m5s0";

sSubMenu["mr_factsfigures"] = "m5s1";

sSubMenu["mr_background"] = "m5s2";

sSubMenu["mr_peopleatnesta"] = "m5s3";

sSubMenu["mr_nestainthenews"] = "m5s4";

sSubMenu["mr_imagelibrary"] = "m5s5";

sSubMenu["mr_prcontacts"] = "m5s6";



sSubMenu["ac_whoswho"] = "m6s0";

sSubMenu["ac_newsevents"] = "m6s1";

sSubMenu["ac_messageboards"] = "m6s2";

sSubMenu["ac_awardsupport"] = "m6s3";



var sMainMenu = new Array();

sMainMenu["sid3"] = "imgmain1";

sMainMenu["sid4"] = "imgmain2";

sMainMenu["sid5"] = "imgmain3";

sMainMenu["sid6"] = "imgmain4";

sMainMenu["sid7"] = "imgmain5";

sMainMenu["sid8"] = "imgmain6";



var objCurrentSubMenu;

var sSubMenuImageRef;

var sMainMenuImageRef;

var bOnSectionHome = false;



function highlightCurrentPge(iCurrentMainSection,iCurrentSoftID) {

	// Find main menu item

	sMainMenuImageRef = sMainMenu["sid" + iCurrentMainSection];

	if (sMainMenuImageRef && sMainMenuImageRef!="undefined") {

		var sMainMenuImageIndex = sMainMenuImageRef.charAt(7);

		objCurrentSubMenu = mElement("divsub"+sMainMenuImageIndex);

		if (sSubMenu[iCurrentSoftID]) { // We are not on a section home page

			sSubMenuImageRef = sSubMenu[iCurrentSoftID];

			mElement("img"+sSubMenuImageRef, "divsub"+sMainMenuImageIndex, "iMageZ").src = "files/nav/sub/se/"+sSubMenuImageRef+".gif" ;

			// highlight the main menu image

			mElement(sMainMenuImageRef).src = "files/nav/main/se/0" + sMainMenuImageIndex + ".gif";

			// fold out the submenu

			show(objCurrentSubMenu);

		} else {

			bOnSectionHome = true;

			// highlight the main menu image

			mElement(sMainMenuImageRef).src = "files/nav/main/se/0" + sMainMenuImageIndex + ".gif";

			// fold out the submenu

			show(objCurrentSubMenu);

		}

	}

}



function pageInit(iCurrentMainSection,iCurrentSoftID) {

	// Mak sure the correct menu option is highlighted

	highlightCurrentPge(iCurrentMainSection,iCurrentSoftID)

}



function show(oRef) {

	eval("oRef." + sStyleObj + "visibility='visible'");

}



function hide(oRef) {

	eval("oRef." + sStyleObj + "visibility='hidden'");

}



function mElement(elementName) {

	if (document.layers) {

	//we want 1 object (not nested)

		//simple layer reference

		if (mElement.arguments.length == 1) {

			var cEl = eval("document.layers['" + elementName + "']");

		//refer document in layer: document.layers[layername].document

		} else if (mElement.arguments[1] == 'DoC') {// use 'strange' spelling to minimise conflicts with existing objects

			var cEl = eval("document.layers['" + elementName + "'].document");

		//refer an image: document.images[imageName]

		} else if (mElement.arguments[1] == 'iMageZ') {

			var cEl = eval("document.images['" + elementName + "']");

		//nested objects

		} else if (mElement.arguments.length>1) {

			var cEl = "document.layers['" + mElement.arguments[1] + "']";//start the string

			for (var i=2;i<mElement.arguments.length;i++) {//leave the first argument, because that's the one you're after, the second because you used that one to start the string

				if ( (mElement.arguments[i] != 'DoC') && (mElement.arguments[i] != 'iMageZ') && (mElement.arguments[i] != 'ForMz') ) {

					//alert(mElement.arguments[i]);

					cEl = cEl + ".document.layers['" + mElement.arguments[i] + "']";//get the next layer

				}

			}

			if (mElement.arguments[mElement.arguments.length-1] == 'iMageZ')  {

				cEl = cEl + ".document.images['" + elementName + "']";//in case you need the images in the layer rather than the layer or doc

			} else if (mElement.arguments[mElement.arguments.length-1] == 'ForMz')  {

				cEl = cEl + ".document.forms['" + elementName + "']";//in case you need the form in the layer rather than the layer or doc

			} else {

				cEl = cEl + ".document.layers['" + mElement.arguments[0] + "']";//add first element (the one you're after)

				if (mElement.arguments[mElement.arguments.length-1] == 'DoC') {

				cEl = cEl + ".document";//in case you need the document in the layer rather than the layer itself

				}

			} 

			cEl = eval(cEl);//wrap up and make string into an object

		} else {

			var cEl = eval("document.layers['" + mElement.arguments[1] + "'].document." + elementName);

		}

	//old IE browsers:

	} else if (document.all) {

		var cEl = eval('document.all.' + elementName);

	//W3C standard:

	} else {

		var cEl = document.getElementById(elementName);

	}

	return cEl;

}



function showMenu(iMenu) {



	if ("imgmain"+iMenu != sMainMenuImageRef) {

		// Highlight the main menu item

		mElement("imgmain"+iMenu,"divnav00","iMageZ").src = "files/nav/main/hi/0" + iMenu + ".gif";

	}



	sCurrent = iMenu;



	if (sLastShowing == null) {

		if (mElement("divsub"+iMenu)) {

			if ((mElement("divsub" + iMenu)!=objCurrentSubMenu) && objCurrentSubMenu) {

				hide(objCurrentSubMenu)

			}

			show(mElement("divsub"+iMenu))

		}

	} else {

		showMenuReal(iMenu)

	}



	// Cancel any pending hide timer

	if (iHideTimer) clearTimeout(iHideTimer)



	// If the cursor moved from another main menu item, hide it

	if ((iMenu!=sLastShowing) && (sLastShowing!=null)) hideMenuReal(sLastShowing,false)



	// Remember which item we're hovering above

	sLastShowing = iMenu;

}





function showMenuReal(iMenu) {

	// Turns on highlighting for a main menu item and shows the corresponding submenu layer

	if (iMenu==sCurrent && sLastShowing!=null) {

		// Display the submenu layer

		if ((mElement("divsub" + iMenu) != objCurrentSubMenu) && objCurrentSubMenu) {

			hide(objCurrentSubMenu)

		}

		if (mElement("divsub" + iMenu)) {

			show(mElement("divsub" + iMenu))

		}

	}

}



function hideMenu(iMenu) {

	// Start a timer to hide the menu item after HIDE_DELAY msecs. This timer can be cancelled should the mouse pointer move back

	iHideTimer = setTimeout("hideMenuReal('"+iMenu+"',true)", HIDE_DELAY)

}



function hideMenuReal(iMenu) {

	// Turns off highlighting for a main menu item and hides the corresponding submenu layer



	if ("imgmain"+iMenu != sMainMenuImageRef) {

		// Switch the main menu item back to normal state

		mElement("imgmain"+iMenu,"divnav00","iMageZ").src = "files/nav/main/no/0" + iMenu + ".gif";

	}



	if (mElement("divsub"+iMenu) != objCurrentSubMenu) {

		// Hide the submenu

		if (mElement("divsub"+iMenu)) {

			hide(mElement("divsub"+iMenu));

			if (objCurrentSubMenu) show(objCurrentSubMenu);

		}

	}



	sLastShowing = null;

}



function hiSub(sImg) {

	if (sImg != sSubMenuImageRef) {

		// Highlights a submenu item

		mElement("img"+sImg,"divsub"+sImg.charAt(1),"iMageZ").src = "files/nav/sub/hi/"+sImg+".gif" ;

	}

}



function noSub(sImg) {

	if (sImg != sSubMenuImageRef) {

		// Reverts a submenu item back to normal status

		mElement("img"+sImg,"divsub"+sImg.charAt(1),"iMageZ").src = "files/nav/sub/no/"+sImg+".gif" ;

	}

}



function changeArticle(sel) {

	var selId = sel.selectedIndex;

	var asid = sel[selId].value;

	if (!isNaN(asid)) {

		location.href = "index.asp?asid=" + asid;

	}

}



function randomInteger(iMax) {

	// returns an integer between 0 and iMax

	return parseInt(Math.random()*iMax)

}



function openHelp(o_url) {

	var o_width = 360;

	var o_height = 410;

	window.open (o_url, 'ApplicationHelp', 'scrollbars=1,status=0,resizable=1,Width='+ o_width +',Height='+ o_height +',left='+ ((screen.availWidth/2)-(o_width/2)) +',top='+ ((screen.availHeight/2)-(o_height/2)) +',screenX='+ ((screen.availWidth/2)-(o_width/2)) +',screenY='+ ((screen.availHeight/2)-(o_height/2)) +'');

}



function openGuidance(o_url) {

	var o_width = 470;

	var o_height = 470;

	window.open (o_url, 'ApplicationGuidance', 'scrollbars=1,status=0,resizable=1,Width='+ o_width +',Height='+ o_height +',left='+ ((screen.availWidth/2)-(o_width/2)) +',top='+ ((screen.availHeight/2)-(o_height/2)) +',screenX='+ ((screen.availWidth/2)-(o_width/2)) +',screenY='+ ((screen.availHeight/2)-(o_height/2)) +'');

}



bGlobalJSLoaded = true;