(function($) {
	$.fn.caption = function() {

		return this.each(function() {
			
			var $img = $(this), $first = $('<div></div>'), $second = $('<div></div>');

			if($img.attr('alt').length > 0) {

				$second.attr('style', $img.attr('style'));
				$img.removeAttr('style');

				$second.attr('class', $img.attr('class')).addClass('caption');
				$img.removeAttr('class');

				//$second.width($img.width());
				$first.width($img.width());

				$img.wrap($second).wrap($first);

				$img.parent().append('<p>' + $img.attr('alt') + '</p>');

			}

		});
	}

})(jQuery);

