/* js for image handling looks for img tags with caption class, 
gets the img width, wraps a div around the image and sets the div width to the image width, 
grabs the next paragraph and moves that inside the div */ 
	$(window).bind("load", function(){
		$("img.caption").each(function(){
			var caption = null;
			var imgWidth = this["width"];
			//	var reqWidth = imgWidth + 10;
			var reqWidth = imgWidth;
			var addClass = '';

			if ($(this).hasClass('left')) {
				addClass = ' left';
			} else if ($(this).hasClass('right')) {
				addClass = ' right';
			} else if ($(this).hasClass('center')) {
				addClass = ' center';
			}

			if ($(this).next().is('p')) {
				caption = $(this).next();
				$(this).wrap("<div class='figure" + addClass + "' style='width:"+reqWidth+"px;'></div>");
				var captionText = caption.html();
				$(this).after("<p>"+captionText+"</p>");
				$(caption).remove();
			} else if ($(this).parent().is('p')) {
				caption = $(this).parent().next();
				$(this).parent().wrap("<div class='figure" + addClass + "' style='width:"+reqWidth+"px;'></div>");
				if ($(caption).is("p")) {
					var captionText = caption.html();
					$(this).parent().after("<p>"+captionText+"</p>");
					$(caption).remove();
				}
			}
		});
	});
