$(function (){
//$(document).ready(function(){
  $(".newsContent img").each(function(i) {
    
		
		var captiontext = $(this).attr('alt');
    
		//get the css float value from the image
		var align = $(this).css('float');
		
		//overwrite the flaot on the image itself
		$(this).css('float', 'none');
		
		// we can then apply a margin to the appropriate side also
		
		var margin = "";
		
		if (align == 'right'){
			margin = 'margin-left: 30px;';
		} else {
			margin = 'margin-right: 30px;';
		}
		
		
		if(captiontext){
			$(this).wrap("<div class=\"imageContainer\" style=\"float: " + align + "; " + margin + "\"></div>");
			$(this).parent().append("<div class=\"caption\">" + captiontext + "</div>");
  }
	
	});
});