

var tip_closeTimerID;
var tip_fadeTimerID;

var tip_forceWidth = 0;
var tip_forceHeight = 0;

function TipSetSize(w, h) {
	tip_forceWidth = w;
	tip_forceHeight = h;
}

function TipNew(content) {
	var obj = document.getElementById('ToolTipObject');
	
	if (!obj) {
		obj = document.createElement("div");
		obj.id = 'ToolTipObject';
		obj.className = "tooltip";

		document.body.appendChild(obj);
	}
	if (content) {
		var tmp = document.getElementById(content);
		obj.innerHTML = tmp.innerHTML;
	} else {
		obj.innerHTML = "empty";
	}
	return obj;
}

function TipPosition(e) {
	var xoff = 16;
	var yoff = 6;
	var winw, winh, scrx, scry;


	mx = event.clientX;
	my = event.clientY;

	scrx = window.pageXOffset;
	scry = window.pageYOffset;
	winw = window.innerWidth;
	winh = window.innerHeight;


	mx += scrx;
	my += scry;

	if ((mx + tip_forceWidth + xoff) > (winw + scrx) && 
		winw > tip_forceWidth)
	{ mx -= tip_forceWidth + 32 + 4; }

	if ((my + tip_forceHeight + yoff) > (winh + scry) && 
		winh > tip_forceHeight)
	{ my -= tip_forceHeight + yoff + 4; }

	var obj = document.getElementById('ToolTipObject');
	obj.style.left = (mx + xoff) + "px";
	obj.style.top = (my + yoff) + "px";
}

function TipShow(content, timer, opacity) {
	var mx, my;
	if (timer == null) timer = 3000;
	if (opacity == null) opacity = 80;

	var obj = TipNew(content);
	obj.style.visibility = "visible";
	document.onmousemove = TipPosition;
	document.onmouseover = TipPosition;


	if (timer > 0) tip_closeTimerID = setTimeout("TipHide()", timer);

	return true;
}

function TipFade() {
	var obj = document.getElementById('ToolTipObject');

	var opacity = obj.style.opacity - 0.1;


	if (opacity > 0) {
		tip_fadeTimerID = setTimeout("TipFade()", 50);

		obj.style.opacity = opacity;
		obj.style.MozOpacity = opacity;

		return;
	}

	TipHide();
}

function TipHide() {
	var obj = document.getElementById('ToolTipObject');
	obj.style.visibility = "hidden";
	obj.style.top = "0px";
	obj.style.left = "0px";
	document.onmousemove = null;
	document.onmouseover = null;

	clearTimeout(tip_closeTimerID);
	clearTimeout(tip_fadeTimerID);
	return true;
}
