(function($){$.fn.fix_img_inbox=function(settings){
	settings = $.extend({src:null},settings);
	var oo=settings.src;	
	return this.each(function(){
		var obj=$(this);
		var ww=obj.parent().width()
		var hh=obj.parent().height()
		obj.hide();
		obj.removeAttr("width");
		obj.removeAttr("height");
		if(oo==null){settings.src=obj.attr("src")}else{obj.attr({"src":settings.src});}
		var img=new Image();
		img.src=settings.src;
		var autoset=function(){
			if(img.width>0 && img.height>0){
			cc1=img.width/img.height
			cc2=ww/hh
			if(cc1>=cc2){
				if(img.width>ww){obj.css({height:parseInt(img.height*ww/img.width)+"px",width:ww+"px"});}
				else{obj.css({width:img.width+"px",height:img.height+"px"});}
			}else{
				if(img.height>hh){obj.css({width:parseInt(img.width*hh/img.height)+"px",height:hh+"px"});}
				else{obj.css({width:img.width+"px",height:img.height+"px"});}
			}
			obj.css({margin:parseInt((hh-obj.height())/2)+"px 0px 0px "+parseInt((ww-obj.width())/2)+"px"});
			}
		}
		if(img.complete || img.loaded){autoset(); obj.fadeIn(); return;}
		$(img).load(function(){autoset(); obj.fadeIn(); return;}).error(function(){obj.attr("src",""); obj.fadeIn(); return;});
	});
};})(jQuery);
