﻿var ToolTips = Class.create();

ToolTips.prototype = {
    xCord : 0,								// @Number: x pixel value of current cursor position
	yCord : 0,								// @Number: y pixel value of current cursor position
	tipElements : ['a','abbr','acronym'],	// @Array: Allowable elements that can have the toolTip
	obj : Object,							// @Element: That of which you're hovering over
	tip : Object,							// @Element: The actual toolTip itself
	active : 0,								// @Number: 0: Not Active || 1: Active
	
	initialize: function() 
    {
        if ( !document.getElementById || !document.createElement || !document.getElementsByTagName )
			return;
		
		var i,j;
		
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
			    Event.observe(current[j],'mouseover',this.tipOver);
				Event.observe(current[j],'mouseout',this.tipOut);
				current[j].setAttribute('tip',current[j].title);
				current[j].removeAttribute('title');
			}
		}
    },
    
    updateXY : function(e) {
		if ( document.captureEvents ) {
			myToolTips.xCord = e.pageX;
			myToolTips.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			myToolTips.xCord = window.event.clientX+document.documentElement.scrollLeft;
			myToolTips.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		myToolTips.tip.style.visibility = 'hidden';
	},

	checkNode : function() {
		var trueObj = myToolTips.obj;
		if ( myToolTips.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	
	tipOver : function(e) {
		myToolTips.obj = this;
		tID = window.setTimeout("myToolTips.tipShow()",500);
		myToolTips.updateXY(e);
	},
	
	tipShow : function() {		
		var scrX = Number(myToolTips.xCord);
		var scrY = Number(myToolTips.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = myToolTips.checkNode();
		var addy = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			addy = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
			myToolTips.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>" + addy + "</em></p>";
		} 
		else {
			addy = anch.firstChild.attributes.getNamedItem("tip").nodeValue;
			myToolTips.tip.innerHTML = "<p>Opgelet:<em>"+ addy + "</em></p>";
		}
		
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(myToolTips.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(myToolTips.tip.offsetWidth+10))+'px';
		} else {
			myToolTips.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(myToolTips.tip.offsetHeight+tp) ) {
			myToolTips.tip.style.top = parseInt(tp-(myToolTips.tip.offsetHeight+10))+'px';
		} else {
			myToolTips.tip.style.top = tp+'px';
		}
		myToolTips.tip.style.visibility = 'visible';
		myToolTips.tip.style.opacity = '.1';
		myToolTips.tipFade(10);
	},
	
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			myToolTips.tip.style.opacity = '.'+newOpac;
			myToolTips.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("myToolTips.tipFade('"+newOpac+"')",20);
		}
		else { 
			myToolTips.tip.style.opacity = '.80';
			myToolTips.tip.style.filter = "alpha(opacity:80)";
		}
	}
}
	
function initTooltips() 
{ 
    myToolTips = new ToolTips(); 
}	

Event.observe(window, 'load', initTooltips, false);
