var hint_close_timer;
var current_hint;


function show_hint(evt, hint) {
	hint = 'hint_' + hint;
	clearTimeout(hint_close_timer);
	if (current_hint !== hint) {
		if ($('hint_message').firstChild) $('hints').appendChild($('hint_message').firstChild);
		if ($(hint)) $('hint_message').appendChild($(hint));
		evt = evt ? evt : window.event;
		$('hint').style.left = Event.pointerX(evt) - 10 + 'px';
		current_hint = hint;
	}
	$('hint').show();
}

function hide_hint() {
	hint_close_timer = setTimeout( function () { close_hint() }, 2000);
}

function close_hint() {
	$('hint').hide();
}

Element.observe(window, 'load', function () {
	var as = $('toolbar').select('a');
	for (var i = 0; i < as.length; i++) {
		if (!as[i].id) continue;
		var h = as[i].id;
		h = h.replace(/^h_/, '');
		as[i].onmouseover = (function (h) {
			return function (evt) {
				show_hint(evt, h);
			};
		}) (h);
		as[i].onmouseout = function () { hide_hint(); };
		as[i].onclick = function () { return false; };
	}
	$('hint').onmouseover = function () { clearTimeout(hint_close_timer) };
	$('hint').onmouseout = function () { hide_hint(); };
	$('hint_close').onclick = function () { clearTimeout(hint_close_timer); close_hint(); return false;};
});