//nova abordagem às tooltips de entradas de glossário.
//LP 18-01-2008

var id = "myTooltip";
var background = "#333333";
var border = "1px solid #000000";
var display = "none";
var cursor = "help";
var font = "10px Arial, Verdana, Sans-serif";
var color = "#ffffff";
var width = "250px";

var opacity = 100; // 0 a 100
var padding = "2px 5px";
var position = "absolute";

//
function setPos(event) {
  var marginX = -9; //distancia do mouse em x
  var marginY = 3; //distancia do mouse em y
	if (document.all) {//IE
	  if (window.event.clientX > document.body.clientWidth/2){
	     var marginX = -223;
	  }
		_x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		_y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		_x += (window.event.clientX+marginX);
		_y += (window.event.clientY+marginY);
	} else {//Good Browsers
	  if (event.pageX > document.body.clientWidth/2){
	     var marginX = -223;
	  }
		_x = (event.pageX+marginX);
		_y = (event.pageY+marginY);
	}
}
//
function showTip(text) {
	var t = document.getElementById(id);

	t.style.display = "block";
	document.onmousemove = function(event) {
    setPos(event);
		t.innerHTML = text;
		t.style.left = _x+"px";
		t.style.top = _y+"px";
	}
}
//
function hideTip() {
	var t = document.getElementById(id).style;
	t.display = "none";
}
//
function tooltip() {
	var body = document.getElementsByTagName("body");
	body = body[0];
	body.innerHTML += "<div align='justify' id='"+id+"'></div>";
	var t = document.getElementById(id).style;
	t.background = background;
	t.border = border;
	t.display = display;
	t.font = font;
	t.color = color;
	t.opacity = opacity/100;
	t.width = width;
	t.filter = "alpha(opacity="+opacity+")";
	t.padding = padding;
	t.position = position;
	var links = document.getElementsByTagName("a");
	for (i=0; i<links.length; i++) {
		var title = links[i].getAttribute("title");
		if (title) {
			links[i].setAttribute("tptitle", title);
			links[i].removeAttribute("title");
			links[i].onmouseover = function() { showTip(this.getAttribute("tptitle")+"<br />"+this.href); }
			links[i].onmouseout = function() { hideTip(); }
		}
	}
}
//
window.onload = function() {
	tooltip();
}

