/* Hints */
qhint = {
	init: function() {
		if (typeof this.hint_div != 'undefined') {
			return;
		}
		if (document.getElementById('hint_text') != null) {
			this.hint_div=document.getElementById('hint_text');
		} else {
			this.hint_div=document.createElement('div');
			this.hint_div.id='hint_text';
			this.hint_div.style.display='none';
			document.getElementsByTagName('body')[0].appendChild(this.hint_div);
		}
		return;
	},
	
	show: function(obj) {
		if (typeof this.hint_div=='undefined') {
			this.init();
		}
		if (this.hint_div.style.display == 'block') {
			return;
		} else if (!obj.hasAttribute('custom_hint')) {
			return;
		}
		var offset = this.offsets(obj);
		var scroll = this.scrolls(); 
		this.hint_div.innerHTML = "<p>"+obj.getAttribute('custom_hint').replace(/\[b\]/g, "<b>").replace(/\[\/b\]/g, "<\/b>").replace(/\[br\]/g, "</p><p>")+"</p>";
		this.hint_div.style.display = 'block';
		
		var total_width = offset.left+this.hint_div.offsetWidth+10;
		var body_width = document.getElementsByTagName("body")[0].offsetWidth;
		var horiz_dir = total_width < body_width ? obj.offsetWidth : -5 - this.hint_div.offsetWidth;
		
		this.hint_div.style.left = (offset.left+horiz_dir)+'px';
		this.hint_div.style.top = offset.top - scroll.top < this.hint_div.offsetHeight ? (offset.top + obj.offsetHeight)+'px' : (offset.top+5-this.hint_div.offsetHeight)+'px';
		
		return;	
	},
	
	hide: function() {
		if (this.hint_div.style.display == 'none') {
			return;
		}		
		this.hint_div.style.display = 'none';
		return;	
	},
	
	offsets: function(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return {left: curleft,top: curtop};
	},
	
	scrolls: function() {
		return {top: self.pageYOffset||(document.documentElement&&document.documentElement.scrollTop)||(document.body&&document.body.scrollTop), left: self.pageXOffset||(document.documentElement&&document.documentElement.scrollLeft)||(document.body&&document.body.scrollLeft)};
	}
}

function showhint(obj) {
	return qhint.show(obj);	
};
function hidehint() {
	return qhint.hide();
};
/* End of Hints */

