/**
*
*	simpleTooltip jQuery plugin, by Marius ILIE
*	visit http://dev.mariusilie.net for details
*
**/
(function($) {
    $.fn.simpletooltip = function() {
        return this.each(function() {
            var title = $(this).attr("title").split(';');
            var text = title[0];
            var rating;
            if (title[1])
                rating = title[1];
            else
                rating = '0';
            $(this).attr("title", "");
            $(this).closest("table").attr("title", "");
            $(this).find("a").attr("title", "");
            if (text != undefined) {
                $(this).hover(function(e) {
                    var tipX = e.pageX + 12;
                    var tipY = e.pageY + 12;
                    $(this).attr("title", "");
                    $("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'>" + text + "<span class='av-rating'><span style='width:" + rating + ";'>&nbsp;</span></span></div>");
                    if ($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
                    else var tipWidth = $("#simpleTooltip").width()
                    $("#simpleTooltip").width(tipWidth);
                    $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
                }, function() {
                    $("#simpleTooltip").remove();
                    $(this).attr("title", title);
                });
                $(this).mousemove(function(e) {
                    var tipX = e.pageX + 12;
                    var tipY = e.pageY + 12;
                    var tipWidth = $("#simpleTooltip").outerWidth(true);
                    var tipHeight = $("#simpleTooltip").outerHeight(true);
                    if (tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
                    if ($(window).height() + $(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
                    $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
                });
            }
        });
    }
})(jQuery);
