$(document).ready(function() {
	
//Page Scrolling
	$(".scroll").click(function(event){
        //prevent the default action for the click event
        event.preventDefault();
 
        //get the full url - like mysitecom/index.htm#home
        var full_url = this.href;

        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
        var parts = full_url.split("#");
        var trgt = parts[1];

        //get the top offset of the target anchor
        var target_offset = $("#"+trgt).offset();
        var target_top = target_offset.top;
 
        //goto that anchor by setting the body scroll top to anchor top
        $('html, body').animate({scrollTop:target_top}, 900);
    });

    var $sections = $('section');  // all content sections
	//console.log($sections)
	var $navs = $('nav > ul > li');  // all nav sections
	//console.log($navs)
	var topsArray = $sections.map(function() {
	    return $(this).position().top - 400;  // make array of the tops of content
	}).get();                                 //   sections, with some padding to
	//   change the class a little sooner
	var len = topsArray.length;  // length of total sections
	var currentIndex = 0;        // current sections selected
	
	var getCurrent = function( top ) {   // take the current top position, and see which
	    for( var i = 0; i < len; i++ ) {   // index should be displayed
	        if( top > topsArray[i] && topsArray[i+1] && top < topsArray[i+1] ) {
	            return i;
	        }
	    }
	};
	
	   // on scroll,  call the getCurrent() function above, and see if we are in the
	   //    current displayed section. If not, add the "selected" class to the
	   //    current nav, and remove it from the previous "selected" nav
	$(window).scroll(function(e) {
	    var scrollTop = $(this).scrollTop();
	    var checkIndex = getCurrent( scrollTop );
	    if( checkIndex !== currentIndex ) {
	        currentIndex = checkIndex;
	        $navs.eq( currentIndex ).addClass("hlight").siblings(".hlight").removeClass("hlight");
	    }
	});

});
