/* ----------------------------------------------------------------------

	JS Underlib v1.1
	by Ian Whitcomb
	
	http://www.xynthetik.com
	
	Simply add this javascript file and the CSS file onto
	your document and youll be able to create tooltip links
	just by using the following code.
	
		<a description="Tooltip body" name="Tooltip name">Label</a>
	
	
	Or just use the description to exclude the name bar.
	
		<a description="Tooltip body">Label</a>
		

   ---------------------------------------------------------------------- */

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
	   cursor.x = e.pageX;
	   cursor.y = e.pageY;
    } else {
	   cursor.x = e.clientX +
		  (document.documentElement.scrollLeft ||
		  document.body.scrollLeft) -
		  document.documentElement.clientLeft;
	   cursor.y = e.clientY +
		  (document.documentElement.scrollTop ||
		  document.body.scrollTop) -
		  document.documentElement.clientTop;
    }

    return cursor;

}
	
function initTooltips(){
	var oDiv = new Array();	
	var links = document.getElementsByTagName('a');
	for(i = 0; i <= links.length-1; i++){
		if(links[i].getAttribute("description")){
			if(!links[i].getAttribute("href")){
				links[i].className = "tooltip";
			}
			links[i].onmouseover = function(event){
				oDiv[i] = document.createElement("DIV");
				oDiv[i].className = "tooltip";
				oDiv[i].id = "tooltip-"+i;
				oDiv[i].style.top = getPosition(event).y+5+"px";
				oDiv[i].style.left = getPosition(event).x+5+"px";
				oDiv[i].innerHTML = (this.getAttribute("name")) ? "<span class=\"name\">"+this.getAttribute("name")+"</span><span class=\"description\">"+this.getAttribute("description")+"</span>" : "<span class=\"description\">"+this.getAttribute("description")+"</span>" ;
				document.body.appendChild(oDiv[i]);
			}
			links[i].onmouseout = function(){
				document.body.removeChild(document.getElementById("tooltip-"+i));
			}
			links[i].onmousemove = function(event){
			
				var windowHeight = window.innerHeight || document.body.clientHeight;
				var windowWidth = window.innerWidth || document.body.clientWidth;
				var scrollTop = window.pageYOffset || document.body.scrollTop;
				var scrollLeft = window.pageXOffset || document.body.scrollLeft;
				
				if(document.getElementById("tooltip-"+i)){
				
					if(getPosition(event).y+5+document.getElementById("tooltip-"+i).clientHeight > windowHeight+scrollTop){
						oDiv[i].style.top = (getPosition(event).y-document.getElementById("tooltip-"+i).clientHeight-5)+"px";
					} else {
						oDiv[i].style.top = (getPosition(event).y+5)+"px";
					}
					
					if(getPosition(event).x+5+document.getElementById("tooltip-"+i).clientWidth > windowWidth+scrollLeft){
						oDiv[i].style.left = (getPosition(event).x-document.getElementById("tooltip-"+i).clientWidth-5)+"px";
					} else {
						oDiv[i].style.left = (getPosition(event).x+5)+"px";
					}
					
				}
			}
		}
	}
	
}

function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

addEvent(window, 'load', initTooltips);
