var originalFirstChild;
var timerID = 0;

if (hl_color == null) var hl_color = '#efefef';
if (def_color == null) var def_color = '#dee3e7';

function createHint(which, msg, x, y)
{
	which.style.backgroundColor= hl_color;
	// record the original first child (protection when deleting)
	if (typeof(originalFirstChild) == 'undefined')
	{
	originalFirstChild = document.body.firstChild;
	}

	if (msg != '')
	{
	if (timerID != 0)
	{
		destroyTitle(which);
	}

	x = document.all ? (event.clientX + document.body.scrollLeft) : x;
	y = document.all ? (event.clientY + document.body.scrollTop) : y;
	element = document.createElement('div');
	element.style.position = 'absolute';
	element.style.zIndex = 1000;
	element.style.visibility = 'hidden';
	excessWidth = 0;
	if (document.all)
	{
		excessWidth = 50;
	}
	excessHeight = 20;
	var ss = msg;
	var re = /"postbody"/g;
	var r = ss.replace(re, '"genmed"');
	element.innerHTML = '<div class="bodyline"><table width="400" cellspacing="0" cellpadding="3" border="0"><tr><td class="row1"><table width="100%" cellspacing="0" cellpadding="3" border="0" align="center"><tr><td><span class="gensmall"><b>Последнее сообщение:</b></span></td></tr><tr><td class="quote">' + r + '</td></tr></table></td></tr></table></div>';
	renderedElement = document.body.insertBefore(element, document.body.firstChild);
	renderedWidth = renderedElement.offsetWidth;
	renderedHeight = renderedElement.offsetHeight;

	// fix overflowing off the right side of the screen
	overFlowX = x + renderedWidth + excessWidth - document.body.offsetWidth;
	x = overFlowX > 0 ? x - overFlowX : x;

	// fix overflowing off the bottom of the screen
	overFlowY = y + renderedHeight + excessHeight - window.innerHeight - window.pageYOffset;
	y = overFlowY > 0 ? y - overFlowY : y;

	renderedElement.style.top = (y + 15) + 'px';
	renderedElement.style.left = (x + 15) + 'px';

	timerID=setTimeout("renderedElement.style.visibility = 'visible'", 500);
	}
}

function destroyHint(which, bkcolor)
{
	if (timerID != 0)
	{
		clearTimeout(timerID);
		timerID=0;
	}
	which.style.backgroundColor=def_color;
	// make sure we don't delete the actual page contents (javascript can get out of alignment)
	if (document.body.firstChild != originalFirstChild)
	{
		document.body.removeChild(document.body.firstChild);
	}
}
