$(document).ready(function(){
	// $('#nav').accordion({
	// 		header: '.handle',
	// 		collapsible: true,
	// 		navigation: true
	// 	});
	
	
	$('.handle').click(function(){
       //if it's already the active link, just close the menu up and remove the class
       if($(this).hasClass('active_tertiary')){
         $(this).removeClass('active_tertiary');
         $(this).nextAll('.sub-menu').first().slideUp('fast','easeInOutCubic');
				 return false;
       } else {
       //else, close up any existing ones (that aren't an ancestor) and open this one and add the active class

         if($(this).hasClass('child')){
             $(this).addClass('active_tertiary').nextAll('.sub-menu').first().slideDown('fast','easeInOutCubic');
         } else {
             $('.active_tertiary').removeClass('active_tertiary').nextAll('.sub-menu').first().slideUp('fast','easeInOutCubic');
             $(this).addClass('active_tertiary').nextAll('.sub-menu').first().slideDown('fast','easeInOutCubic');
         }
       }

       if($('.active_tertiary').length == 0){
         persistPage();
       }
       return false;
   });


   //*********************** sub nav persistence vvv ********************
   function persistPage(){
     $('.selected').each(function(){
				if($(this).hasClass('child')){
					$(this).parents('.sub-menu').show().prevAll('.handle').first().addClass('active_tertiary');	
				} else if($(this).hasClass('handle')){
					$(this).addClass('active_tertiary').nextAll('.sub-menu').first().show();
				}
			});
   }
   persistPage();
	
	$('.home_promo:first').animate({ left: '0' }, 'slow', 'easeInOutCubic');
	$('#news_items.home').cycle({
		fx: 'scrollUp',
		easing: 'easeInOutCubic'
	})
});
