//**********************************************************************
// Glossary Term Popup
//**********************************************************************

var gtObjPopUp = null;
var gtPopMenuOn = 0;
var is_iPhone = (navigator.userAgent.match(/iPhone/i) != null); 

function gtPopUp(evt,objectID) {
	if (gtPopMenuOn == 1) gtPopHide();
	var evt = (evt) ? evt : ((window.event) ? event : null);
	gtObjPopUp = document.getElementById(objectID);
	if (is_iPhone) {
		gtObjPopUp.parentNode.onclick = gtPopHide;
	} else {
		document.onclick = gtPopHide;
	}

	var xPos = evt.clientX
	var yPos = evt.clientY;
	if (xPos + gtObjPopUp.offsetWidth > Geometry.getViewportWidth()) xPos = xPos - gtObjPopUp.offsetWidth;
	if (yPos + gtObjPopUp.offsetHeight > Geometry.getViewportHeight()) yPos = yPos - gtObjPopUp.offsetHeight;
	if (xPos < 0) xPos = 0;
	if (yPos < 0) yPos = 0;
	xPos += Geometry.getHorizontalScroll();
	yPos += Geometry.getVerticalScroll();
	
	// Correct the position in case the popup is nested in one or more absolutely
	// positioned layers.
	if (gtObjPopUp.offsetParent) {
		xPos -= getX(gtObjPopUp.offsetParent);
		yPos -= getY(gtObjPopUp.offsetParent);
	}
	
	gtObjPopUp.style.position = 'absolute';
	gtObjPopUp.style.left = xPos + 'px';
	gtObjPopUp.style.top = yPos + 'px';
	gtObjPopUp.style.visibility = 'visible';
} 

function gtPopHide() {
	if (gtPopMenuOn == 0) {
		gtPopMenuOn = 1;
		return
	} else {
		gtObjPopUp.style.visibility = 'hidden';
		if (is_iPhone) {
			gtObjPopUp.parentNode.onclick = null;
		} else {
			document.onclick = null;
		}
		gtObjPopUp = null;
		gtPopMenuOn = 0;
	}
}


