
/* scale image */


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

		var defaults = {
		maxwidth: 200,
		linkclass:'',
		icon:true,
		thickbox:true
		};
		var options = $.extend(defaults, options);

		return this.each(function() {
			obj = $(this);

			var width = obj.width();
			var height = obj.height();
			if (width > options.maxwidth) {
				//Set variables	for manipulation
				var ratio = (height / width );
				var new_width = options.maxwidth;
				var new_height = (new_width * ratio);
				var classes = options.linkclass+' scaleImage';

				//thickbox
				if (options.thickbox == true) {
					var img_full_link = obj.attr('src');
					obj.wrap('<a class="thickbox" title="'+obj.attr('alt')+'" href="'+img_full_link+'"></a>');
					tb_init(obj.parent('a'));
				}
				
				//Shrink the image and add link to full-sized image
				obj.height(new_height).width(new_width);
				obj.addClass(classes);
				
				//zoom icon
				if (options.icon == true) {
					obj.after('<div class="thumb-zoom"> </div>');
					obj.hover(function(){
						$(this).next('.thumb-zoom').addClass("hover");
					},function(){
						$(this).next('.thumb-zoom').removeClass("hover");
					});
				}
			
			}
		});
	};
})(jQuery);



/* kepresize */



(function($){
	
	$.fn.imageresize = 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);
				obj.width = new_width;
				obj.height = new_height;
			} 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);
				obj.width = new_width;
				obj.height = new_height;
			}
		});
		
	};
})(jQuery); 