function resize() {resizeFrame(elemento, margin);};
jQuery.event.add(window, "load", resize);
jQuery.event.add(window, "resize", resize);
function resizeFrame(item, marge) {
$(item).each(function() {
var m = marge*2;
var mw = $(window).width()-m;
var mh = $(window).height()-m;
var w = $('img',this).width();
var h = $('img',this).height();
var mr = mh/mw;
var cr = h/w;
$('img',this).css({position:'absolute',minWidth:(w-w)+20,minHeight:(h-h)+20,margin:'auto',top:'0',right:'0',bottom:'0',left:'0',padding:marge});
if(cr < mr){
var r = mw/w;
$('img',this).css({width: mw});
$('img',this).css({height: h*r});
}else if(cr > mr){
var r = mh/h;
$('img',this).css({height: mh});
$('img',this).css({width: w*r});
}
});
}