$(function() {
    // Hide all the non-javascript tooltip spans
    $("a.tooltip").each(function() {
        $(this).parents().each(function() {
            var p = $(this);
            var pos = p.css("position");

            /* If it's positioned, */
            if(pos == "relative" || pos == "absolute" || pos == "fixed") {
            /*
            ** Add the "on-top" class name when the
            ** mouse is hovering over it, and remove
            ** it when the mouse leaves.
            */
                p.hover(function() {
                        $(this).addClass("on-top");
                    },
                    function() {
                        $(this).removeClass("on-top");
                    });
            }
        });

        $(this).hover(function() {
            this.tip = this.title;
            $(this).after(
                '<div style="position:relative"><div class="tooltipwrapper">' + this.tip + '</div></div>'
            );
            this.title = "";
            $(".tooltipwrapper").fadeIn(300);
        },
        function() {
            $(".tooltipwrapper").fadeOut(100).parent().remove();
            this.title = this.tip;
        });
        $(this).click(function() {
            return false;
        });
    });
});

