/**
*
*	simpleTooltip jQuery plugin, by Marius ILIE
*	visit http://dev.mariusilie.net for details
*
**/
(function ($) {
    $.fn.simpletooltip = function () {
        return this.each(function () {
            if ($(this).attr("title") != undefined) {
                $(this).hover(function (e) {
                    var text = $(this).attr("title");
                    var tipX = e.pageX + 12;
                    var tipY = e.pageY + 12;
                    $(this).attr("title", "");
                    $("body").append("<div id='ToolTip' style='position: absolute; z-index: 100; display: none;'>" + text + "</div>");
                    //if($.browser.msie) var tipWidth = $("#ToolTip").outerWidth(true)
                    //else 
                    var tipWidth = $("#ToolTip").width()
                    $("#ToolTip").width(tipWidth + 10);
                    $("#ToolTip").css("left", tipX).css("top", tipY).show();
                }, function () {
                    $(this).attr("title", $("#ToolTip").html());
                    $("#ToolTip").remove();
                });
                $(this).mousemove(function (e) {
                    var tipX = e.pageX + 12;
                    var tipY = e.pageY + 12;
                    var tipWidth = $("#ToolTip").outerWidth(true);
                    var tipHeight = $("#ToolTip").outerHeight(true);
                    if (tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
                    if ($(window).height() + $(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
                    $("#ToolTip").css("left", tipX).css("top", tipY).show();
                });
            }
        });
    }
})(jQuery);
