var buttonPOSArray = new Array();
var buttonPOS;
var hideTimeOut;
var ie = 0;
var menuDivArray = new Array();

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function getItemsList(button,state,menudiv){
	itemsMenu = document.getElementById(menudiv);
	if(state == "show"){
		hideAll();
		menuDivArray.push(menudiv);
		clearTimeout(hideTimeOut);
		wHeight = getWindowHeight();
		buttonPOS = findPos(button.childNodes[0]).toString();
		buttonPOSArray = buttonPOS.split(",");
		xPos = buttonPOSArray[0] + "px";
		yPos = parseInt(buttonPOSArray[1])+15;
		if(ie){
			yPos = yPos + 22;
		}
		
		itemsMenu.style.display = "block";
		dHeight = itemsMenu.offsetHeight;
		yPos = yPos - (dHeight+39);
		yPos = yPos.toString() + "px";
		itemsMenu.style.top = yPos;
		itemsMenu.style.left = xPos
		/*if((parseInt(buttonPOSArray[1]) + dHeight) > wHeight){
			yPos = parseInt(buttonPOSArray[1])-dHeight;
			yPos = yPos.toString() + "px";
			itemsMenu.style.top = yPos;
		}*/
		
	}
	if(state == "hide"){
		hideTimeOut = setTimeout("hideAll()",250);
	}
	if(state == "hold"){
		clearTimeout(hideTimeOut);
	}
}

function hideAll(){
	if(menuDivArray.length > 0){
		document.getElementById(menuDivArray.pop()).style.display = "none";
	}
}

function getWindowHeight() {
  var windowHeight = 0;
	
	if (typeof(window.innerHeight) == 'number'){
		windowHeight = window.innerHeight;	
	}else{
		if (document.documentElement && document.documentElement.clientHeight){
			windowHeight = document.documentElement.clientHeight;
			
		}
		else{
			if (document.body && document.body.clientHeight){
				ie = 1;
				windowHeight = document.body.clientHeight;
			}
		}
	}
				
  return windowHeight;
};
