
function ToolTip(linkElement, html, options) {
	// Properties
	this.linkElement = linkElement;
	this.html        = html
	this.options     = options ? options : new Object();
	this.tooltip     = null;
	
	// Default properties
	if ( this.options.snapToMouse == undefined ) this.options.snapToMouse = true;
	if ( this.options.marginX == undefined ) this.options.marginX = 16;
	if ( this.options.marginY == undefined ) this.options.marginY = 16;
	
	// Methods
	this.init     = ToolTip_Init;
	this.create   = ToolTip_Create;
	this.show     = ToolTip_Show;
	this.hide     = ToolTip_Hide;
	this.follow   = ToolTip_Follow;
	this.setPos   = ToolTip_SetPos;
	this.goToLink = ToolTip_GoToLink;
	
	if ( this.linkElement )
		this.init();
}



function ToolTip_Init() {
	var refObj = this;
	
	this.create();
	
	this.linkElement.onmouseover = function(e) { refObj.show(e); };
	this.linkElement.onmouseout = function(e) { refObj.hide(e); };
	if ( this.options.snapToMouse )
		this.linkElement.onmousemove = function(e) { refObj.follow(e); };
	if ( this.options.link )
		this.linkElement.onclick = function(e) { refObj.goToLink(e); };
}




function ToolTip_Create() {
	this.tooltip = document.createElement("div");
		//this.tooltip.id = "noSignatureAgreement-learnmore-item";
		this.tooltip.className = "tooltip";
		if ( this.options.cssClass )
			this.tooltip.className = this.tooltip.className + " " + this.options.cssClass;
		this.tooltip.style.display = "none";
		this.tooltip.style.position = "absolute";
	
	var eToolTipContainer = document.createElement("div");
		eToolTipContainer.className = "tooltip-container";
			
	var eToolTipContent = document.createElement("div");
		eToolTipContent.className = "tooltip-content";
		eToolTipContent.innerHTML = this.html;
		
	var eToolTipFooter = document.createElement("div");
		eToolTipFooter.className = "tooltip-footer";
		eToolTipFooter.innerHTML = "&nbsp;";
		
	eToolTipContainer.appendChild(eToolTipContent);
	eToolTipContainer.appendChild(eToolTipFooter);
	this.tooltip.appendChild(eToolTipContainer);
	
	document.documentElement.getElementsByTagName("body")[0].appendChild(this.tooltip);
}



function ToolTip_Show(e) {
	this.setPos(e);
	this.tooltip.style.zIndex = "100000";
	this.tooltip.style.display = "block";
}



function ToolTip_Hide(e) {
	this.tooltip.style.display = "none";
	this.tooltip.style.zIndex = "0";
}



function ToolTip_Follow(e) {
	this.setPos(e);
}



function ToolTip_GoToLink(e) {
	this.hide(e);
	window.location.href = this.options.link;
}



function ToolTip_SetPos(e) {
	if (!e) e = event;
	var screenPosX = window.scrollX != undefined ? window.scrollX : document.documentElement.scrollLeft;
	var screenPosY = window.scrollY != undefined ? window.scrollY : document.documentElement.scrollTop;
	
	this.tooltip.style.left = String(e.clientX + screenPosX + this.options.marginX) + "px";
	this.tooltip.style.top  = String(e.clientY + screenPosY + this.options.marginY) + "px";
}
