replace this code:
jQuery(this).attr('src', src.substr(0, src.length-3) + 'jpg');
with:
var $el = jQuery(this);
//save the original source in a variable
var src = $el.attr('src');
//replace the current source with a loading gif (i.e. http://preloaders.net/)
jQuery(this).attr('src', '/path/to/loading.gif');
//start loading the original image
var img = new Image();
//once the original image is loaded then replace the loading gif
img.onload = function () {
$el.attr('src', src);
}
img.src = src;