/* Initialize browser variables. */
var NS4 = (document.layers)?1:0; // Test for Netscape 4.0 to 4.72
var NS6 = ((document.getElementById)&&(!document.all)); // Test for NS 6 +
var KeepMenu = 0;
//var NS6Alert = document.cookie.substring(0, 1);
//var Platform = navigator.platform.substring(0,3); //Win or Mac (not actually used)

// Load image rollover filenames for older browsers.
FileNames = new Array();
FileNames[0] = PathToImages+"images/1rm.gif";
FileNames[1] = PathToImages+"images/2rm.gif";
FileNames[2] = PathToImages+"images/3rm.gif";
FileNames[3] = PathToImages+"images/4lm.gif";
FileNames[4] = PathToImages+"images/5lm.gif";
FileNames[5] = PathToImages+"images/1r.gif";
FileNames[6] = PathToImages+"images/2r.gif";
FileNames[7] = PathToImages+"images/3r.gif";
FileNames[8] = PathToImages+"images/4l.gif";
FileNames[9] = PathToImages+"images/5l.gif";

var loaded = "";

function LoadImgs() {
	if (document.images) {
		
		Rollover0 = new Image();
		Rollover0.src = PathToImages+"images/1rm.gif";
		Rollover0a = new Image();
		Rollover0a.src = PathToImages+"images/1r.gif";
		
		Rollover1 = new Image();
		Rollover1.src = PathToImages+"images/2rm.gif";
		Rollover1a = new Image();
		Rollover1a.src = PathToImages+"images/2r.gif";
		
		Rollover2 = new Image();
		Rollover2.src = PathToImages+"images/3rm.gif";
		Rollover2a = new Image();
		Rollover2a.src = PathToImages+"images/3r.gif";
		
		Rollover3 = new Image();
		Rollover3.src = PathToImages+"images/4lm.gif";
		Rollover3a = new Image();
		Rollover3a.src = PathToImages+"images/4l.gif";
		
		Rollover4 = new Image();
		Rollover4.src = PathToImages+"images/5lm.gif";
		Rollover4a = new Image();
		Rollover4a.src = PathToImages+"images/5l.gif";
		
		loaded = 1;
	}
}

LoadImgs();

function SwapIn(Name,No) {
	if (document.images && (loaded == 1)) {
		if (NS4){// Weird NS DOM treats DIV as separate document
			eval('document.Corner.document.images["'+Name+'"].src = Rollover'+No+'.src');
		} else if(NS6){
			document.getElementById(Name).src = eval("Rollover"+No+".src;");
		} else {
			document.images[Name].src = eval("Rollover"+No+".src");
		}
	} else {
		return;
		if (NS4){
			eval('document.Corner.document.images["'+Name+'"].src = FileNames['+No+']');
		} else if (NS6){
			document.getElementById(Name).src = eval("FileNames["+No+"];");
		} else {
			document[Name].src = eval("FileNames["+No+"]");
		}
	}
}

function SwapOut(Name,No) {
	if (document.images && (loaded == 1)) {
		if (NS4){
			eval('document.Corner.document.images["'+Name+'"].src = Rollover'+No+'a.src');
		} else if (NS6){
			document.getElementById(Name).src = eval("Rollover"+No+"a.src;");
		} else {
			document.images[Name].src = eval("Rollover"+No+"a.src");
		}
	} else {
	    No = No + 5;
		if (NS4) {
			eval('document.Corner.document.images["'+Name+'"].src = FileNames['+No+']');
		} else if (NS6){
			document.getElementById(Name).src = eval("FileNames["+No+"];");		
		} else {
			document[Name].src = eval("FileNames["+No+"]");
		}
	}
}


/*
This function Hides all submenus.  Each of the main menu links calls 
this function, so that moving your mouse over a link hides all 
submenus.  If a menu link has its own submenu, then that link also 
calls PopUp() after it has finished called Hide().
*/
/*
As of beta 3, Hide() must cancel pending calls to HideDelay(), so that 
menus will not vanish milliseconds after they've appeared.  Hence the 
clearTimeout call.  The TimerID must be checked first to see if it's set, 
otherwise an error will be generated when the script tries to clear a 
timeout that hasn't been set.
*/
function Hide(){
	if (this.TimerID){
		window.clearTimeout(this.TimerID);
	}
	// Hide pop-up menus.
	PopUp("InterestsMenu", 0);
	PopUp("LanguagesMenu", 0);
	
	// Switch mouseovers back to normal.
	SwapOut('Interests', 0);
	SwapOut('Languages', 1);
}


/*
PopUp() reveals or hides a given submenu.  MenuName specifies which 
menu should be altered, and on is a boolean value.  If the function 
is called with on specified as "1", then the menu is revealed.  If 
on is specified as "0" then the menu is hidden.  
*/
function PopUp (MenuName, on) {
	KeepMenu = 1;
	if (on){
		if (NS4) {
			document.layers[MenuName].visibility = "show";
		} else if (NS6){
			CurrentMenu = document.getElementById(MenuName);
			CurrentMenu.style.visibility = "visible";
		} else {
			document.all[MenuName].style.visibility = "visible";
		}
	} else {
		if (NS4) {
			document.layers[MenuName].visibility = "hide";
		} else if (NS6) {
			CurrentMenu = document.getElementById(MenuName);
			CurrentMenu.style.visibility = "hidden";
		} else {
			document.all[MenuName].style.visibility = "hidden";
		}
	}
}

/*
HideDelay() is called from the OnMouseOut of those menu items that 
have sub-menus to pop up.  When a user moves off the parent link,
HideDelay() checks to see if KeepMenu is true, which it is because it 
was set by PopUp().  So, it sets KeepMenu to false and sets a timeout 
to call itself in half a second.  Meanwhile, if the user moves the mouse 
over the submenu that is being displayed, Extender() is called, which cancels 
the timeout request, leaving the menu in place.  

HideDelay() is also called from the OnMouseOut of the submenu, so that the 
submenu will vanish once someone has moved on to other things.
*/
function HideDelay(KeepMenu) {
	if (KeepMenu == 0){
		Hide();
	} else { 
		KeepMenu = 0;
		this.TimerID = window.setTimeout('HideDelay('+KeepMenu+')', 250);
	}
}

/*
Extender() is called from the table that each submenu is kept in, and 
also from each link in the submenu.  When it is called, it clears the 
existing Timeout call to HideDelay().

Netscape doesn't recognize OnMouseOver or OnMouseOut events for the 
<table> tag, so each table is encapsulated in a <layer> tag with the 
same calls to Extender() and HideDelay().  This ensures that the 
menus work the same in both Netscape and IE.
*/
function Extender(){
	if (this.TimerID){
		window.clearTimeout(this.TimerID);
	}
}
