// Right hand menu function
// requires basic_functions.js

// works only with W3C compliant browsers
// p is x-position to right of calling obj where to place menu (if 0 or unspecified will go to mouse pos)
function showContextMenu(e,menuName,p){
	hideContextMenus();
	var menu = getObj(menuName);
	menu.style.left = (p>0) ? (findPosX(e) + p)+"px" : xMousePos+"px";
	menu.style.top = (yMousePos-8)+"px";
	switchDiv(menuName,1);
	setContextMenuTimer(5000);
	return false;
}

// hides all context menus
function hideContextMenus(){
	for(menu in contextMenuArr){
		switchDiv(menu, 0);
	}
}
// function to hide indivdual menu
function hideContextMenu(menuName){
	switchDiv(menuName, 0);
}

function doContextMenuHide(){
	if(timerRunning){
		hideContextMenus();
	}
}
// function to set delayed close on menus. If time=0 it means keep menu open
menuTimeout = false;
function setContextMenuTimer(time){
	if(!time){
		timerRunning=false;
		if(menuTimeout){
			window.clearTimeout(menuTimeout);
		}
	}
	else{
		timerRunning=true;
		menuTimeout = window.setTimeout("doContextMenuHide()", time);
	}
	
}
// function to return cancel portion of menu for dynamically generated menus
function getContextMenuCancel(menuName){
	return "<ul><li><a href=\"javascript:hideContextMenu('"+menuName+"');\">Cancel</a></li></ul>";
}
// capture mouse position so we know where to put menus
function captureMousePosition(e) {
	if(document.all){ // grab the x-y pos.s if browser is IE
		xMousePos = event.clientX + document.body.scrollLeft
		yMousePos = event.clientY + document.body.scrollTop
	}else{	// grab the x-y pos.s if browser is NS
		xMousePos = e.pageX
		yMousePos = e.pageY
	} 
}

if(!document.all){ // not IE
	document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = captureMousePosition;

// object to store references to all menus on page - all menus must be added to this object: contextMenuArr[menuID] = menuID;
contextMenuArr = new Object();
