
//////////////////////////////////////////////////////////////////
// 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 = "a"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX = 0; //This is qTip's X offset//
var qTipY = 0; //This is qTip's Y offset//

var _isIE6 = !window.XMLHttpRequest;

//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

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.onmouseover = function(evt) { tooltip.hide(evt) };
   
}

function getElementPosition(theElement){

  var posX = 0;
  var posY = 0;

  while (theElement != null) {
    posX += theElement.offsetLeft;
    posY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
   return {x:posX,y: posY};

}
tooltip.move = function(evt) {

/*
    var x = 0, y = 0;
    if (document.all) {//IE
        //x = window.event.srcElement.getBoundingClientRect().left;
        //y = window.event.srcElement.getBoundingClientRect().bottom - 2;
        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 = getElementPosition(evt.target).x;
        //y = getElementPosition(evt.target).y + evt.target.offsetHeight;		
        x = evt.pageX;
        y = evt.pageY;
    }
    //this.tip.style.left = (x + this.offsetX) + "px";
    //this.tip.style.top = (y + this.offsetY) + "px";
*/

    // get the help icon as object:
    var helpIcon = document.all ? evt.srcElement : evt.target;

    // set tootip "top" css attribute:
    // TODO: "20" is a sample value for top offset - fix it!
    var toolTipTop = Sys.UI.DomElement.getBounds(helpIcon).y + 20;
    
    // set tooltip "left" css attribute:
    // TODO: "20" is a sample value for left offset - fix it!
    var toolTipLeft = Sys.UI.DomElement.getBounds(helpIcon).x + 20;
    
    this.tip.style.top = toolTipTop + "px";
    this.tip.style.display = "block";

    if ((toolTipLeft + parseInt(this.tip.clientWidth) + 15) > document.body.clientWidth) {//15=constant for margin right of oToolTip
        this.tip.style.left = (document.body.offsetWidth - parseInt(this.tip.clientWidth) - 15) + "px";
    } else {
        this.tip.style.left = toolTipLeft + "px";
    }

    //    if (_isIE6) {
    //        document.all.qIframe.style.left = oToolTip.style.left;
    //        document.all.qIframe.style.top = oToolTip.style.top;
    //        document.all.qIframe.style.width = oToolTip.offsetWidth;
    //        document.all.qIframe.style.height = oToolTip.offsetHeight;
    //        document.all.qIframe.style.zIndex = "10000"
    //        document.all.qIframe.style.display = "block";
    //    }
}

tooltip.show = function(evt, text) {
    //alert(text);
    if (!this.tip) return;
    if (_isIE6) {
        //document.all.qIframe = text;
    }
    this.move(evt);
    this.tip.innerHTML = text;
    
    this.tip.style.display = "block";
}

tooltip.hide = function(evt) {
//    if (_isIE6) {
//        document.all.qIframe.style.display = "none";
//    }
	if (!this.tip) return;
	var obj = null;
	if (document.all) {//IE
		obj = window.event.srcElement;
	} else {
		obj = evt.target;
	}
	if (typeof(obj) == "object" && obj.tagName != "A" && obj.id != this.tip.id) {
		this.tip.innerHTML = "";
		this.tip.style.display = "none";
	}
}
function qTipOver(event) {
    tooltip.init();
    if (tooltip) {        
        var obj = null;
        if (document.all) {//IE
            obj = window.event.srcElement;
        } else {
            obj = event.target;
        }
        var sTip = obj.getAttribute("title");
        if(sTip) {
            obj.removeAttribute("title");
	        obj.setAttribute("tiptitle", sTip);		        
        }
	    tooltip.show(event, obj.getAttribute('tiptitle'));
	}
}
