jQuery(document).ready(function($){
	var sections = $('.section');  // all content sections
	var navs = $('li.menu-item');  // all nav sections

	var topsArray = sections.map(function() {
	    return $(this).position().top - 50;  // make array of the tops of content
	}).get();                                 //   sections, with some padding to
	                                          //   change the class a little sooner
	var len = topsArray.length;  // quantity of total sections
	var currentIndex = 0;        // current section 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;
	        }
	    }
	};
	$(document).scroll(function(e) {
	    var scrollTop = $(this).scrollTop();
	    var checkIndex = getCurrent( scrollTop );
	    if( checkIndex !== currentIndex ) {
	        currentIndex = checkIndex;
	        navs.eq( currentIndex ).addClass("selected").siblings(".selected").removeClass("selected");
	    }
	});
});
