var toolTipLib = { 
    // Local copies of the current mouse position coordinates:
    xCord : 0,
    yCord : 0,
    // ??
    obj : null,
    // tipElements contains the tags, for which the mouse events should be changed:
    tipElements : ['a', 'abbr'],
    
    attachToolTipBehavior: function() {
        // Detect clients browser. DOM is set, if a capable browers is beeing used,
        // I is set if IE is beeing used:
        var DOM = (document.getElementById)?1:0;
        var I = document.all;
        // The js is activated only if DOM is set:
        if (DOM && !I) {
            if (!document.getElementById ||
                !document.createElement ||
                !document.getElementsByTagName) {
                return;
            }
            var i,j;
            addEvent(document,'mousemove',toolTipLib.updateXY,false);
            if ( document.captureEvents ) {
                    document.captureEvents(Event.MOUSEMOVE);
            }
            for ( i=0;i<toolTipLib.tipElements.length;i++ ) {
                var current = document.getElementsByTagName(toolTipLib.tipElements[i]);
                for ( j=0;j<current.length;j++ ) {
                    addEvent(current[j],'mouseover',toolTipLib.tipOver,false);
                    addEvent(current[j],'mouseout',toolTipLib.tipOut,false);
                    // Define an attribte called 'tip' an give it the value of the title:
                    current[j].setAttribute('tip',current[j].title);
                    // Remove the title attribute to make the js runnable:
                    current[j].removeAttribute('title');
                }
            }
        }
    },
    
    updateXY : function(e) {
        /* This function updates the local copy of the x- and y-coordinate
           of the upper left corner of the mouse pointer when the mouse
           is beeing moved */
        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) {
        // This funcion checks, if obj is one of the html-tag-types, definded in tipElements
        var trueObj = obj;
        /* The following if-statement must compare the nodeName with all type-names contained
           in tbe array tipElements: */
        if (trueObj.nodeName.toLowerCase() == 'a' || 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');
        // Get coordinates of the upper left corner of the mouse pointer:
        var scrX = Number(toolTipLib.xCord);
        var scrY = Number(toolTipLib.yCord);
        // Set coordinates of the upper left corner of the displayed box:
        var tp = parseInt(scrY-3);
        var lt = parseInt(scrX+15);
        // Get the current html-tag (node):
        var anch = toolTipLib.checkNode(toolTipLib.obj);
        // If 'anch' is a link-tag without a title, set the skip flag, which leads to no execution of the display:
        if ((anch.nodeName.toLowerCase() == 'a') && (anch.getAttribute('tip') == '')) {
            var skip = true;
        } else {
            var skip = false;
        }
        if (!skip) {
            // Create new div-element:
            newDiv.id = 'toolTip';
            document.getElementsByTagName('body')[0].appendChild(newDiv);
            newDiv.style.opacity = '.1';
            // Set the text appearing in the box:
            newDiv.innerHTML = "<p>"+anch.getAttribute('tip')+"</p>";
            // Place the text in the box:
            if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(newDiv.offsetWidth+lt) ) {
                newDiv.style.left = parseInt(lt-(newDiv.offsetWidth+10))+'px';
            } else {
                newDiv.style.left = lt+'px';
            }
            if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(newDiv.offsetHeight+tp) ) {
                newDiv.style.top = parseInt(tp-(newDiv.offsetHeight+10))+'px';
            } else {
                newDiv.style.top = tp+'px';
            }
            toolTipLib.tipFade('toolTip',10);
        } // end if
    },
    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 = '.8';
            obj.style.filter = "alpha(opacity:80)";
        }
    }
};
addEvent(window,'load',toolTipLib.attachToolTipBehavior,false);
