(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");
				var name = $(this).attr("name");
				
				if (name && !url) {
					// this is a target anchor, make it link to the top
					var link_content = $(this).html();
					if (jQuery.trim(link_content) == ""){
						$(this).attr("href", "#top");
						$(this).html("^");
						
						url = "#top";
					}
				}
				
				if(url){
					if(url.indexOf("#") != -1 && url.indexOf("#") == 0 && (url.indexOf("#") != url.length -1)){
		
						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()
								 || $(document).width()-anchor.offset().left >= $(window).width()
								 || anchor.offset().left > $(window).width()){
												   
									$('html, body').animate({
										scrollTop: anchor.offset().top,
										scrollLeft: anchor.offset().left
									}, speed, easing, function(){
										if(redirect){ 
											window.location = url 
										}
									});
								
								}
								
								return false;
																
							});
						}
					
					}	
				}
			});
			
		}
	
	});
	
})(jQuery);