var toolTipLib = {
    xCord : 0,
    yCord : 0,
    obj : null,
    attachToolTipBehavior: function() {
        if ( !document.getElementById ||
            !document.createElement ||
            !document.getElementsByTagName ) {
            return;
        }

        // tonitone: array for the elements
        var docElements = new Array('a', 'acronym', 'abbr');
        var i;
        addEvent(document,'mousemove',toolTipLib.updateXY,false);
        if ( document.captureEvents ) {
                document.captureEvents(Event.MOUSEMOVE);
        }
        var emtDiv = document.createElement('div');
        document.getElementsByTagName('body')[0].appendChild(emtDiv);
        emtDiv.style.position = 'absolute';

        // tonitone: walk through the array
        for ( var h=0; h <= docElements.length; h++) {
            docElement = document.getElementsByTagName(docElements[h]);
            for ( i=0;i<docElement.length;i++ ) {
                 // tonitone: check if title is set
                if (docElement[i].getAttribute('title') != null && docElement[i].getAttribute('title') != '') {
                    addEvent(docElement[i],'mouseover',toolTipLib.tipOver,false);
                    addEvent(docElement[i],'mouseout',toolTipLib.tipOut,false);
                    docElement[i].setAttribute('tip',docElement[i].title);
                    docElement[i].removeAttribute('title');
                }
            }
        }

    },
    updateXY : function(e) {
        if ( document.captureEvents ) {
            toolTipLib.xCord = e.pageX;
            toolTipLib.yCord = e.pageY;
        } else if ( window.event.clientX ) {
            toolTipLib.xCord = window.event.clientX+document.documentElement.scrollLeft;
            toolTipLib.yCord = window.event.clientY+document.documentElement.scrollTop;
        }
    },
    tipOut: function(e) {
        if ( window.tID ) {
            clearTimeout(tID);
        }
        if ( window.opacityID ) {
            clearTimeout(opacityID);
        }
        var l = getEventSrc(e);
        var div = document.getElementById('toolTip');
        if ( div ) {
            div.parentNode.removeChild(div);
        }
    },
    checkNode : function(obj) {
        var trueObj = obj;
        if ( trueObj.nodeName.toLowerCase() == 'a' || trueObj.nodeName.toLowerCase() == 'acronym' || trueObj.nodeName.toLowerCase() == 'abbr' ) {
            return trueObj;
        } else {
            return trueObj.parentNode;
        }
    },
    tipOver : function(e) {
        toolTipLib.obj = getEventSrc(e);
        tID = setTimeout("toolTipLib.tipShow()",500)
    },
    tipShow : function() {
        var newDiv = document.createElement('div');
        var scrX = Number(toolTipLib.xCord);
        var scrY = Number(toolTipLib.yCord);
        var tp = parseInt(scrY+15);
        var lt = parseInt(scrX+10);
        var anch = toolTipLib.checkNode(toolTipLib.obj);
        var addy = '';
        var access = '';
        if ( anch.nodeName.toLowerCase() == 'a' ) {
            addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
            var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
        } else {
            addy = anch.firstChild.nodeValue;
        }
        newDiv.id = 'toolTip';
        document.getElementsByTagName('body')[0].appendChild(newDiv);
        newDiv.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+"</em></p>";
        if ( document.documentElement.clientWidth < parseInt(newDiv.offsetWidth+lt) ) {
            newDiv.style.right = '20px';
        } else {
            newDiv.style.left = lt+'px';
        }
        if ( document.documentElement.clientHeight < parseInt(newDiv.offsetHeight+tp) ) {
            newDiv.style.top = parseInt(tp-(newDiv.offsetHeight+10))+'px';
        } else {
            newDiv.style.top = tp+'px';
        }
        newDiv.style.opacity = '.1';
        toolTipLib.tipFade('toolTip',10);
    },
    tipFade: function(div,opac) {
        var obj = document.getElementById(div);
        var passed = parseInt(opac);
        var newOpac = parseInt(passed+10);
        if ( newOpac < 80 ) {
            obj.style.opacity = '.'+newOpac;
            obj.style.filter = "alpha(opacity:"+newOpac+")";
            opacityID = setTimeout("toolTipLib.tipFade('toolTip','"+newOpac+"')",20);
        }
        else {
            obj.style.opacity = '.80';
            obj.style.filter = "alpha(opacity:80)";
        }
    }
};
addEvent(window,'load',toolTipLib.attachToolTipBehavior,false);

