(function($){
	
	$.extend({
			 
		smoothAnchors : function(speed){
				
			speed = speed || "fast";
			
			$("a").each(function(i){
							
				var url = $(this).attr("href");
				
				if(url){
					if(url.indexOf("#") != -1 && url.indexOf("#") == 0){
		
						var aParts = url.split("#",2);
						var anchor = $("a[name='"+aParts[1]+"']");
						
						if(anchor){
																					
							$(this).click(function(){
												   
								if($(document).height()-anchor.offset().top >= $(window).height() || anchor.offset().top > $(window).height()){
												   
									$('html, body').animate({
										scrollTop: anchor.offset().top
									}, speed, null, function(){
										window.location = url;
									});
								
								}
								
								return false;
																
							});
						}
					
					}
					
				}
				
			});
			
		}
	
	});
	
})(jQuery);
