 /*
Author: Tim Souther
Description: gives class to the navigation links based on the scroll position.
*/

/* set this */
var navHeightGo =		290; /* start here */

/* these will be overwritten */
var navHeightStop =		890; /* stop here */
var sidebarHeight = 	724; /* the hieght of the sidebar */
var contentHeight =		1400;

$(window).scroll(function(){

		/*  returns height of #scrollingsidebar */
		var sidebarHeight = $("div#scrollingsidebar").height();
		
		
		/*  returns height from the top of the page to just before the footer */
		var contentHeight = $("div#mainwrap").height();
		
		var navHeightStop = contentHeight - sidebarHeight; 
		
		$("div.pageThreeContent").css("min-height", sidebarHeight + "px");
		
		console.log("content:" + contentHeight + " sidebar:" + sidebarHeight);
			
		/* if the window is scrolled between Go and Stop, 
		fix the nav's position to the top of screen */
		if( ($(document).scrollTop() > navHeightGo) && ($(document).scrollTop() < navHeightStop) ){
			$("#scrollingsidebar").css("position","fixed");
			$("#scrollingsidebar").css("top","10px");   
			/* console.log($(document).scrollTop());  */        
		}
		else if($(document).scrollTop() > navHeightStop){
			$("#scrollingsidebar").css("position","absolute");
			$("#scrollingsidebar").css("top",navHeightStop + "px");
		}
		else{
			/*
			otherwise have it be positioned absolutely to 
			250px below the top.*/
			$("#scrollingsidebar").css("position","inherit");
			$("#scrollingsidebar").css("top","0px");
		}
});
