// c1Tooltip.js
// copylight (c) 2009 GrapeCity inc.

/// <reference path="jquery.js" />
/// <reference path="jquery-vsdoc.js" />

this.tooltip = function(){	
    xOffset = 20;
    yOffset = 20;

    var isWin9X = (navigator.appVersion.toLowerCase().indexOf('windows 98')+1);
    var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0);
    var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera')+1?1:0);
    if (isOpera) isIE = false;
    var isSafari = (navigator.appVersion.toLowerCase().indexOf('safari')+1?1:0);

    function getScrollPosition() {
        var obj = new Object();
        obj.x = document.documentElement.scrollLeft || document.body.scrollLeft;
        obj.y = document.documentElement.scrollTop || document.body.scrollTop;
        return obj;
    }

    function getScreenSize() {
        var obj = new Object();
        if (!isSafari && !isOpera) {
            obj.x = document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth;
            obj.y = document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight;
        } else {
            obj.x = window.innerWidth;
            obj.y = window.innerHeight;
        }
        obj.mx = parseInt((obj.x)/2);
        obj.my = parseInt((obj.y)/2);
        return obj;
    }

    function getLeft(e) {
        var left = (e + xOffset);
	var screenSize = getScreenSize();
	var scrollPos = getScrollPosition();
        if((screenSize .x / 2 + scrollPos.x) < e)
            left = e - $("#TTPanel").width() - xOffset;
        return left;
    }

    function getTop(e) {
        var top =  (e + yOffset);
	var screenSize = getScreenSize();
	var scrollPos = getScrollPosition();
        if((screenSize .y / 2 + scrollPos.y) < e)
            top = e - $("#TTPanel").height() - yOffset;
        return top
    }

    $("span.TT, span.TT2, span.TT3").hover(function(e){											  
        this.t = this.title;
        this.title = "";									  
        $("body").append("<p id='TTPanel'>" + this.t + "</p>");

        $("#TTPanel")
            .css("top", getTop(e.pageY) + "px")
            .css("left", getLeft(e.pageX) + "px")
            .fadeIn("fast", function()
            {
                if (jQuery.browser.msie)
                    this.style.removeAttribute("filter");
                this.style.visibility = 'hidden';
                this.style.visibility = 'visible';
            });
    },
    function(){
        this.title = this.t;		
        $("#TTPanel").remove();
    });	
    
    $("span.TT, span.TT2, span.TT3").mousemove(function(e){
        $("#TTPanel")
            .css("top", getTop(e.pageY) + "px")
            .css("left", getLeft(e.pageX) + "px");
    });	
};