// Dynamic Diagram's Baseline DHTML Scripts
// Created by Henry Woodbury, July, 2005; 
// Updated for Cold Spring Harbor Web Site Design, March 2006
// Creates drop-down menu functionality from specific list of IDs

domData.flag = false; // stops menus from being triggered until page is loaded.
var mCurr = false; // says mouse is roaming, not on a global menu at all

mNames = new Array("protocols-dropdown-container","help-dropdown-container","submit-protocols-dropdown-container"); // names of menu(s)

// Track Mouse Position
var x, y;

// Add initFloater() to the window.onload using addLoadEvent in domdata.js
addLoadEvent(initMenus);


// Initialize Menus and start event capture
function initMenus() {
	if (domData.isOther) { return; }
	for (var i = 0; i < mNames.length; i++) {
		makeObject(mNames[i]);
		initMenuBounds(mNames[i]);
	}
	if (domData.isNN6Up) { document.body.addEventListener("mousemove", whereAmI, true); 
	} else { document.onmousemove = whereAmI; }
	domData.flag = true;
} // End initMenus()


// Initialize menu bounds
function initMenuBounds(mName) {
	var obj = theObjs[mName];
	obj.x1 = obj.objGetLeft() - 5; // 5 pixel padding
	obj.y1 = obj.objGetTop() - 40; // Extra padding to cover menu image
	obj.x2 = obj.objGetLeft() + obj.objGetWidth() + 5; // 5 pixel padding
	obj.y2 = obj.objGetTop() + obj.objGetHeight() + 25; // 25 pixel padding
} // End initMenus()


// Track mouse moves
function whereAmI(e) {

	if (domData.isNN6Up) { 
		x = e.clientX + domData.scrollX();
		y = e.clientY + domData.scrollY();;
	} else { 
		x = event.clientX + domData.scrollX(); 
		y = event.clientY + domData.scrollY(); 
	}

	if (!mCurr) { return; }

	var obj = theObjs[mCurr];

	if ((x < obj.x1) || (x > obj.x2) || (y < obj.y1) || (y > obj.y2)) { 
		mCurr = false;
		menuOff('none'); // Turn off all menus
	}
			
} // End whereAmI(e)


// Turn on menu (and turn off others)
function menuOn(menu) {

	if (!domData.flag) { return; }
	if (mCurr == menu) { return; }
	
	mCurr = menu;
	menuOff(mCurr); // Turn off Non-current menus
	var obj = theObjs[mCurr];
	obj.objShow();

} // End MenuOn(menu)
	

// Hide All Menus
function menuOff(except) {
	for (var i = 0; i < mNames.length; i++) { 
		if (mNames[i] != except) { 
			var obj = theObjs[mNames[i]];
			obj.objHide(); 
		}
	}
} // END menuOff(except) 
