function AjaxHint(id, divHint) {
	var oThis = this;
	this.divHint = $(divHint);

	Event.observe(id, 'mouseover', function(e) { oThis.getHint(e);});
	Event.observe(id, 'mouseout', function(e) { oThis.hideHint(e);});
}

AjaxHint.prototype = {
	ajaxRequest: null,
	hintedObject:  null,
	hintTimer: null,

	cancelActivity: function () {
		if (this.hintTimer) {
			clearTimeout(this.hintTimer);
			this.hintTimer = null;
		}
		if (this.ajaxRequest) {
			this.ajaxRequest.transport.abort();
			this.ajaxRequest = null;
		}
	},

	getHint: function (event) {
		element = Event.element(event);
		if (element.tagName.toLowerCase() != 'a') {
			return;
		}
		this.hintedObject = element;
		this.hintedObject.style.cursor = 'wait';
		var oThis = this;
		this.hintTimer = setTimeout(
			function() {oThis.timerGetHint()}, 
			500
		);
	},

	timerGetHint: function () {
		if (! this.hintedObject) {
			return;
		}

		var oThis = this;
		this.ajaxRequest = new Ajax.Request(
			'gethint.php',
			{
				method: 'get',
				parameters: 'id=' + 
					this.hintedObject.id.substring(3),
				onComplete: function(request) 
					{ oThis.ajaxGetHint(request); }
			}
		);
	},
	
	hideHint: function (event) {
		element = Event.element(event);
		if (element.tagName.toLowerCase() != 'a') {
			return;
		}
		this.cancelActivity();
		this.hintedObject.style.cursor = '';
		this.hintedObject = null;
		this.divHint.style.display = 'none';
		
	},
	
	ajaxGetHint: function (request) {
		this.divHint.innerHTML = request.responseText;
		var pos = Position.cumulativeOffset(this.hintedObject);
		this.divHint.style.left = pos[0] + 'px';
		this.divHint.style.top = (pos[1] + this.hintedObject.offsetHeight) + 'px';
		this.divHint.style.display = 'block';
		this.hintedObject.style.cursor = '';
	}	
}

window.onload = function() {
	new AjaxHint('ulHintDisplayer', 'divHint');
}