/*original javascript for Bubble Tooltips by Alessandro Fulciniti
- http://pro.html.it - http://web-graphics.com */

/* Modified for "#"-links, timeout, header and link title by J. Raben */
/* Modified for span by J. Kammann */

var tttimeoutObj = null;
var tttimeoutValue = 500;
var tttooltip = null;
var doHideSelects = false;

function enableTooltips(id){
	var links, i, h;
	if (!document.getElementById || !document.getElementsByTagName) return;
	h = document.createElement("div");
	h.id="btc";
	h.setAttribute("id", "btc");
	h.style.position = "absolute";
	document.getElementsByTagName("body")[0].appendChild(h);
	if (id == null) links = document.getElementsByTagName("span");
	else links = document.getElementById(id).getElementsByTagName("span");
	for (i=0; i<links.length; i++) {
    	Prepare(links[i]);
    }
}

function Prepare(el){
	var tooltip, b, s, t, l, tparts, tparts2, headerText = "";
	t = el.getAttribute("title");
	if (t && t.match(/\|/)) {
		tparts = t.split('|');
		t = tparts[1];
		headerText = tparts[0];
		if (tparts.length >= 3) l = tparts[2];
	}
	el.removeAttribute("title");
	tooltip = CreateEl("span","tooltip");
	if (headerText.length) {
		s = CreateEl("h1", "top");
		s.appendChild(document.createTextNode(headerText));
		tooltip.appendChild(s);
		s = CreateEl("span", "middle");
	}
	else {
		s = CreateEl("span","top");
	}
	if (t && t.match(/\\n/)) {
		tparts2 = t.split('\\n');
		for (count = 0; count < tparts2.length; count++) {
			s.appendChild(document.createTextNode(tparts2[count]));
			//s.appendChild(document.createElement("br"));
		}
	}
	else s.appendChild(document.createTextNode(t));
	tooltip.appendChild(s);
	b=CreateEl("b", "bottom");
	b.appendChild(document.createTextNode(l));
	if (t && t.length) {
		tooltip.appendChild(b);
		setOpacity(tooltip);
		el.tooltip = tooltip;
		el.onmouseover = showTooltipTimeout;
		el.onclick = showTooltipTimeout;
		el.onmouseout = hideTooltip;
		el.onmousemove = Locate;
	}
}

function showTooltipTimeout(e) {
	tttooltip = this.tooltip;
	tttimeoutObj = setTimeout('this.tooltip=tttooltip;showTooltip();', tttimeoutValue);
}

function ttremoveTimeout() {
	if (tttimeoutObj) clearTimeout(tttimeoutObj);
	tttimeoutObj = null;
}
function showTooltip() {
	ttremoveTimeout();
	/* hide select-Boxes */
	if (doHideSelects) {
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "hidden";
		}
	}
	document.getElementById("btc").appendChild(this.tooltip);
	document.getElementById("btc").firstChild.style.bottom = "0px";
}

function hideTooltip(e){
	ttremoveTimeout();
	/* show select-Boxes */
	if (doHideSelects) {
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
		}
	}
	var d=document.getElementById("btc");
	if (d.childNodes.length > 0) d.removeChild(d.firstChild);
}

function setOpacity(el){
	el.style.filter = "alpha(opacity:95)";
	el.style.KHTMLOpacity = "0.95";
	el.style.MozOpacity = "0.95";
	el.style.opacity = "0.95";
}

function CreateEl(t,c){
	var x = document.createElement(t);
	if (c) x.className = c;
	x.style.display = "block";
	return(x);
}

function Locate(e){
	var posx = 0, posy = 0;
	if (!e) e = window.event;
	if (e.pageX || e.pageY) {
    	posx = e.pageX;
		posy = e.pageY;
    }
	else if (e.clientX || e.clientY) {
    	if (document.documentElement.scrollTop) {
        	posx = e.clientX + document.documentElement.scrollLeft;
        	posy = e.clientY + document.documentElement.scrollTop;
        }
    	else {
        	posx = e.clientX + document.body.scrollLeft;
        	posy = e.clientY + document.body.scrollTop;
        }
    }
	document.getElementById("btc").style.top = (posy-10) + "px";
	document.getElementById("btc").style.left = (posx-20) + "px";
} 

var oldOnloadBubble = window.onload;

window.onload = function() {
	enableTooltips();
	if (oldOnloadBubble) oldOnloadBubble();
};
