/* Jolin Yim jolin_yim@wgbh.org 03.29.11 ----------------------------------------------------*/ var num=1; var len; var currentUL; var currentSection; var loc; var searchStr; $(document).ready(function(){ currentSection = $('body').attr('class'); //current section loc = window.location.toString(); //get url var locParts = loc.split("/"); //separate by / var locLength = locParts.length; //total length of url array $('#nav ul').addClass("no-height"); $('#nav ul li').addClass('nav-list-items'); //prep li for animation //show current hav item if(currentSection=="") { //if it is P&T index currentUL = $('#pt_nav'); searchStr = "./index.html"; }else{ //all other sections - search by currention/last part of url currentUL = $('#'+currentSection+'_nav'); if(currentSection=="reading") { currentSection="readingbuddies"; } //console.log(currentSection); if(currentSection=="sponsors") { searchStr = currentSection+"/index.html"; }else if(currentSection=="activities" && locParts[locLength-1]!="books.html") { searchStr=currentSection+"/activities.html"; }else if(currentSection=="helpinganimals"){ searchStr=currentSection+"/index.html"; }else{ searchStr = currentSection+"/"+locParts[locLength-1]; } } currentUL.removeClass('no-height').addClass('hide'); //prep current ul for animation currentUL.delay(500).slideDown("normal"); //slide down animation for ul var foundMatch = false; $('#nav a').each(function(){ if(!foundMatch) { if($(this).attr('href').indexOf(searchStr) != -1){ $(this).parent().addClass('current'); foundMatch=true; } } }); len=$(currentUL).children().length; //find total length of subsections showLI(); //nav hover animation - slide to right $('#nav li').hover(function() { $(this).children('a').addClass("on").animate({ marginLeft: 10 }, {duration:100, queue:false}); }, function(){ $(this).children('a').removeClass("on").animate({ marginLeft: 0 }, {duration:100, queue:false}); }); }); //subsection animation - loop through total length of li and animate slide to right to reveal one by one function showLI() { if(num<=len) { var obj = $(currentUL).find('li:nth-child('+num+')'); obj.animate({ width:'100%' }, 90, function(){ $(this).animate({marginLeft:0}, 80, function(){num++; showLI();}); }); } }