(function($){
	
	$.extend({
			 
		smoothAnchors : function(speed, easing, redirect){
				
			speed = speed || "fast";
			easing = easing || null;
			redirect = (redirect === true || redirect == null) ? true : false;
			
			$("a").each(function(i){
				var url = $(this).attr("href");
				
				if(url){
					if(url.indexOf("#") != -1 && url.indexOf("#") == 0){
						var aParts = url.split("#",2);
						if(aParts[1]){
							var anchor = $("[name="+aParts[1]+"]");
						}
						
						if(anchor && anchor.length){
							$(this).click(function(){
								if($(document).height()-anchor.offset().top >= $(window).height()
								 || anchor.offset().top > $(window).height()
								 || $(document).width()-anchor.offset().left >= $(window).width()
								 || anchor.offset().left > $(window).width()){
									$('body').animate({
										scrollTop: anchor.offset().top - 20,
										scrollLeft: anchor.offset().left
									}, speed, easing, function(){
										if(redirect){
											var fx = $('<div><div>').css({position:'absolute',visibility:'hidden',top: anchor.offset().top - 20 + 'px'}).attr( 'name', aParts[1] ).appendTo( document.body );
											anchor.attr( 'name', '' );
											window.location = url;
											fx.remove();
											anchor.attr('name', aParts[1]);
										}
									});
									$('html').animate({
										scrollTop: anchor.offset().top - 20,
										scrollLeft: anchor.offset().left
									}, speed, easing);
								}
								
								return false;
							});
						}
					
					}
					
				}
				
			});
			
		}
	
	});
	
})(jQuery);
