jQuery(function( $ ){
	// The same for all waypoints
	$('body').delegate('.frame', 'waypoint.reached', function(event, direction) {
		var $active = $(this);

		if (direction === "up") {
			$active = $active.prev();
		}
		if (!$active.length) $active = $active.end();
				
		$('.link-active').removeClass('link-active');
		$('a[href=#'+$active.attr('id')+']').addClass('link-active');

		$('.block-active').removeClass('block-active');
		$('#'+$active.attr('id')+' .leftbutton').addClass('block-active');
		$('#'+$active.attr('id')+' .rightbutton').addClass('block-active');
	});
	
	// Register each section as a waypoint.
	$('.frame').waypoint({ offset: '0px' });
	
	// Negates the flash of non-active nav.
	$('body > #nav a').click(function() {$(this).addClass('link-active');});
});
