/**
 * scaleImage 0.1
 * 
 * Rendez vos sites glissant !
 *
 * Copyright (c) 2008 Benoit G (http://www.tim-burton.net) based upon
 * Licensed under the Creative Commons License:
 * http://creativecommons.org/licenses/by/3.0/
 *
 * Date: 2008-08-25
 */
 
	(function($){
		$.fn.scaleImage = function(options) {

			
 
			var defaults = {
			maxwidth: 200,
			linkclass:'',
			icon:true,
			thickbox:true
			};
			if (options.maxwidth != null) defaults.maxwidth = options.maxwidth;
			if (options.thickbox != null) defaults.thickbox = options.thickbox;
			
			
			
			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="zoomImage" 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="zoomImagethumb-zoomOut"> </div>');
						obj.hover(function(){
							$(this).next('.zoomImagethumb-zoomOut').addClass("zoomImagethumb-zoomOver");
						},function(){
							$(this).next('.zoomImagethumb-zoomOut').removeClass("zoomImagethumb-zoomOver");
						});
					}
 
				}
			});
		};
	})(jQuery);