(function($){
	
	$.fn.extend({
		
		smoothScroll: function( animateOptions ) {
			
			var top = 0;
			
			var animateOptions = $.extend({
				duration: 620,
				easing: 'easeInOutExpo'
			}, animateOptions);
			
			this.each(function(){
				$(this).bind('click.somoothScroll', function(){
					var hash = $(this).attr('href');
					if ( hash.match(/^#/) ) {
						var elemTop = $(hash).offset().top;
						var winHeight = $(window).height();
						var bodyHeight = $(document).height();
						if ( elemTop + winHeight > bodyHeight ) {
							var top = bodyHeight - winHeight;
						} else {
							var top = elemTop;
						}
						$('html, body').animate({'scrollTop': top}, animateOptions);
						return false;
					} else {
						return true;
					}
				});
			});
			
			return this;
		}
		
	});
	
})(jQuery);






