var revert = new Array();
var imgNames = new Array('who-we-are-image', 'what-we-do-image', 'who-weve-helped-image', 'rbl-institute-image', 'marketplace-image', 'contact-us-image');
var currentExpanded = "empty-menu"; //Setting this to empty-menu makes an empty menu display if there isn't a menu specified in the {embed:header} on the page.
var timeoutDelay = 250; //Number of milliseconds the menu waits before displaying the submenu
var timeoutID = null;

// Preloads the main menu images for faster rollover
if (document.images) {
  var flipped = new Array();
  for(i=0; i < imgNames.length; i++) {
	flipped[i] = new Image();
	flipped[i].src = "http://rbl.net/images/uploads/misc/"+imgNames[i]+"-on.gif";
  }
}

//Switches the image of the main menu item when it is rolled over.  Is called onMouseOver a div.
function over(num) {
  if(document.images) {
	revert[num] = document.images[imgNames[num]].src;
	document.images[imgNames[num]].src = flipped[num].src;
  }
}

//Switches the image back to the original once the person has left the main menu item.  Is called onMouseOut a div
function out(num) {
  if(document.images) document.images[imgNames[num]].src = revert[num];
}

/*Allows for a delay on changing the secondary menu in the case that a user
selects a main menu item and is going to the secondary item they want and accidently hit 
another main menu item.*/
function doMenuEnterAction (subMenu, menuItem){
	//This line is to make it so that you can use the subMenu variable in the setTimeout function.
	var functionToExecuteAfterDelay = function() {toggleSub(subMenu);};
	over(menuItem);
	timeoutID = setTimeout(functionToExecuteAfterDelay, timeoutDelay); 
}

function doMenuExitAction(menuItem){
	out(menuItem); 
	clearTimeout(timeoutID);
}

//Expands and contracts menus.  Toggles item between display:none and display:block.  Looks up item by id.
function toggleSub(submenu) {
	if(document.getElementById(submenu).style.display != 'inline') {
		document.getElementById(submenu).style.display = 'inline';	
	} 
	
	if(currentExpanded != null && submenu != currentExpanded){
		document.getElementById(currentExpanded).style.display = 'none';
	}
	currentExpanded = submenu;
}