//////////////////////////////////////////////////////////////////
// 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 qTipTags = new Array("a", "div");
var qTipTag = "a"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX = -30; //This is qTip's X offset//
var qTipY = 25; //This is qTip's Y offset//


var offsetfromcursorX=-7; //Customize x offset of tooltip
var offsetfromcursorY=23; //Customize y offset of tooltip

var offsetdivfrompointerX=13; //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=13; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}
var ie=document.all;
var ns6=document.getElementById && !document.all;

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;

    var anchors = new Array();
    for (var i=0; i<qTipTags.length; i++)
    {
        tmpAnchors = document.getElementsByTagName (qTipTags[i]);
        for (var j=0; j<tmpAnchors.length; j++)
        {
            anchors[anchors.length] = tmpAnchors[j];
        }
    }

    //var anchors = document.getElementsByTagName (qTipTag);

    for (var i = 0; i < anchors.length; i ++) {
        a = anchors[i];
        sTitle = a.getAttribute("title");
        sClass = a.getAttribute("class");
        if(sTitle && (sClass != "gbox" && sClass != "gtip") ) {
            a.setAttribute("tiptitle", sTitle);
            a.removeAttribute("title");
            a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
            a.onmouseout = function() {tooltip.hide()};
        }
    }
}

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 nondefaultpos=false;
    var curX=(ns6)?evt.pageX : event.clientX+ietruebody().scrollLeft;
    var curY=(ns6)?evt.pageY : event.clientY+ietruebody().scrollTop;
    //Find out how close the mouse is to the corner of the window
    var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
    var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20;

    var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-evt.clientX-offsetfromcursorX;
    var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-evt.clientY-offsetfromcursorY;

    var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;

    //if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<this.tip.offsetWidth){
        //move the horizontal position of the menu to the left by it's width
        this.tip.style.left=curX-this.tip.offsetWidth+"px";
        nondefaultpos=true;
    }
    else if (curX<leftedge){
        this.tip.style.left="5px";
    }
    else{
        //position the horizontal position of the menu where the mouse is positioned
        this.tip.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px";
        //pointerobj.style.left=curX+offsetfromcursorX+"px";
    }

    //same concept with the vertical position
    if (bottomedge<this.tip.offsetHeight){
        this.tip.style.top=curY-this.tip.offsetHeight-offsetfromcursorY+"px";
        nondefaultpos=true;
    }
    else{
        this.tip.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px";
        //pointerobj.style.top=curY+offsetfromcursorY+"px";
    }
    //this.tip.style.visibility="visible";

//     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.style.zindex = "200000";
    if ( text.length > 75 )
        this.tip.style.width = "200px";
    else
        this.tip.style.width = "";
}

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

/*
window.onload = function () {
    tooltip.init ();
}
*/

