﻿var timeoutFlag = 0;
var _e = null;

function getTerm(aObj, termId, e)
{
	_e = e.type;
	AjaxGlossary.GetTerm(termId, GetTerm_callback, aObj);
}

function GetTerm_callback(response)
{
	if (response != null && response.value != null)
	{
		var glossary = response.value;

		if (typeof(glossary) == "object")
		{
			glossaryTerm(response.context, glossary.HtmlCode, _e);
		}
	}
}

function glossaryTerm(aObj, html, e)
{

	divObj = document.getElementById("term");

	if (e == 'mouseover') {

		timeoutFlag = 1;

		xLoc = findPosX(aObj);
		yLoc = findPosY(aObj);

		if (document.all) {
			divObj.style.top = yLoc - aObj.offsetParent.offsetParent.scrollTop;
			divObj.style.left = xLoc - divObj.offsetWidth;
		} else {
			divObj.style.top = (yLoc - aObj.parentNode.parentNode.parentNode.scrollTop) + 'px';
			divObj.style.left = (xLoc - divObj.offsetWidth) + 'px';
		}

        divObj.innerHTML = html;
		divObj.style.visibility = 'visible';

	} else {

		delayedClose("term");

	}

}

function delayedClose(id) {

	timeoutFlag = 0;
	myId = id;
	someTimeout = setTimeout('closeMenu(myId)',1000);

}

function closeMenu(id) {

	if (timeoutFlag == 0) {
		document.getElementById(id).style.visibility = 'hidden';
	}

}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
