(function($) {
	$.fn.ngImageResize = function(options) {
		var params = jQuery.extend({
			height: 9,
			width: 9
		}, options);

		this.each(function() {
			var height = params.height,
				width = params.width,
				img_height = $(this).height(),
				img_width = $(this).width(),
				m_ceil = Math.ceil,
				m_floor = Math.floor;

			height_ratio = img_height /  height;
			width_ratio = img_width /  width;

			if (height_ratio > width_ratio) {
				ratio = height_ratio;
			} else {
				ratio = width_ratio;
			}

			height = m_floor(m_ceil(img_height / ratio));
			width = m_floor(m_ceil(img_width / ratio));

			$(this).attr({
				'height': height,
				'width': width
			});
		});
	};
})(jQuery);

