﻿(function($) {

    $.fn.toolTip = function() {

        $(this).mouseover(function(e) {

            //usage: $(".infotip").toolTip();

            $('.tt').hide();
            $("body").remove('.tt');

            var html = "<div id='toolTip' class='tt'><div id='tooltop'></div><div id='tooltext'></div><div id='toolbottom'></div></div>";
            $("body").prepend(html);

            //set this first so rest of script can figure out correct div height 
            if ($(this).attr("tip") == null) {
                //$("#tooltext").text($(this).attr("title"));
                $(this).attr("tip", $(this).attr("title"));
                $(this).attr("title", '');
            }
            else {

            }

            $("#tooltext").text($(this).attr("tip"));

            var height = $("#toolTip").height();
            var topOffset = e.pageY - (height + 10);
            var leftOffset = e.pageX;

            if (topOffset < 1) {
                topOffset = 10;
            }

            if (leftOffset < 1) {
                leftOffset = 10;
            }

            if ($(this).attr("leftOffset") != null) {
                leftOffset = leftOffset - $(this).attr("leftOffset");
            }

            //topOffset = 30;
            //leftOffset = 0;
            
            topVal = (topOffset) + "px";
            leftVal = (leftOffset) + "px";
            //alert(topVal);
            //alert(leftVal);

            $('#toolTip').css({ left: leftVal, top: topVal });

            $("#toolTip").show();

            $("#tooltext").click(function() {
                $('#toolTip').fadeOut('slow');
            });

            $(this).mouseleave(function() {
                var t = setTimeout(" $('#toolTip').fadeOut('slow'); ", 1800);
                //$('#toolTip').fadeOut("slow");                            
            });

        });

    }

})(jQuery);




