﻿$(document).ready(function() {
    $('img.ro').RollOver()
});
(function($) {
    $.RollOver = { version: '1.0.0' };
    $.fn.RollOver = function(settings) {
        settings = jQuery.extend({
            ImgExtention: '_o',
            callback: function() { }
        }, settings);
        $(this).each(function() {
            var _self = this;
            //preload image
            $(window).bind('load', function() {
                $(document.createElement('img')).attr('src', newimage($(_self).attr('src')));
            });
            //bind hover effect
            $(_self).hover(
                function() { $(_self).attr('src', newimage($(_self).attr('src'))); },
                function() { $(_self).attr('src', oldimage($(_self).attr('src'))); }
            );
        });
        function newimage(src) {
            var extMatch = /^.+\.([^.]+)$/.exec(src);
            var ext
            if (extMatch == null) { ext = ''; }
            else { ext = extMatch[1]; };
            var res = '';
            if (src.indexOf(settings.ImgExtention + '.' + ext) == -1) {
                res = src.replace('.' + ext, settings.ImgExtention + '.' + ext);
            }
            else {
                res = src;
            };
            return res
        };
        function oldimage(src) {
            return src.replace(settings.ImgExtention + '.', '.');
        };
    };
})(jQuery);