// displays the popup menu for the group links
function showmenu(menuid, obj, e, anchor, hAdjust, vAdjust) {
	if(!document.getElementById || !document.createElement) return;

	//check for other open menus
	if(document.openMenuId != menuid){
		hideObject(document.openMenuId);	
	}

	//setup the menu object
	var menuobj = document.getElementById(menuid);
	
	// do nothing if the menu doesn't exist
	if(menuobj == null || typeof menuobj == 'undefined') return;
	
	//prevent other events
	if (window.event) event.cancelBubble = true;
	else if (e.stopPropagation) e.stopPropagation();

	//stop previous timers
	cancelhide();
	
	//configure the mouseout event
	obj.onmouseout = hidemenu;

	//set adjustments based on selected 'anchor' corner
	var anchorX = 0;
	var anchorY = 0;
	if(anchor.charAt(0) == 's') anchorY = menuobj.offsetHeight;
	if(anchor.charAt(1) == 'e') anchorX = menuobj.offsetWidth;

	//set the position and show the menu
	var position = findPos(obj);
	menuobj.style.left = position[0] - anchorX + hAdjust + 'px';
	//menuobj.style.top = position[1] - anchorY + vAdjust + 'px';
	menuobj.style.top = '192px';
	menuobj.style.visibility = 'visible';
	menuobj.onmouseover = cancelhide;
	menuobj.onmouseout = hidemenu;
	
	createMask(menuobj);
	
	// set menu flag
	document.openMenuId = menuid;

	function hidemenu() {
		hideTimer = setTimeout('hideObject(\'' + menuobj.id + '\')', 400);
	}
	
	function cancelhide() {
		if (typeof hideTimer != "undefined")
		clearTimeout(hideTimer);
	}
}

function hideObject(id){
	obj = document.getElementById(id);
	if(obj != null && typeof obj != 'undefined'){
		obj.style.visibility = 'hidden';
		//clear the mask
		hideMask();
		//set menu flag
		document.openMenuId = false;
	}
}

// helper function that finds the positon of an object, used to position the popup menu
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		// this loop will continue until offsetParent doesn't exist and obj evals to null
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function hideMask(){
		if(document.all){
			maskObj = document.getElementById('menumask');
			maskObj.style.display = 'none';
		}
}

function createMask(obj){
	if(document.all){
		var iframe = document.getElementById('menumask');
		if(iframe == null || typeof iframe == 'undefined'){
			var iframe = document.createElement('iframe');
			//iframe.src = 'javascript://false;';
			iframe.src = '/theme/img/pixel.gif';
			iframe.tabIndex = '-1';
			iframe.id = 'menumask';
			obj.parentNode.appendChild(iframe);
		}

		iframe.style.top = obj.offsetTop + 'px';
		iframe.style.left = obj.offsetLeft + 'px';
		iframe.style.width = obj.offsetWidth + 'px';
		iframe.style.height = obj.offsetHeight + 'px';
		iframe.style.display = 'block';
	}
}