(function($){
		$.fn.thumbnail = function(options) {
		
		var settings = $.extend({
			classname:null
		}, options);
		
		this.each(
			function(){
				
				var thumbcontainer = $(this).wrap('<div class="'+settings.classname+'"></div>').parent()
				this.className = this.className.replace(settings.classname, 'thmb')
				thumbcontainer.css({'overflow':'hidden','position':'relative'})
				
				
				var imwidth = $(this).width()
				var imheight = $(this).height()
				
				$(this).css({'position':'relative'})
				if (imwidth && imheight){
					if(Math.abs($(this).width()-thumbcontainer.width()) > Math.abs($(this).height()-thumbcontainer.height())){
						$(this).css({'height':'100%'})
						$(this).css({'width':(($(this).height()/imheight))*($(this).width()/thumbcontainer.width())*100+'%'})
						$(this).css({'left':((($(this).width()-thumbcontainer.width())/thumbcontainer.width())/2)*-100+'%'})
					}else{
						$(this).css({'width':'100%'})
						$(this).css({'height':(($(this).width()/imwidth))*($(this).height()/thumbcontainer.height())*100+'%'})
						//$(this).css({'top':((($(this).height()-thumbcontainer.height())/thumbcontainer.height())/2)*-100+'%'})
					}
				}
			}
		)
		return this;
	}
})(jQuery);
