/*!
 * Simple Hints script
 * require_once('static/js/base/base');
 * @author Tomas Simonaitis, 2006
 */

var hintTip = document.createElement("div");
var hintOwner = null;
var hintPos = new Array(2);
var timer = null;
var ctimer = null;
var hintData = null;

var sideHintTip = document.createElement("div");

// init hint showing, hint is created and shown after _delay_ unless aborted by hideHint()
// @param ev - event data
// @param owner - hint owner (this)
// @param hid - string holding div id to be used
// @param hdata - hint data, innerHTML to be used (string (latin1 or utf-8) encoded in base64)
function showHint(ev, owner, hclass, hdata)
{	
	if (hintOwner)
		hideHint();	

	hintTip.className = hclass;
	hintTip.style.visibility = 'hidden';
	
	hintData = hdata;
	document.body.appendChild(hintTip);		
	hintOwner = owner;

	if (ev.pageX) {
		hintPos[0] = ev.pageX;
		hintPos[1] = ev.pageY;
	} else {
		hintPos[0] = ev.clientX;
		hintPos[1] = ev.clientY;
	}

	timer = setTimeout("revealHint()", 200);
	ctimer = setTimeout("hideHint()", hdata.length * 40 + 200);
}

// hides hint
function hideHint()
{
	if (timer) {
		clearTimeout(timer);
		timer = null;
	}

	if (ctimer) {
		clearTimeout(ctimer);
		ctimer = null;
	}

	if (hintOwner) {
		document.body.removeChild(hintTip);	
		hintOwner = null;
	}
}

// actually shows hint
function revealHint()
{
	if (hintOwner) {
		if (hintData)
			hintTip.innerHTML = base64_decode(hintData);

		hintTip.style.left = (hintPos[0] + 5) + 'px';
		hintTip.style.top = (hintPos[1] + 5) + 'px';
		hintTip.style.position = 'absolute';
		hintTip.style.visibility = 'visible';
	}		
}

// display hint in side hint
function showSideHint(owner, hclass, hdata)
{
	if ($(owner)) {
		hideSideHint();

		sideHintTip.className = hclass;
		var pos = getElemPos($(owner));

		sideHintTip.style.left = (pos.x + pos.width) + 'px';
		sideHintTip.style.top = pos.y + 'px';
		sideHintTip.style.position = 'absolute';
		sideHintTip.style.visibility = 'visible';		
		sideHintTip.innerHTML = base64_decode(hdata);

		document.body.appendChild(sideHintTip);
	}
}

// hide side hint
function hideSideHint()
{	
	try {
		document.body.removeChild(sideHintTip);
	}
	catch (Exception) {
	}
}

