// JavaScript Document
$(document).ready(function(){
	$('img.insertBlurb').each(function() {
		//check title exists
		if($(this).attr("alt")) {
			
			$title = $(this).attr("alt");
			
			//grab image width
			$width = $(this).css("width");
			
			//grab margin
			$margin_left = $(this).css("margin-left");
			$margin_right = $(this).css("margin-right");
			$margin_top = $(this).css("margin-top");
			$margin_bottom = $(this).css("margin-bottom");
			
			//unset margin
			$(this).css("margin","0");
			
			//grab float
			$float = $(this).css("float");
			
			//unset float
			$(this).css("float","none");
			
			//wrap in a div
			$(this).wrap("<div class=\"img_wrap\"></div>");
			
			//assign width, float and margins
			$(this).parent("div").css({
									  'float': $float, 
									  'width': $width, 
									  'margin-left': $margin_left, 
									  'margin-right': $margin_right, 
									  'margin-top': $margin_top, 
									  'margin-bottom': $margin_bottom, 
									  'padding':0
									  });
			
			//append title in <p class=blurb>
			$(this).parent("div").append("<p class=\"blurb\">"+ $title +"</p>");
			
		};
   });
});
