/*
Based On: SweetTitles By Dustin Diaz | http://www.dustindiaz.com
Updated: jgalley
*/
var APPC_SweetTitles = { 
	xCord : 0,		// @Number: x pixel value of current cursor position
	yCord : 0,		// @Number: y pixel value of current cursor position
	obj : Object,	// @Element: That of which you're hovering over
	tip : Object,	// @Element: The actual toolTip itself

	init : function() {
		if (!document.getElementById || !document.createElement || !document.getElementsByTagName)
		{
            return;
		}

		this.tip = document.createElement('div');
		this.tip.id = 'GlossaryPopUp';
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		
		var myDefinitions = document.getElementsByTagName('dfn');
		for (var i = myDefinitions.length-1; i>=0; i-- ) {
		    addEvent(myDefinitions[i], 'click', this.click);
		    addEvent(myDefinitions[i], 'mouseover', this.tipOver);
		    addEvent(myDefinitions[i], 'mouseout', this.tipOut);
		    myDefinitions[i].setAttribute('tip', myDefinitions[i].title);
		    myDefinitions[i].removeAttribute('title');
		}

	},
	
	click : function() {
	    
	           if(document.all){
	             document.location= "Glossary.aspx?STerm=" + APPC_SweetTitles.obj.innerText;
	            } else{
	             document.location= "Glossary.aspx?STerm=" + APPC_SweetTitles.obj.textContent;
        }
	},

	tipOver : function(e) {
		APPC_SweetTitles.obj = this;
		tID = window.setTimeout("APPC_SweetTitles.tipShow()",500);
		APPC_SweetTitles.updateXY(e);
	},

	tipShow : function() {		
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);

		this.tip.innerHTML = "<p>" + this.obj.getAttribute('tip') + "</p>";

		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}

		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}

		this.tip.style.visibility = 'visible';
		this.tip.style.opacity = '.1';
		this.tipFade(10);
	},

	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 90 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("APPC_SweetTitles.tipFade('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '.90';
			this.tip.style.filter = "alpha(opacity:90)";
		}
	},

	tipOut: function() {
		if ( window.tID ) { clearTimeout(tID); }
		if ( window.opacityID ) { clearTimeout(opacityID); }
		APPC_SweetTitles.tip.style.visibility = 'hidden';
	},

	updateXY : function(e) {
		if ( document.captureEvents ) {
			APPC_SweetTitles.xCord = e.pageX;
			APPC_SweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			APPC_SweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			APPC_SweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	}
};

function pageLoader() {
	APPC_SweetTitles.init();
}

addEvent(window, 'load', pageLoader);