Team:Lethbridge HS/pageControlScripts


jQuery(document).ready(function(){

                    var aChildren = jQuery(".sideBarContent li").children();
                  var aArray = [];
                  for (var i=0; i<aChildren.length; i++){
                       var aChild = aChildren[i];
                      var ahref = jQuery(aChild).attr('href');
                      aArray.push(ahref);
                  }
           jQuery(window).scroll(function(){
               var windowPos2 = jQuery(window).scrollTop();
               var windowHeight = jQuery(window).height();
               var docHeight = jQuery(document).height;
               
               for (var i=0; i < aArray.length; i++){
                   var theID = aArray[i];
                   var divPos = jQuery(theID).offset().top;
                   var divHeight = jQuery(theID).height();
                   
                   if (windowPos2+130 >= divPos && windowPos2+130 < (divPos + divHeight)){
                       jQuery("a[href='" + theID + "']").addClass("sideBarItemActive"); 
                       
                   }
                   else{
                       jQuery("a[href='" +theID + "']").removeClass("sideBarItemActive");    
                   }
               } 
               
               if (windowPos2 + windowHeight == docHeight){
                   if (!jQuery(".sideBarContent li:last-child a").hasClass("sideBarItemActive")){
                    var navActiveCurrent = jQuery(".sideBarItemActive").attr("href");
                      jQuery("a [href='" + navActiveCurrent + "']").removeClass("sideBarItemActive");
                       jQuery(".sideBarContent li:last-child a").addClass("sideBarItemActive");
                       
                   }
               }
               });
   });