/*
 * ----------------------
 * - Képátméretező v0.2 -
 * ----------------------
 *
 * Készítette: Burda Roland - 2009 július 10.
 * E-mail: qkac87@gmail.com
 * SZABADON TERJESZTHETŐ, ÉS FELHASZNÁLHATÓ! CSERÉBE, EZT A SZÖVEGET NE TÁVOLÍTSD EL! KÖSZÖNÖM!
 * 
 * Példa a használathoz:
 * ---------------------
 *
 * $(document).ready(function(){
 *     $('.thumb').kepresize({maxWidth:200, maxHeight:150});
 * });
 *
 * VAGY:
 *
 * $(document).ready(function(){
 *     $('.thumb').kepresize();
 * });
 *
 */

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

		var defaults = {  
			maxWidth : 110,  // Max width for the image
			maxHeight : 115  // Max height for the image
		};

		var options = $.extend(defaults, options); 

		return this.each(function() {
			obj = $(this);
			
			// Nulling widht and height
			var width = 0;
			var height = 0;
			
			// Get image parameters, and calculate scale
			var width = obj.width();    // Current image width
			var height = obj.height();  // Current image height
			var x_scale = width / options.maxWidth;   // X scale
			var y_scale = height / options.maxHeight; // Y scale
			
			if(y_scale > x_scale){
				new_height = Math.ceil(height * (1/y_scale));
				new_width = Math.ceil(width * (1/y_scale));
				obj.css("height", new_height);
				obj.css("width", new_width);
			} else {
				new_height = Math.ceil(height * (1/x_scale));
				new_width = Math.ceil(width * (1/x_scale));
				obj.css("height", new_height);
				obj.css("width", new_width);
			}
		});
		
	};
})(jQuery); 