//
// this script was written by Ben Frain - more info at http://www.benfrain.com
// 
jQuery(document).ready(function(){

  jQuery('ul#vertnav > li > ul')
    .click(function(e){
      e.stopPropagation();
    })
    .hide();

jQuery('.level0-active ul').show();

    
  	
  
//this section below prevents the first level links being followed. 
  jQuery('ul#vertnav > li').click(function(event) {
  event.preventDefault();
});
    
  jQuery('ul#vertnav > li, ul#vertnav > li > ul > li').click(function(){
    var selfClick = jQuery(this).find('ul:first').is(':visible');
    if(!selfClick) {
      jQuery(this)
        .parent()
        .find('> li ul:visible')
        .slideToggle();
        
    }
    
    jQuery(this)
      .find('ul:first')
      .stop(true, true)
      .slideToggle();
      
  });
  
  //this section make the nereast ul section to the link show
  var url = window.location.toString() // this will return http://mydomain.com/pagename.html?query=xxxxxx
  
  
  // this bit adds a class to the active section for CSS 
  jQuery('ul#vertnav > li a').each(function(){
      var myHref= jQuery(this).attr('href');
      if( url.match( myHref)) {
           jQuery(this).addClass('activeClassNameForCSSHighlight')
            jQuery(this).closest('ul').show();
      }
});
  
});
