jQuery(document).ready(function() {  
  
  //Find all images in the body and run a function on each of them
  jQuery('img.altcaption').each(function(i) {
    
    //Grab the alt attribute from the current image.
    var txt = jQuery(this).attr('alt'); 
    
    //Grab the width of the image. I subtract 12 here because my caption style has 5px padding + 1px border on each side.
    var img_width = jQuery(this).width();
		
		//Grab the image alignment
		var image_float = jQuery(this).css('float');
    
    //Pop a tag with class caption after the current img tag
    if(txt) {
      jQuery(this).after("<div class='altcaption' style='float:"+image_float+";clear:both;width:"+img_width+"px;'><div>"+txt+"</div></div>");
    }
    
  });
});

