﻿jQuery.fn.tooltip = function(options) {
    var settings = { param: null }
    if (options) { jQuery.extend(settings, options); }
    return this.each(function() {


        var _originalControl = $(this);
        var _head = "<div class='wid-search-field-l'></div>";
        var _bottom = "<div class='wid-search-field-r'></div>";

        tooltipClass = ".tooltip"; // replace with your class, for multiple classes, separate with comma.
        xOffset = 10;
        yOffset = 20;
        fadeInTime = 150;

        jQuery(tooltipClass).hover(function(e) {
            this.t = this.title; this.title = "";
            this.t = str_replace("::", "<br />", this.t);
            this.t = str_replace("[!]", "<span class='tooltipTitle'>", this.t);
            this.t = str_replace("[/!]", "</span>", this.t);
            this.t = str_replace("[", "<", this.t); this.t = str_replace("]", ">", this.t);

            if (this.t != "") {
                jQuery("body").append("<p id='tooltip'>" + this.t + "</p>");
                jQuery("#tooltip").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px").fadeIn(fadeInTime);
            }
        },
                function() {
                    this.title = this.t;
                    jQuery("#tooltip").remove();
                });

        jQuery(tooltipClass).mousemove(function(e) {
            jQuery("#tooltip").css("top", (e.pageY - xOffset) + "px").css("left", (e.pageX + yOffset) + "px");
        });
        
        function str_replace(search, replace, subject) {
            return subject.split(search).join(replace);
        }
    });
};
