// by Anatoly Rr


(function($) {
	$.fn.shrink = function(options) {
		var defaults = {
			maxWidth: 200,
			maxHeight: 200
		};
		var opts = $.extend(defaults, options);
		
		toggleImg = function (obj)
		{
			if (opts.maxWidth >= obj.width)
			{
				obj.width = obj.originalWidth;
				obj.height = obj.originalHeight;				
				return false;
			}			
			
			w = opts.maxWidth  / obj.originalWidth;
			h = opts.maxHeight / obj.originalHeight;
			k = (w > h) ? h : w;
			
			obj.width = obj.originalWidth * k;
			obj.height = obj.originalHeight * k;
			return false;
		}
		
		
		this.each(function(){
			// console.log (this);
			if ((this.width > opts.maxWidth) || (this.height > opts.maxHeight))
			{
				this.originalWidth = this.width;
				this.originalHeight = this.height;
				toggleImg (this);
				this.style.cursor = 'url(/img/magnify.cur), -moz-zoom-in';
				// $(this).click(function() {toggleImg(this);});				
			}
		});		

	};	
})(jQuery);
