var hint_elm = null;
var hint_showing = 0;
var hint_link_elm = null;
var elm_hint = null;

var event_src = function(e) { 
	if (e){ return e.target; }
	if (window.event){ return window.event.srcElement; }
	return null;
}

function init_hint(){
	hint_elm = document.createElement('DIV');
	hint_elm.className = 'tooltip';
	hint_elm.style.display = 'none';
	document.body.appendChild(hint_elm);
}
function display_hint(link, text, len){
	if (!hint_elm){
		init_hint();
	}
	if (hint_showing){
		if (hint_link_elm == link){
			hide_hint();
			return;
		}
		hide_hint();
	}
	var x = hint_PosX(link);
	var y = hint_PosY(link);
	if (len > 200){
		hint_elm.style.width = '300px';
	}else if (len > 100){
		hint_elm.style.width = '200px';
	}else{
		hint_elm.style.width = '150px';
	}
	hint_elm.style.left = x+'px';
	hint_elm.style.top = (y+20)+'px';
	elm_hint = document.getElementById(text);
	move_children(elm_hint, hint_elm);
	hint_showing = 1;
	hint_elm.style.display = 'block';
	hint_link_elm = link;
	document.onmousedown = doc_mousedown;
}
function doc_mousedown(e){
	if (event_src(e) == hint_link_elm){
		document.onmousedown = function(){};
	}else{
		hide_hint();
	}
}
function hide_hint(){
	document.onmousedown = function(){};
	if (!hint_elm){
		return false;
	}
	hint_showing = 0;
	hint_elm.style.display = 'none';
	hint_link_elm = 'null';
	move_children(hint_elm, elm_hint);
	return false
}
function move_children(e_from, e_to){
	while(e_from.childNodes.length){
		e_to.appendChild(e_from.removeChild(e_from.childNodes[0]));
	}
}
function hint_PosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}
function hint_PosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}