	(function($) {
		$.fn.proportionateImage = function(options) {

			this.each(function(){

				var max_width = this.width;
				var max_height = this.height;

				var img = this;
				var imageObj = new Image();

				var desired_ratio = max_width / max_height;

				var new_width;
				var new_height;

				imageObj.onload = function() {

					var width = imageObj.width;
					var height = imageObj.height;

					var image_ratio = width / height;

					if (image_ratio > desired_ratio)
					{
						if (width > max_width)
						{
							new_width = max_width;
							new_height = height * max_width / width;
						}
						else
						{
							new_width = width;
							new_height = height;
						}
					}
					else
					{
						if (height > max_height)
						{
							new_height = max_height;
							new_width = width * max_height / height;
						}
						else
						{
							new_width = width;
							new_height = height;
						}
					}

					img.style.width = new_width + "px";
					img.style.height = new_height + "px";
					img.style.visibility = 'visible';

				}

				imageObj.src = this.src;

			});
			return this;
		};
	})(jQuery);

	var proportionate_me_loaded = true;
