// MODIFIED

/* CROSS-BROWSER EVENT HANDLER */
function addEvent(obj, evType, fn){
	 if (obj.addEventListener){
		 obj.addEventListener(evType, fn, true);
		 return true;
	 } else if (obj.attachEvent){
		 var r = obj.attachEvent("on"+evType, fn);
		return r;
	 } else {
		return false;
	 }
}
/* END EVENT HANDLER */


//////////////////////////////////////////////////////////////////
// qTip - CSS Tool Tips - by Craig Erskine
// http://qrayg.com | http://solardreamstudios.com
//
// Inspired by code from Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
//////////////////////////////////////////////////////////////////



var qTipTag = new Array("a", "img", "input", "div", "span"); //Which tag do you want to qTip-ize? Keep it lowercase!// edited by Luuk Peters, making it Array compatible
var qTipX = -30; //This is qTip's X offset//
var qTipY = 25; //This is qTip's Y offset//



//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null,
  overlap : null,
  windowWidth : 0,
  windowHeight : 0,
  tip_offsetHeight : 0
}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle, offX;
	
	for (var qtti = 0 ; qtti< qTipTag.length ; qtti++) //array compatibility
	{
		var anchors = document.getElementsByTagName (qTipTag[qtti]);

		for (var i = 0; i < anchors.length; i ++) {
			a = anchors[i];
			sTitle = a.getAttribute("title");
			if(sTitle) {
				if(a.hasAttribute && a.hasAttribute("offsetx")) {
					offX = parseInt(a.getAttribute("offsetx"));
					a.removeAttribute("offsetx");
				}
				a.setAttribute("tiptitle", sTitle);
				a.removeAttribute("title");
				if(isNaN(offX)) {
					a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'));};
					a.onmouseout = function() {tooltip.hide();};
				} else {
					a.onmouseover = function() {tooltip.setX(offX);tooltip.show(this.getAttribute('tiptitle'));};
					a.onmouseout = function() {tooltip.resetX();tooltip.hide();};
				}
			}
		}
		this.getwindowsize();
	}

}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}

	var scrOf = this.getscrollxy ();
	var scrOfX = scrOf[0];
	var scrOfY = scrOf[1];

	//this.tip.innerHTML = scrOfY + " + " + this.tip_offsetHeight + " = " + (y+this.tip_offsetHeight) + ">" + this.windowHeight + "," + this.tip.innerHTML;
	if ((y-scrOfY)+20+this.tip_offsetHeight > (this.windowHeight))
	{
		this.tip.style.left = (x + this.offsetX) + "px";
		this.tip.style.top = (y + this.offsetY - (this.tip_offsetHeight + 30)) + "px";
	}
	else 
	{
		this.tip.style.left = (x + this.offsetX) + "px";
		this.tip.style.top = (y + this.offsetY) + "px";
	}

}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
	this.tip_offsetHeight = this.tip.offsetHeight;
//	this.tip.innerHTML = this.tip.offsetHeight+"<br/>"+text;

/*if (document.all)	// it is IE
	{
		this.overlap = new Array ();
		this.hidecontrol("SELECT");
		this.hidecontrol("IFRAME");
		this.hidecontrol("OBJECT");
	}
*/
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
	this.showcontrol();
}

tooltip.setX = function (x) {
	this.offsetX = x;
}

tooltip.resetX = function () {
	this.offsetX = qTipX;
}

//
// functions that obtain the coordinates of an HTML element
//
tooltip.getX = function ()
{
	var x = 0;
	var obj = this.tip;

	do
	{
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	while (obj);
	return x;
}

tooltip.getY = function ()
{
	var y = 0;
	var obj = this.tip;

	do
	{
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	while (obj);
	return y;
}

tooltip.hidecontrol = function (tagName)
{
	var x = this.getX ();
	var y = this.getY ();
	var w = this.tip.offsetWidth;
	var h = this.tip.offsetHeight;

	var i;
	for (i = 0; i < document.all.tags(tagName).length; ++i)
	{
		var obj = document.all.tags(tagName)[i];
		if (!obj || !obj.offsetParent)
			continue;

		// check if the object and the subMenu overlap

		var ox = cmGetX (obj);
		var oy = cmGetY (obj);
		var ow = obj.offsetWidth;
		var oh = obj.offsetHeight;

		if (ox > (x + w) || (ox + ow) < x)
			continue;
		if (oy > (y + h) || (oy + oh) < y)
			continue;
		//subMenu.cmOverlap.push (obj);
		this.overlap[this.overlap.length] = obj;
		obj.style.visibility = "hidden";
	}
}

//
// show the control hidden by qtip
//
tooltip.showcontrol = function ()
{
	if (this.overlap)
	{
		var i;
		for (i = 0; i < this.overlap.length; ++i)
			this.overlap[i].style.visibility = "";
	}
	this.overlap = null;
}

tooltip.getwindowsize = function () {

	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		this.windowWidth = window.innerWidth;
		this.windowHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		this.windowWidth = document.documentElement.clientWidth;
		this.windowHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		this.windowWidth = document.body.clientWidth;
		this.windowHeight = document.body.clientHeight;
	}

}

tooltip.getscrollxy = function () {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

addEvent(window , 'load', function () {
	tooltip.init ();
});