//opens the subnav menu on click
//Exceptions are in about us
var menuClickFunction = function(anchor){        
    anchor.addEvent('click', function(e){        
	    if(!$('wa-about')){     						
	    	//Add open class to parent UL
			this.getParent().toggleClass('menu-open');
			//Stop event
			e.stop(); 
		}    
    });
}

window.addEvent('load', function(){
	//Anchor links to open children
    var anchorArray = $$('.date-year');
    //Current path
    var locationPath = window.location.pathname;
    var menuColor = '#ffffff';
	
    //Go through each anchor, and add click event
    anchorArray.each(menuClickFunction);
        
    //If there is a subnav
    if($('ps-subnavigation')){
    	//get anchor with the same path name as page
    	var currentAnchor = $('ps-subnavigation').getElements('a[href=' + locationPath + ']');
    	if(currentAnchor.length == 0){
    		currentAnchor = $('ps-subnavigation').getElements('a[href=' + window.location.href + ']');
    	}
    	
    	if(currentAnchor){
    		currentAnchor.each(function(anchor){
				//Get the anchor's parent LI
		    	var currentLi = anchor.getParent('li');
		    	//add here class
		    	    
		    	currentLi.addClass('here');
		    	if(currentLi){
		    		//get parent
			        var parentElement = currentLi.getParent('li');
					
			        //if no parent li, then use current li
			        if(parentElement == null || parentElement == ""){	        	
			        	parentElement = currentLi;
			        }
			        
			        //add open class
			       
			        parentElement.addClass('menu-open');
			       
		        }     	
    		});
    		
    	}   	
    }
    
    //If there is an "expand all" anchor, add click event to open all
    if($$('.ps-expand-all')){    
        var expandLink = $$('.ps-expand-all').getElement('a');    
        expandLink.addEvent('click', function(event){        
            $$('.date-year').each(function(childLink){
                childLink.getParent().set('class', 'menu-open');
            });            
            event.stop();        
        });
    }    
});