$(document).ready(function(){
    $("img.hover, div.hover").each(function() {
        var bg  = this.tagName == 'IMG' ? 0 : 1;
        var img = bg ? $(this).css('background-image') : this.src;

        // remove url() from the image if we get it from css
        if ( bg ){
            img.match(/url\("?(.*?)"?\)$/);
            img = RegExp.$1;
        }

        // remove domain part of the image
        img.match(/^https?:\/\/.*?(\/.*)$/)
        img = RegExp.$1;


        // preload images
        img.match(/^(.*)\.(\w+)$/);
        this._over     = new Image();
        this._over.src = RegExp.$1 + "_h." + RegExp.$2;

        this._out      = new Image();
        this._out.src  = img;

        if ( bg ){
            $(this).mouseover(function(){ $(this).css('background-image', "url(" + this._over.src  + ")")  })
            $(this).mouseout( function(){ $(this).css('background-image', "url(" + this._out.src   + ")") })
        }else{
            $(this).mouseover(function(){ this.src = this._over.src; })
            $(this).mouseout( function(){ this.src = this._out.src;  })
        }
    })
})