﻿function ShowTooltip(elemLink, strURL) {
	var elemTooltip = $('divTooltip');
	elemTooltip.style.position = "absolute";
  
  /* work-around possible prototype bug in cumulativeOffset() in IE6 */
  
  if (Prototype.Browser.IE6()) { 
    var aOffset = Position.positionedOffset(elemLink);
  } else {
    var aOffset = Position.cumulativeOffset(elemLink);
  }

  elemTooltip.style.left = aOffset[0] + "px";
  elemTooltip.style.top = (aOffset[1] + elemLink.offsetHeight + 3) + "px";
  
  elemTooltip.show();
  if (this.strURL != strURL) {
    new Ajax.Request(strURL, { method: 'get', onSuccess: function(transport) {
      elemTooltip.innerHTML = transport.responseText;
      this.strURL = strURL; // this is the current content of the tooltip, no need to get it again
    },
    onFailure: function(transport) {
      elemTooltip.innerHTML = "Glossary item failed to load (" + transport.status + " error)";
    }});
  }
}

function HideTooltip() {
  $('divTooltip').hide();
}

// Checks for and hides a hanging tooltip
Event.observe(document, "dom:loaded", function() {
  HideTooltip();
	Event.observe($("divContentBody"), "mouseover", function(event) {
		if (!Event.element(event).hasClassName("glossaryterm"))
			HideTooltip();
	});
});

function Highlight(strElementID) {
	Element.addClassName($(strElementID), 'highlight');
}
function RemoveHighlight(strElementID) {
	Element.removeClassName($(strElementID), 'highlight');
}