/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/***************************************************************************
* Modified by Alex Garcia on 1/28/2006:
***************************************************************************/

var offsetxpoint = 5; //Customize x offset of movable tooltip
var offsetypoint = 20; //Customize y offset of movable tooltip
var ie = document.all;
var ns6 = document.getElementById && !document.all;
var enabletip = false;

if (ie || ns6)
	var tipobj = document.getElementById("thetooltip");
if (ns6) {
	var shadow_tlc = document.getElementById("shadow_tlc");
	var shadow_l = document.getElementById("shadow_l");
	var shadow_blc = document.getElementById("shadow_blc");
	var shadow_bll = document.getElementById("shadow_bll");
	var shadow_b = document.getElementById("shadow_b");
	var shadow_blr = document.getElementById("shadow_blr");
	var shadow_brc = document.getElementById("shadow_brc");
	var shadow_r = document.getElementById("shadow_r");
	var shadow_trc = document.getElementById("shadow_trc");
}

function ietruebody() {
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

// movable tooltips
function tooltip(thetext, thewidth) {
	if (ns6 || ie) {
		if (typeof thewidth != "undefined") tipobj.style.width = thewidth + "px";
		tipobj.innerHTML = thetext;
		enabletip = true;
		return false;
	}
}

// called for movable tooltips
function positiontip(e) {
	if (enabletip && tipobj) {
		var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
		var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
		//window.status = "(" + curX + ", " + curY + ")";
		
		//Find out how close the mouse is to the corner of the window
		var rightedge = ie && !window.opera ? ietruebody().clientWidth - event.clientX - offsetxpoint : window.innerWidth - e.clientX - offsetxpoint - 20;
		var bottomedge = ie && !window.opera ? ietruebody().clientHeight - event.clientY - offsetypoint : window.innerHeight - e.clientY - offsetypoint - 20;
		var leftedge = (offsetxpoint < 0) ? offsetxpoint * (-1) : -1000;
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge < tipobj.offsetWidth) {
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left = ie ? ietruebody().scrollLeft + event.clientX - tipobj.offsetWidth + "px" : window.pageXOffset + e.clientX - tipobj.offsetWidth + "px";
		}
		else if (curX < leftedge) {
			tipobj.style.left = "5px";
		}
		else {
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left = curX + offsetxpoint + "px";
			//tipobj.style.top = curY + offsetypoint + "px";
		}
		
		//same concept with the vertical position
		if (bottomedge < tipobj.offsetHeight)
			tipobj.style.top = ie ? ietruebody().scrollTop + event.clientY - tipobj.offsetHeight - offsetypoint + "px" : window.pageYOffset + e.clientY - tipobj.offsetHeight - offsetypoint + "px";
		else
			tipobj.style.top = curY + offsetypoint + "px";
		tipobj.style.visibility = "visible";
		
		if (ns6) {
			// position the shadow elements
			var tlc_pos_l = parseInt(tipobj.style.left) - 7;
			var tlc_pos_t = parseInt(tipobj.style.top);
			
			var l_pos_l = parseInt(tipobj.style.left) - 7;
			var l_pos_t = parseInt(tipobj.style.top) + 7;
			var l_height = parseInt(tipobj.offsetHeight) - 7;
			
			var blc_pos_l = parseInt(tipobj.style.left) - 7;
			var blc_pos_t = parseInt(tipobj.style.top) + parseInt(tipobj.offsetHeight);
			
			var bll_pos_l = parseInt(tipobj.style.left);
			var bll_pos_t = blc_pos_t;
			
			var b_pos_l = parseInt(tipobj.style.left) + 7;
			var b_pos_t = blc_pos_t;
			var b_width = parseInt(tipobj.offsetWidth) - 14;

			var blr_pos_l = parseInt(tipobj.style.left) + parseInt(tipobj.offsetWidth) - 7;
			var blr_pos_t = blc_pos_t;

			var brc_pos_l = parseInt(tipobj.style.left) + parseInt(tipobj.offsetWidth);
			var brc_pos_t = blc_pos_t;
			
			var r_pos_l = brc_pos_l;
			var r_pos_t = parseInt(tipobj.style.top) + 7;
			var r_height = parseInt(tipobj.offsetHeight) - 7;
			
			var trc_pos_l = brc_pos_l;
			var trc_pos_t = parseInt(tipobj.style.top);
			
			// top left corner of shadow
			shadow_tlc.style.left = tlc_pos_l.toString() + "px";
			shadow_tlc.style.top = tlc_pos_t.toString() + "px";
			shadow_tlc.style.width = "7px";
			shadow_tlc.style.height = "7px";
			shadow_tlc.style.visibility = "visible";
			
			// left side of shadow
			shadow_l.style.left = l_pos_l.toString() + "px";
			shadow_l.style.top = l_pos_t.toString() + "px";
			shadow_l.style.width = "7px";
			shadow_l.style.height = r_height.toString() + "px";
			shadow_l.style.visibility = "visible";
			
			// bottom left corner of shadow
			shadow_blc.style.left = blc_pos_l.toString() + "px";
			shadow_blc.style.top = blc_pos_t.toString() + "px";
			shadow_blc.style.width = "7px";
			shadow_blc.style.height = "7px";
			shadow_blc.style.visibility = "visible";

			// bottom left inner corner of shadow
			shadow_bll.style.left = bll_pos_l.toString() + "px";
			shadow_bll.style.top = bll_pos_t.toString() + "px";
			shadow_bll.style.width = "7px";
			shadow_bll.style.height = "7px";
			shadow_bll.style.visibility = "visible";

			// bottom of shadow
			shadow_b.style.left = b_pos_l.toString() + "px";
			shadow_b.style.top = b_pos_t.toString() + "px";
			shadow_b.style.width = b_width.toString() + "px";
			shadow_b.style.height = "7px";
			shadow_b.style.visibility = "visible";

			// bottom right inner corner of shadow
			shadow_blr.style.left = blr_pos_l.toString() + "px";
			shadow_blr.style.top = blr_pos_t.toString() + "px";
			shadow_blr.style.width = "7px";
			shadow_blr.style.height = "7px";
			shadow_blr.style.visibility = "visible";
			
			// bottom right corner of shadow
			shadow_brc.style.left = brc_pos_l.toString() + "px";
			shadow_brc.style.top = brc_pos_t.toString() + "px";
			shadow_brc.style.width = "7px";
			shadow_brc.style.height = "7px";
			shadow_brc.style.visibility = "visible";
			
			// right shadow
			shadow_r.style.left = r_pos_l.toString() + "px";
			shadow_r.style.top = r_pos_t.toString() + "px";
			shadow_r.style.width = "7px";
			shadow_r.style.height = r_height.toString() + "px";
			shadow_r.style.visibility = "visible";
			
			// top right corner of shadow
			shadow_trc.style.left = trc_pos_l.toString() + "px";
			shadow_trc.style.top = trc_pos_t.toString() + "px";
			shadow_trc.style.width = "7px";
			shadow_trc.style.height = "7px";
			shadow_trc.style.visibility = "visible";
		}
	}
}

function hidetooltip() {
	enabletip = false;
	enablelockedtip = false;
	tipobj.style.visibility = "hidden";
	tipobj.style.left = "-1000px";
	tipobj.style.backgroundColor = '';
	tipobj.style.backgroundImage = '';
	tipobj.style.width = '';
	
	for (var i = 0; (div = document.getElementsByTagName("div")[i]); i++) {
		if (div.id.indexOf("shadow_") != -1) {
			div.style.visibility = "hidden";
			div.style.left = "-1000px";
		}
	}
}

document.onmousemove = positiontip;
