/*********************************************************************
	Page:		menu.js
	Date:		2005.12.7
	Developer:	Ye Wang
	Function:	DHTML menu: 
				- IE, Safari, Firefox;
				- menu;
				- image rollover & on-state;
**********************************************************************/

var arrMenus = new Array(
	"about",
	"attorney",
	"practice",
	"career",
	"news", 
	"probono",
	"office"
);

var objMenuTimeout = null;
var objMenuTemp = new Object();
var pageOn = "index";



// Create menu & image object;
function initObj(id, state) {
	this.imgID = "nav" + id;
	this.imgObj = document.getElementById(this.imgID);
	this.imgState = eval(id + "_" + state);
	this.menuID = "menu_" + id;
	this.menuObj = document.getElementById(this.menuID);
	this.hasMenu =  hasMenu(id);
	
	this.top = getPosition(this.imgObj).Top;
	this.left = getPosition(this.imgObj).Left;
	if (this.hasMenu) {
		this.on = function(intTop, intLeft) {
			openMenu(this.menuID, (this.top + intTop), (this.left + intLeft));		
		}
		this.off = function() {
			objMenuTimeout = setTimeout("CloseMenuCheck()", 100)
		}
	} else {
		this.on = function(intTop, intLeft) {return false;}
		this.Off = function() {return false}
	}
	
	// based on the state, swap images
	if (state == "off" && id == pageOn) {
		// no image swap;
	} else {
		document.images[this.imgID].src = this.imgState.src;
	}
}

function PrimaryNavOver(id, intTop, intLeft){
	var menuObj = new initObj(id, "on");

	// Clear any interval for menus
	clearTimeout(objMenuTimeout);

	// Close menus
	CloseMenus();

	// menu on
	menuObj.on(intTop, intLeft);
}
function PrimaryNavOut(id) {
	var menuObj = new initObj(id, "off");
	// Check to see if we have a menu for this item
	if (menuObj.hasMenu){
		// We dont want to shut it down right away, but we do 
		// want to set a timer to turn it off. 
		objMenuTimeout = setTimeout("CloseMenuCheck()", 100);
	}		
}
function MenuOver(id) {	
	var menuObj = new initObj(id, "on");
	clearTimeout(objMenuTimeout);
}
function MenuOut(id) {
	var menuObj = new initObj(id, "off");
	objMenuTimeout = setTimeout("CloseMenuCheck()", 500);	
}
function CloseMenuCheck(){

	// Clear any interval for menus
	clearTimeout(objMenuTimeout);
	
	// Close the menu
	CloseMenus();
}
function CloseMenus(){
	var objMenu = null;
	
	// Loop through the menus and close them
	for (var i = 0 ; i < arrMenus.length ; i++){
		objMenu = document.getElementById("menu_" + arrMenus[i]);
		
		// Check to see if we have a menu
		if (objMenu){
			objMenu.style.display = "none";
		}	
	}
}


// Properties
function getPosition(el){
	//el = document.getElementById(id);
	var objTopLeft = el; 
	var objNode = null;
	var objPosition = { Top:el.offsetTop , Left: el.offsetLeft };
		
	// retrieve button image position	
	while (el.offsetParent != null){
		el = el.offsetParent;
		objPosition.Top += el.offsetTop;
		objPosition.Left += el.offsetLeft;		 
	}
	// Return the position
	return(objPosition);
}
	
function openMenu(menuID, intTop, intLeft){
	var objMenu = document.getElementById(menuID);
	
 
	// Check to see if we have a menu
	if (objMenu){
		// Position the menu
		objMenu.style.top = (intTop + "px");
		objMenu.style.left = (intLeft + "px");
		
		// Display the menu
		objMenu.style.display = "block";

	}	
}
function hasMenu(id){
	for (var i = 0 ; i < arrMenus.length ; i++){
		// Check to see if this menu matches
		if (id == arrMenus[i]){
			return(true);
		} 
	}
	// There was no match for this menu
	return(false);
}


