$(document).ready(function() {
  
   $('img').each(function(i) {
		iw = $(this).width();
		pw = $(this).parent().width();
		if(iw>pw){
			nw = pw;
			$(this).css('width',nw+'px');
		}
		if(iw>300 && iw<pw){
			nw = pw;
			$(this).css('width',nw+'px');	
		}
  });
});
