function BindHover(o) {
    o = $.extend({
        preload: true
    }, o || {});

    $(":hasHover").bindHover(o);

    if (o.preload)
        PreloadImages();
}

jQuery.expr[":"].hasHover = function(e, i, m) {
    return jQuery(e).attr('class') && jQuery(e).attr('class').match(m[3] ? m[3] : "Hover_");
};

(function($) {
    $.fn.bindHover = function(o) {
        o = $.extend({
            hoverMarker: "Hover_",
            hoverDelay: 0,
            preload: true,
            preloadMarker: "Preload"
        }, o || {});

        return this.each(function() {

            var el = $(this);

            if (el.attr('class')) {

                $.each(el.attr("class").split(' '), function(i, c) {

                    if (c.match(o.hoverMarker + '$') == o.hoverMarker) {

                        var hoverClass = c.slice(0, -1) + (o.preload ? o.preloadMarker : "");

                        el.removeClass(c);

                        if (jQuery().hoverIntent && o.hoverDelay) {
                            var config = {
                                over: function(event) { $(this).addClass(hoverClass); },
                                timeout: o.hoverDelay,
                                out: function(event) { $(this).removeClass(hoverClass); }
                            };
                            el.hoverIntent(config)
                        }
                        else {
                            el.hover(function() {
                                el.addClass(hoverClass);
                            }, function() {
                                el.removeClass(hoverClass);
                            });
                        }
                        return false;
                    }
                });
            }
        });
    }

})(jQuery);

function PreloadImages(o) {

    o = $.extend({
        preloadMarker: "Preload"
    }, o || {});

    var allImgs = [];
    var preloadMarker = eval("/" + o.preloadMarker + "$/i");
    
    for (var i = 0; i < document.styleSheets.length; i++) {
        var styles = '';
        var csshref = (document.styleSheets[i].href) ? document.styleSheets[i].href : 'window.location.href';
        var baseURLarr = csshref.split('/');
        baseURLarr.pop();
        var baseURL = baseURLarr.join('/');
        if (baseURL != "")
            baseURL += '/';

        $.each(document.styleSheets[i].cssRules || document.styleSheets[i].rules, function() {
            if (preloadMarker.test(this.selectorText))
                styles += this.style.cssText;
        });

        var imgUrls = styles.match(/[^\(]+\.(gif|jpg|jpeg|png)/g);
        if (imgUrls != null && imgUrls.length > 0 && imgUrls != '') {

            $.each(jQuery.makeArray(imgUrls), function(i) {
                var url = this.replace('"', '').replace("'", "");
                allImgs[i] = new Image();
                allImgs[i].src = (url[0] == '/' || url.match('http://') || url.match('https://')) ? url : baseURL + url;
            });
        }
    }

    return allImgs;
};

$.expr[":"].containsNoCase = function(el, i, m) {

    var search = m[3];

    if (!search) return false;

    return eval("/" + search + "/i").test($(el).text());

};
//$("tr:containsNoCase(jquery)").addClass("highlight");

String.prototype.endsWith = function(str) {
    return (this.match(str + '$') == str)
}
jQuery.expr[":"].asp = function(e, i, m) {

    return jQuery(e).attr('id') && jQuery(e).attr('id').endsWith(m[3]);
};

//Example usage $(":asp('UserLabel')").addClass('highlight');


