jQuery(document).ready(function(){
    // jQuery doesn't wait for images to load, so the following doesn't work 
    // when no width, height are specified on image tags. Instead we wait for
    // the window to load.
    // http://stackoverflow.com/questions/544993/official-way-to-ask-jquery-wait-for-all-images-to-load-before-executing-something
    $(window).load(function(){
        $('.captioned').each(function(i){
            var image_width = $(this).children().children('img').width();
            $(this).children('.image-caption').css("width", image_width);
        });
    });
    // Remove breaks that are sometimes added surrounding paragraphs in image
    // captions
    jQuery(".image-caption > br").remove();
});