
//Global variables
var openMenus = null;
var DDmenuTimer = null;

//this function fades the menu after a menu item has been clicked
function selectItem(obj) { //the argument passed is the <a> object itself
	//select the id of the parent node (the div container in this case)
	var menuID = obj.parentNode.id; 
	//since we now know the div id, we can now fade it once the link has been clicked (triggered by the inline "onclick" event)
	//Effect.Fade(menuID); 
	
}

//hide the menu using the scriptaculous effect engine
//function hideMenu(id) {
//	resetTimeout();
//	menuTimer = setTimeout(function() {Effect.BlindUp(id, {duration:0.25});}, 500);
//}

function DDhideMenu(){ //this is just to delay the calling of hideMenus()
	DDresetTimeout();
	DDmenuTimer = setTimeout("DDhideMenus()", 500);
}

//this closes all and any open menus before opening a new menu
function DDhideMenus(){
	DDresetTimeout();
	if( openMenus ) {
		//Effect.DropOut(openMenus);
		var e = document.getElementById(openMenus).style;
		e.display = "none";
	}
	openMenus = null;
}

function DDresetTimeout() {
	if (DDmenuTimer) clearTimeout(DDmenuTimer);
	DDmenuTimer = null;
}


function DDshowMenu(menuName, offXY) {
	DDresetTimeout();
	DDhideMenus();
	
	var e = document.getElementById(menuName);
	
	//the following two lines were added to the original function to make the menu appear relative to the element, rather than at a fixed location
	e.style.left = offXY[0] + "px";	
	e.style.top = offXY[1] + "px";	
		
    //make the menu appear using the scriptaculous combination effect
	//Effect.BlindDown(menuName, {duration: 0.5});
	e.style.display="block";
	
	openMenus = menuName;
	
}

//Based on original function by QuirksMode http://www.quirksmode.org/js/findpos.html
function DDfindPos(objID) { //receives the object id as argument and returns the object's position in the page
	var curleft = curtop = 0;
	var obj = document.getElementById(objID); //get the object itself to access other of its properties
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	var j = getStyle (objID, 'height'); //call getStyle with the id of the passed object and the "height" property we want returned
	
	//Add the y offset of the element to its height so that the menu will show up under the link and not over it.
	var menuY = (parseInt(curtop) + parseInt(j)); 
	return [curleft,menuY]; // the x,y coordonates of the element (bottom left corner of element)
}


function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.offsetHeight)
		var y = x.offsetHeight;
	//else if (window.getComputedStyle)
		//var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	//CSSValueToInt(y);
	return y;
}

function CSSValueToInt(value) { 

	/*this function takes a returned CSS value like "20px" and removes the "px" so that
	the value (of "20" in this case) can be used in arithmetical operations. 
	Without doing this, the css value of "20px" cannot be added to, say, an integer, 
	so it will rather be concatenated. So this function exists as a workaround to 
	Javascript's concatenation of CSS values to other numbers.
	*/
	var	v = value.substr(0, value.length-2); //Cut off px from the string
	return v;
	
}