/* Pre-load images into cashe
 * so when you mouse over menus
 * they swap instantly
 */

// first an associative array of menu ON images
var menuOn = new Array();
menuOn["home"] = new Image();
menuOn["home"].src = "images/home_on.gif";

menuOn["about"] = new Image();
menuOn["about"].src = "images/about_on.gif";

menuOn["approach"] = new Image();
menuOn["approach"].src = "images/approach_on.gif";

menuOn["verticals"] = new Image();
menuOn["verticals"].src = "images/verticals_on.gif";

menuOn["solutions"] = new Image();
menuOn["solutions"].src = "images/solutions_on.gif";

menuOn["client"] = new Image();
menuOn["client"].src = "images/client_on.gif";

menuOn["contact"] = new Image();
menuOn["contact"].src = "images/contact_on.gif";

// second an associative array of OFF images
var menuOff = new Array();
menuOff["home"] = new Image();
menuOff["home"].src = "images/home_off.gif";

menuOff["about"] = new Image();
menuOff["about"].src = "images/about_off.gif";

menuOff["approach"] = new Image();
menuOff["approach"].src = "images/approach_off.gif";

menuOff["verticals"] = new Image();
menuOff["verticals"].src = "images/verticals_off.gif";

menuOff["solutions"] = new Image();
menuOff["solutions"].src = "images/solutions_off.gif";

menuOff["client"] = new Image();
menuOff["client"].src = "images/client_off.gif";

menuOff["contact"] = new Image();
menuOff["contact"].src = "images/contact_off.gif";


// new logo src's, because
// now it's a button to index.htm
var logoOn = new Image();
logoOn.src = "images/SUMMUS_on.gif";

var logoOff = new Image();
logoOff.src = "images/summusLogo123px.gif";


// Third a function to swap images
function swapMenu(obj, theState) {
	// imgName is the name attribute of the image object
	var imgName = obj.name;
	
	// This is a one-line shortcut, it means
	// if theState is "on" then the object's image source is 
	// from the menuOn array, else it's from the menuOff array
	obj.src = (theState == "on") ? menuOn[imgName].src : menuOff[imgName].src;
}

/*
 * This starts the showing and hiding of the
 * codes for the submenus
 */
 
// this finds the positions the rolled over menu
var elemPosX = 0;
var elemPosY = 0;

function getObjectXY(theElement) {
	elemPosX = theElement.offsetLeft;
	elemPosY = theElement.offsetTop;
	theElement = theElement.offsetParent;
	
	while (theElement != null) {
		elemPosX += theElement.offsetLeft;
		elemPosY += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}
}

function showSubMenu(xMenu, xSub) {
	// get a reference to the current menu and it's submeu
	var thisMenu = document.getElementById(xMenu);
	var theDiv = document.getElementById(xSub).style;
	
	// hide other visble submenus (for Netscape problem of sticky menus)
	for (var i = 0; i < subMenuArray.length; i++) {
		if (subMenuArray[i] != xSub)  {
			document.getElementById(subMenuArray[i]).style.display = "none";	
			
		}
	}
	// Also for Nescape, swap all other menus to off image
	for (var j = 0; j < MenuArray.length; j++) {
		if (MenuArray[j] != xMenu)  {
			var Menu = document.getElementById(MenuArray[j]);	
			swapMenu(Menu, "off");
			
		}
	}
	
	// show the menu's on image
	swapMenu(thisMenu, "on");
	
	// get its X and Y position
	getObjectXY(thisMenu);
	
	// position the submenu DIV
	theDiv.left = elemPosX + "px";
	theDiv.top = elemPosY + 20 + "px"; // 20px is the current menu depth
	
	// Show it
	theDiv.display = "block";
}

function hideSubMenu(xMenu, xSub) {
	// hide the submenu
	document.getElementById(xSub).style.display = "none";
	
	// return the menu's image to off image
	var thisMenu = document.getElementById(xMenu);
	swapMenu(thisMenu, "off");
}

var subMenuArray = new Array("subAbout", "subApproach", "subVerticals", "subClient");
var MenuArray = new Array("about", "approach", "verticals", "client");


