//////////////////////////////////////////////////////////////////////////////////
//
// $Id: tooltip.js 361 2006-09-28 01:22:29Z paulegan $
//
// ToolTip object for displaying a floating text box above HTML elements.
//
// paulegan@mail.com	2002-11-12
//


// Tooltip offset from pointer
var xOffset = 10;
var yOffset = -40;



// ToolTip constructor: requires two DOM elements and will fail
// if they're undefined.  This can happen if an instance is 
// created before the elements are parsed within the HTML.
//
function ToolTip(bodyElement, textElement)
{
	if (!bodyElement) {
		alert("bodyElement undefined!");
		return (false);
	}
	if (!textElement) {
		alert("textElement undefined!");
		return (false);
	}

	this.bodyElement = bodyElement;
	this.textElement = textElement;

	var posx = 0;
	var posy = 0;

	document.onmousemove = function(ev)
	{
		posx = ((ev)?(ev.pageX):(event.x+document.body.scrollLeft))+xOffset;
		posy = ((ev)?(ev.pageY):(event.y+document.body.scrollTop))+yOffset;

		if (bodyElement.style.visibility == "hidden") {
			return (false);
		}
		bodyElement.style.left = posx + "px";
		bodyElement.style.top = posy + "px";

		return (true);
	}

	this.hide();

	return (this);
}


// ToolTip.show(): Replaces tooltip text element and enables visibilty.
//
ToolTip.prototype.show = function(text)
{
	if (!text) {
		return(false);
	}
	this.textElement.innerHTML = text;
	this.bodyElement.style.visibility = "visible";

	return (true);
}


// ToolTip.hide(): Hides the tooltip body element.
//
ToolTip.prototype.hide = function()
{
	this.bodyElement.style.visibility = "hidden";
	return (true);
}

