var p_halign = 'right'; // left, center, right
var p_container = null;

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent; 
		}
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent; 
		}
	}
	return curtop;
}

function showTip(e, text, l) {
	if (!e) var e = window.event;
	if (!obj) var obj = (e.target) ? e.target : e.srcElement;
	p_container.innerHTML = text;
	xPos = findPosX(obj);
	switch (p_halign)
	{
		case 'right':
			xPos += obj.offsetWidth;
			break;
		case 'center':
			xPos += (obj.offsetWidth - p_container.offsetWidth) / 2;
			break;	
	};
	//yPos = findPosY(obj) + obj.offsetHeight + 2;
	//yPos = findPosY(obj) - (obj.offsetHeight / 2) - 80;
	yPos = findPosY(obj) + ( obj.offsetHeight / 2 );
	
    if (xPos + p_container.offsetWidth > document.body.clientWidth) xPos = document.body.clientWidth - p_container.offsetWidth - 2;
	p_container.style.left = xPos + 'px';
	p_container.style.top = yPos + 'px';
	p_container.style.visibility = 'visible';
	if (!obj) return;
	obj.onmouseout = destroyTip;
}

function destroyTip(e) {
	if (!e) var e = window.event;
	if (!obj) var obj = (e.target) ? e.target : e.srcElement;
	p_container.style.visibility = 'hidden';
	p_container.innerHTML = '';
	if (!obj) return;
	obj.onmouseout = null;
}

function initTips() {
	p_container = document.createElement('div');
	p_container.className = 'tooltip';
	p_container.id = 'tooltip';
	if (!p_container) return;
	p_container.style.visibility = 'hidden';
	p_container.style.zIndex = '100';
	p_container.style.position = 'absolute';
	document.body.appendChild(p_container);
}

//window.onload += initTips;