(function($) {
	// Resizes an img inside of the container this plugin is called on
	// with the resizing of the window.
	$.fn.resizeWithWindow = function(originalWidth, originalHeight) {

		return this.each(function() {
			var img = $(this);
			var container = img.parent();
			var win = $(window);

			var imgOriginalWidth = originalWidth;
			var imgOriginalHeight = originalHeight;
			var picWidth = imgOriginalWidth;
			var picHeight = imgOriginalHeight;

			img.css({height: 'auto', width: 'auto'});

			win.resize(function(e) {
				resize_image();
			});
			resize_image();

			function resize_image() {
				var winWidth = win.width();
				var winHeight = win.height();
				var winAspectRatio = winWidth / winHeight;
				var picAspectRatio = picWidth / picHeight;

				if( winAspectRatio > picAspectRatio ) {
					var newWidth = winWidth;
					var newHeight = (winWidth / picWidth) * picHeight;
				} else {
					var newWidth = (winHeight / picHeight) * picWidth;
					var newHeight = winHeight;
				};

				// center the image
				new_top = 0 - ((newHeight - winHeight) / 2);
				new_left = 0 - ((newWidth - winWidth) / 2);

				img.css({height: newHeight, width: newWidth, top: new_top, left: new_left, position: 'absolute'});

				if( jQuery.browser.msie ) {
					container.css({height: winHeight, width: winWidth, overflow: 'hidden'});
				} else {
					container.css({height: '100%', width: '100%', overflow: 'hidden'});
				}
			}
	});
};
})(jQuery);