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

startList = function() {
	if (document.all&&document.getElementById) {
	navRoot = document.getElementById("popMenuCol");
	for (i=0; i<navRoot.childNodes.length; i++) {
	node = navRoot.childNodes[i];
	if (node.className=="popMenu") {
	node.onmouseenter=function() {
	this.className+=" over";
	  }
	  node.onmouseleave=function() {
	  this.className=this.className.replace
		(" over", "");
	   }
	   }
	  }
	 }
	}	


function enableTooltips(id){
var links,i,h;
if(!document.getElementById || !document.getElementsByTagName) return;
h=document.createElement("span"); //<span></span>
h.id="btc"; //<span id="btc"></span>
h.style.position="absolute"; // <span id="btc" style="position: absolute"></span>
document.getElementsByTagName("body")[0].appendChild(h); // add span before  </body>
if(id==null) links=document.getElementsByTagName("a"); //if there is no ID specified in window.onload, gather every link on the page
else links=document.getElementById(id).getElementsByTagName("a"); //else get all links inside the specified ID 
for(i=0;i<links.length;i++){
    Prepare(links[i]); // loop through all the links
    }
}

function Prepare(el){
var tooltip,t,b,s,l;
t=el.getAttribute("title"); // el is each <a>. Get the title. 
if(t==null || t.length==0) return; //it we don't have a title attribute, exit the function
el.removeAttribute("title"); // remove title from <a> so the default pop-up does not show
tooltip=CreateEl("span","tooltip"); //<span class="tooltip"></span>
tooltip.appendChild(document.createTextNode(t)); //<span class="tooltip">title text</span>
// setOpacity(tooltip); 
el.tooltip=tooltip;
el.onmouseover=showTooltip;
el.onmouseout=hideTooltip;
document.getElementById("btc").onmouseover=hideTooltip;
el.onmousemove=Locate;
}

function showTooltip(e){
document.getElementById("btc").appendChild(this.tooltip); 
Locate(e);
}

function hideTooltip(e){
var d=document.getElementById("btc");
if(d.childNodes.length>0) d.removeChild(d.firstChild);
}
//option for setting opacity
function setOpacity(el){
el.style.filter="alpha(opacity:40)";
el.style.KHTMLOpacity="0.40";
el.style.MozOpacity="0.40";
el.style.opacity="0.40";
}

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


function Locate(e){
var posx=0,posy=0;
if(e==null) 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;
        }
    } // we need a function that calculates the height of the bubble and then positions the top accordingly. Or we need to position from the mouse, not the top of the page.
document.getElementById("btc").style.top=(posy-80)+"px"; //position of the tooltip
document.getElementById("btc").style.left=(posx-10)+"px"; //position of the tooltip
}

window.onload = function(e) {
enableTooltips();
startList();
}
