// JavaScript Document
function initMenus() {
$('ul.menu ul').hide();
  $.each($('ul.menu'), function(){
    var cookie = $.cookie(this.id);
    if(cookie === null || String(cookie).length < 1) {
      $('#' + this.id + '.expandfirst ul:first').show();
    }
    else {      
      $('#' + this.id + ' .' + cookie).next().show();
    }
  });

  $('ul.menu li a').click(
    function() {

      var checkElement = $(this).next();
      var parent = this.parentNode.parentNode.id;

      if((checkElement.is('ul')) && (checkElement.is(':visible'))) 
  {
          if($('#' + parent).hasClass('collapsible')) 
    {
              $('#' + parent + ' ul:visible').slideUp('normal');
      
          }
        return false;
      }
      if((checkElement.is('ul')) && (!checkElement.is(':visible'))) 
  {
          $('#' + parent + ' ul:visible').slideUp('normal');
    
          if((String(parent).length > 0) && (String(this.className).length > 0)) 
    {
              $.cookie(parent, this.className);
          }
        checkElement.slideDown('normal');
        return false;
      }
    }


  );
  
  $('.swap').click(function()

          {
             if($(this).text() == 'Click to Collapse All FAQs')
             {
                 $('ul.menu li ul').slideUp('normal');
                 $('ul.menu li ul li').removeClass('active');
                 $(this).text($(this).text() == 'Click to Expand All FAQs' ? 'Click to Collapse All FAQs' : 'Click to Expand All FAQs');
             }else{
                 $('ul.menu li ul').slideDown('normal');
                 $('ul.menu li ul li').addClass('active');
                 $(this).text($(this).text() == 'Click to Expand All FAQs' ? 'Click to Collapse All FAQs' : 'Click to Expand All FAQs');
             }
          }

   );
}
$(document).ready(function() {initMenus();});

