// This file, menus.js, allows dynamic menus to be triggered by mouse rollovers

// Set Global Variables for Tracking submenus
var currMenu = "none"; // says mouse is roaming and no menu is highlighted
var nextMenu = "none"; // says there is no menu ready to display when current meny is done
var x, y; // Current Mouse Position
var mNum = 0; // Number of menus
var mNames = new Array(); // Names of menus

// Define images for toggling
imageSwaps = new Array();
//imageSwaps['myhealth'] = new imageSwap('myhealth');
imageSwaps['members'] = new imageSwap('members');
imageSwaps['employers'] = new imageSwap('employers');
///KJP Test Provider menu toggle off
imageSwaps['providers'] = new imageSwap('providers');
imageSwaps['consultants'] = new imageSwap('consultant');
//imageSwaps['news'] = new imageSwap('news');
imageSwaps['products'] = new imageSwap('products');
imageSwaps['qual_improv'] = new imageSwap('qual_improv');
imageSwaps['about_us'] = new imageSwap('about_us');
imageSwaps['sign_out'] = new imageSwap('sign_out');
function imageSwap(imageName) {
	this.images = new Array();
	this.images[0] = "/behavioralhealthweb/all_images/menu_" + imageName + ".jpg";
	//this.images[1] = "/behavioralhealthweb/all_images/menu_" + imageName + "_on.jpg";
	this.images[2] = "/behavioralhealthweb/all_images/menu_" + imageName + "_on.jpg";
	this.norm = 0;
} // End imageSwap method for imageSwaps

// Initialize DHTML Object(s) and Event Capture
function init(mOn) {
	if (!domData.isOther) {
		domData.flag = true;

		// Cancel menu intialization
		if (mOn == 'na') { return;	}
		
		// Identify which menu image has a default "on" state
		if (mOn != 'none') {
			var obj = imageSwaps[mOn];
			obj.norm = 1;
			imageOut(mOn);
		}
		
		createObjects(); // Function that creates DHTML objects

		// Initialize the menu bounds for the menus
		for (var i = 0; i < mNum; i++) {
			initMenus(mNames[i]); 
		}

		if (domData.isNN6Up) { 
			document.body.addEventListener("mousemove", whereAmI, true);
		} else { 
			document.onmousemove = whereAmI; 
		}

	}
} // End init()


// Set Menu bounding area
function initMenus(oName) {
	var obj = theObjs[oName];
	obj.x1 = obj.objGetLeft() - 10; // Upper X position of Menu
	obj.y1 = obj.objGetTop() - 33; // Upper Y position of Menu, plus space for Parent Menu item
	obj.x2 = obj.objGetLeft() + obj.objGetWidth() + 10; // Bottom X position of Menu 
	obj.y2 = obj.objGetTop() + obj.objGetHeight() + 10; // Bottom Y position of Menu 
} // End SetBounds(oName)


// Track x and y positiong of mouse
function whereAmI(e) {

	if (currMenu == 'none') { return; }
	var obj = theObjs[currMenu];

	if (domData.isNN6Up) { 
		x = e.clientX + domData.scrollX();
		y = e.clientY + domData.scrollY();
	} else if (domData.isIE4Up) { 
		x = event.clientX + domData.scrollX(); 
		y = event.clientY + domData.scrollY(); 
	}

	if ((x < obj.x1) || (x > obj.x2) || (y < obj.y1) || (y > obj.y2)) { 
		currMenu = 'none';
		menuOff('none'); // Turn off all menus
		
	}
		
} // End whereami(e) function


// Turn on menu (and turn off others)
// Function also triggers mouseover, even if no menus exist
function menuOn(menu) {
	
	
	
	if (!domData.flag) { return; }
	if (currMenu == menu) { return; }
	
	imageOver(menu.slice(8)); // Show the menu image "Over" state
	
	currMenu = menu;
	menuOff(currMenu); // Turn off Non-current menus
	
	var obj = theObjs[currMenu];
	//KJP 6/17/2008 Comment out to show the Provider menu
	//if (menu == 'dynamic-providers') { return; } //[rlbanks] SCR 14259 -- Commented out to show the Provider Menu
	obj.objShow();

    
} // End MenuOn(menu)
	

// Hide all menus except current
function menuOff(except) {
	for (var i = 0; i < mNum; i++) { 
		if (mNames[i] != except) { 
			var obj = theObjs[mNames[i]];
			obj.objHide(); 
			imageOut(mNames[i].slice(8));
		}
	}
} // END menuOff(except) 


// Display "mouseover" version of image
function imageOver(lookup) {
	var obj = imageSwaps[lookup];
	document.images[lookup].src = obj.images[2];
} // End imageOver(lookup)



// Display "default" version of image
function imageOut(lookup) {
	var obj = imageSwaps[lookup];
	document.images[lookup].src = obj.images[obj.norm];
} // End imageOver(lookup)

//KJP 11/13/2007 12115
//KJP 12/27/2007 12115 changed the urlS
function EmployerConnectURL(strURL)
{//determine the server to point to based on where the user is entering the
 //site from
	var strHostname;
	var strProtocol;
	var strNewURL;

	if (document.location.hostname.indexOf("optimahealth.com") == -1)
		//did not find the string optimahealth.com
		{
			strHostname = 'reports.sentara.com/Providers/';
		}
		else {
			strHostname = 'reports.sentara.com/Providers/';
		}
	strProtocol = document.location.protocol;
	//parse out the protocol to only return http: or https:
	strProtocol = strProtocol.substr(0,strProtocol.indexOf(":") + 1);

	//build the new URL
	//KJP 12115 12/27/2007
	//strNewURL = strProtocol + "//" + strHostname + strURL;
	strNewURL = strProtocol + "//" + strHostname;
	window.open(strNewURL, '', 'toolbar=yes, scrollbars=yes, location=yes, resizable=yes, height=485, width=700,left=20,top=20');
	return;
}
//RobertTest
function toggleMenu(menuId, buttonId, onImg, offImg)
{
	var mnu;
	var btn;
	
	mnu = document.getElementById(menuId);
	btn = document.getElementById(buttonId);
	
	
	if (mnu != null && btn != null)
	{
		var state = parseInt(btn.getAttribute('menuState'));
		switch (state)
		{
			case 2:
				mnu.style.display = 'none';
				btn.src = offImg;
				btn.setAttribute('menuState',0);
				break;
			default:
				mnu.style.display = '';
				btn.src = onImg;
				btn.setAttribute('menuState',2);
		}
	}
}

// Change the style of the left menu item as the mouse leaves
function sideMenuOut(menuCell)
{
	if (menuCell)
	{
		menuCell.style.backgroundColor='';
		if (menuCell.nextSibling)
		{
			menuCell.nextSibling.style.backgroundColor='';
		}
	}
}
// Change the style of the left menu item as the mouse enters
function sideMenuOver(menuCell)
{ 
	if (menuCell)
	{
		menuCell.style.backgroundColor='#ffffff';
		if (menuCell.nextSibling)
		{
			menuCell.nextSibling.style.backgroundColor='#ffffff';
		}
	}
}
function toggleButton(buttonId, onImg, offImg, action)
{
	var btn = document.getElementById(buttonId);
	if (btn != null)
	{
		var state = parseInt(btn.getAttribute('menuState'));
		switch (state)
		{
			case 0:		// Not expanded, not highlighted
				if (action == "over")
				{
					btn.src = onImg;
					btn.setAttribute('menuState',1);
				}
				break;
			case 1:		// Not expanded, hightlighted
				btn.src = offImg;
				btn.setAttribute('menuState',0);
				break;
			case 2:
				// do nothing
				break;
		}
	}
}
