var currentAnchor;
$(document).ready(function(){
	$(".scroll").click(function(event){
		//prevent the default action for the click event

		//get the full url
		var full_url = this.href;

		//split the url by # and get the anchor target name
		var parts = full_url.split("#");
		var trgt = parts[1];
		//if(currentAnchor != trgt) currentAnchor = trgt;
		//else return false;
		currentAnchor = trgt;
		
		setAboutNav(trgt);
		


		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 300);
	});
	
	function checkSelectedLinks(){
		var scrollTop = $(window).scrollTop();
		$(".section").each(function(){
			var position = $(this).position().top;
			var sectionH = $(this).height();
			$("#read").html("scrollTop "+scrollTop+"  position:"+position	);
			var btmEdge = position + sectionH;
			if(btmEdge>scrollTop){ 
				setAboutNav($(this).attr("id")); 
				return false;
			}
		});
	}
	function setAboutNav($anchor){
		//$("#readout").append("<br>"+$anchor);
		$("#nav a").removeClass("selected");
		$('a[href="?p=about#'+$anchor+'"]').addClass("selected");
	}
	$(window).scroll(checkSelectedLinks);
});
