﻿// Add a .img class on your image for no caption, or .caption to make the alt text your caption
// Adding a link around an image replaces the div thats added normally

(function($) {

	$(document).ready(function() {
		$(".caption, .img").each(function() {

			if ($(this).parent().get(0).tagName == "A") {
				$(this).parent().addClass("imgwrap");
			} else {
				$(this).wrap("<div class='imgwrap'></div>");
			}
		});

		$(".caption").each(function() {
			var title = $(this).attr("alt");
			$(this).after("<span>" + title + "</span>");
		});
	});

	$(window).load(function() {
		$(".caption, .img").each(function() {
			var img = $(this);

			// waits for firefox to load images before applying their widths
			// done due to firefox's inability to support inline-block effectively
			var width = img.width();
			img.parent().width(width);

			// easily the wierdest bug I've ever seen in IE7
			// changing the border property after pageload fixes captions not filling their container. wtf.
			img.parent().addClass("imgwrapfix");
		});
	});

})(jQuery);
