

// TOOLTIP by Paul Sowden
// http://htmlcoder.h1.ru/JavaScript/?11 (ru)


function stopError(){
	return true;
}
window.onerror = stopError;

window.onload = function(e){
	if (document.createElement) tooltip.d();
}

tooltip = {
	t: document.createElement("DIV"),
	c: null,
	g: false,
	m: function(e){
		if (tooltip.g){
			oCanvas = document.getElementsByTagName(
			(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
			)[0];
			x = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
			y = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
			tooltip.a(x, y);
		}
	},

	d: function(){
		tooltip.t.setAttribute("id", "tooltip");
		document.body.appendChild(tooltip.t);
		a = (document.all) ? document.all : document.getElementsByTagName("*");
		aLength = a.length;
		for (var i = 0; i < aLength; i++){
			if (a[i].getAttribute("title")){
				a[i].setAttribute("text", a[i].getAttribute("title"));
				a[i].removeAttribute("title");
				if (a[i].getAttribute("alt") && a[i].complete) a[i].removeAttribute("alt");
				tooltip.l(a[i], "mouseover", tooltip.s);
				tooltip.l(a[i], "mouseout", tooltip.h);
			}else
				if (a[i].getAttribute("alt") && a[i].complete){
					a[i].setAttribute("text", a[i].getAttribute("alt"));
					a[i].removeAttribute("alt");
					tooltip.l(a[i], "mouseover", tooltip.s);
					tooltip.l(a[i], "mouseout", tooltip.h);
				}
		}
		document.onmousemove = tooltip.m;
		window.onscroll = tooltip.h;
	},

	s: function(e){
		d = (window.event) ? window.event.srcElement : e.currentTarget;
		if (!d.getAttribute("text")) return;
		tooltip.t.appendChild(document.createTextNode(d.getAttribute("text")));
		tooltip.c = setTimeout("tooltip.t.style.visibility = 'visible';", 500);
		tooltip.g = true;
	},

	h: function(e){
		tooltip.t.style.visibility = "hidden";
		if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
		clearTimeout(tooltip.c);
		tooltip.g = false;
		tooltip.a(-99, -99);
	},

	l: function(o, e, a){
		if (o.addEventListener) o.addEventListener(e, a, true);
		else
			if (o.attachEvent) o.attachEvent("on" + e, a);
			else
				return null;
	},

	a: function(x, y){
		oCanvas = document.getElementsByTagName(
		(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
		)[0];
		w_width = window.event ? oCanvas.clientWidth : window.innerWidth;
		t_width = window.event ? tooltip.t.clientWidth : tooltip.t.innerWidth;
		t_extra_width = 7; // padding + borderWidth;

		tooltip.t.style.top = y + 8 + "px";
		tooltip.t.style.left = x + 8 + "px";
		while (x + t_width + t_extra_width > w_width){
			--x;
			tooltip.t.style.left = x + "px";
			t_width = window.event ? tooltip.t.clientWidth : tooltip.t.innerWidth;
		}
	}
}


