 (function(a) {
    var j = '',
    d = false;
    a.fn.extend({
        tooltip: function() {
            d = a('<p id="tooltip"></p>').appendTo(document.body);
            return this.live('mouseenter', function(f) {
                j = a(this).attr('title');
               
                a(this).attr('title', '');
                d.html(j).show();
                k(f);
                a(document.body).bind('mousemove', k);
                a(this).mouseleave(function() {
                    d.hide().empty().css({
                        top: 0,
                        left: 0
                    });
                    a(this).attr('title', j);
                    a(document.body).unbind('mousemove', k);
                    d.unbind()
                    })
                })
            }
    });
    function k(f) {
        var b = {},
        c = 10,
        e = d,
        g = (f.pageX + c),
        h = (f.pageY + c),
        i = {
            l: a(window).scrollLeft(),
            t: a(window).scrollTop(),
            w: a(window).width(),
            h: a(window).height()
            };
        e.css({
            top: h + 'px',
            left: g + 'px'
        });
        b = {
            w: e.width(),
            h: e.height()
            };
        if (i.l + i.w < b.w + g + (c * 2) && g > b.w)
            e.css({
            left: (g - b.w - (c * 3)) + 'px'
        });
        if (i.t + i.h < b.h + h + (c * 3) && h > b.h)
            e.css({
            top: (h - b.h - (c * 2)) + 'px'
        })
        }
})(jQuery);
$(document).ready( function(){
    $('.tooltip').tooltip()
    });
