jQuery(function(){
	/* Javascript for Captions
	 * 
	 * Selects all images with the class 'caption' and appends the alt tag underneath.
	 */
	jQuery("img.caption-left").each(function(){
		var $this = jQuery(this);
		MakeCaption($this, "left");
	});
	
	jQuery("img.caption-right").each(function(){
		var $this = jQuery(this);
		MakeCaption($this, "right");
	});
	
	function MakeCaption(element, side)
	{
		element.wrap('<div class="caption-container"/>'); //wrap with a float container,
		element.wrap('<div class="caption-float '+side+'">'); //and a float div
		element.after(jQuery('<div class="caption-text">').html(element.attr('alt'))); //append the alt tag in a div after the image
		var captionMaxWidth = element.width(); //Caption should not exceed the width of the image
		element.parent().css('max-width', captionMaxWidth); //set the max width
		element.parents('p').css('float',side); //set the float
	}
});
