//############################################################
//# TOOLTIP
//############################################################

addEventListener(window,"load",init_tt);

function init_tt() {
  var div_tt = document.createElement("div");
  div_tt.setAttribute("id","tooltip");
  div_tt.className = "tooltip";
 	document.body.appendChild(div_tt);
}

function show_tt(msg,e,_width) {
	var tt = document.getElementById("tooltip");
	var eo = new evntobj(e);
	if (tt) {
		tt.innerHTML = msg;
		if (_width) {
			tt.style.width = _width + "px";
		}
		if (parseInt(eo.x + tt.clientWidth + 10) > parseInt(document.body.clientWidth)) {
			tt.style.left = parseInt(document.body.clientWidth - 10 - tt.clientWidth) + parseInt(document.body.scrollLeft) + "px";
		} else {
			tt.style.left = parseInt(eo.x + 10) + parseInt(document.body.scrollLeft) + "px";
		}
		if (parseInt(eo.y + tt.clientHeight + 15) > parseInt(document.body.clientHeight)) {
			tt.style.top = parseInt(eo.y - 15 - tt.clientHeight) + parseInt(document.body.scrollTop) + "px";
		} else {
			tt.style.top = parseInt(eo.y + 15) + parseInt(document.body.scrollTop) + "px";
		}
		tt.style.position = "absolute";
		tt.style.display = "block";
		evntobj.addEventListener(document,"mousemove",move_tt);
	}
}

function hide_tt() {
	var tt = document.getElementById("tooltip");
	if (tt) {
		tt.style.display = "none";
		//tt.style.width = "140px";
		removeEventListener(document,"mousemove",move_tt);
	}
}

function move_tt(e) {
	var tt = document.getElementById("tooltip");
	var eo = new evntobj(e);
	if (parseInt(eo.x + tt.clientWidth + 10) > parseInt(document.body.clientWidth)) {
		tt.style.left = parseInt(document.body.clientWidth - 10 - tt.clientWidth) + parseInt(document.body.scrollLeft) + "px";
	} else {
		tt.style.left = parseInt(eo.x + 10) + parseInt(document.body.scrollLeft) + "px";
	}
	if (parseInt(eo.y + tt.clientHeight + 15) > parseInt(document.body.clientHeight)) {
		tt.style.top = parseInt(eo.y - 15 - tt.clientHeight) + parseInt(document.body.scrollTop) + "px";
	} else {
		tt.style.top = parseInt(eo.y + 15) + parseInt(document.body.scrollTop) + "px";
	}
	eo.consume();
}
