var IE = document.all ? true : false;
var NS6 = document.getElementById && !document.all;
var currentFloatingBox = null;

document.onmousemove = moveFloatingBox;

function ieTrueBody()
{
	return (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
}

function moveFloatingBox(e)
{
	if (currentFloatingBox) {

		var div = currentFloatingBox;

		var mouseX = NS6 ? e.pageX : event.clientX + ieTrueBody().scrollLeft;
		var mouseY = NS6 ? e.pageY : event.clientY + ieTrueBody().scrollTop;

		var offX = 14;
		var offY = 22;

		var rightEdge  = IE && !window.opera ?
			ieTrueBody().clientWidth -  event.clientX - offX:
			window.innerWidth  - e.clientX - offX - 20;
		var bottomEdge = IE && !window.opera ?
			ieTrueBody().clientHeight - event.clientY - offY :
			window.innerHeight - e.clientY - 20 - offY;
		var leftEdge = offX < 0 ? -offX : -1000;

		if (rightEdge < div.offsetWidth) {
			div.style.left = IE ?
				ieTrueBody().scrollLeft + event.clientX - div.offsetWidth - 4 + "px" :
				window.pageXOffset + e.clientX - div.offsetWidth - 4 + "px";
		} else if (mouseX < leftEdge) {
			div.style.left = "5px";
		} else {
			div.style.left = mouseX + offX + "px";
		}

		if (bottomEdge < div.offsetHeight) {
			div.style.top = IE ?
				ieTrueBody().scrollTop + event.clientY - div.offsetHeight - 4 + "px" :
				window.pageYOffset + e.clientY - div.offsetHeight - 4 + "px";
		} else {
			div.style.top = mouseY + offY + "px";
		}
		
	}
}

function showFloatingBox(id)
{
	floatingBox = document.getElementById(id);
	if (floatingBox != currentFloatingBox) {
		hideFloatingBox();
	}
	currentFloatingBox = floatingBox;
	currentFloatingBox.style.display = '';
	return true;
}

function hideFloatingBox()
{
	if (currentFloatingBox) {
		currentFloatingBox.style.display = 'none';
		currentFloatingBox = null;
	}
	return true;
}
