/* This accordion implementation originally found at stemkoski.com */

jQuery(document).ready(function() {

  //ACCORDION BUTTON ACTION
  jQuery('h3.accordionButton').click(function() {

    if(jQuery(this).next().css('display') == 'none') {

      /*if the object AFTER the one being clicked (always a div.accordionContent)
       * has the CSS property 'display' with a value of none, show it and hide
       * the rest. Then change the background image to be the minus sign */

      jQuery('ul.accordionContent').slideUp();
      jQuery(this).next().slideDown();
      jQuery('h3.accordionButton').removeClass('expanded'); //if there has been an expandAll
      jQuery(this).addClass('expanded');

    } else {

      /* Otherwise, it must be showing, so hide it and change the background
         * image to plus sign */

      jQuery(this).removeClass('expanded');
      jQuery(this).next().slideUp();
    }
  });

  //EXPAND AND COLLAPSE BUTTON ACTIONS

  /*self-evident, but when the element with the id "expandAll" is clicked,
     * show all instances of div.accordionContent with a slideDown and make
     * sure that all backgrounds are minus sign*/

  jQuery('#expandAll').click(function() {
    jQuery('h3.accordionButton').addClass('expanded');
    jQuery('ul.accordionContent').slideDown();
        
  });

  /*self-evident, but when the element with the id "collapseAll" is clicked,
     * hide all instances of div.accordionContent with a slideUp and make
     * sure all background images are the plus sign */
  jQuery('#collapseAll').click(function(){
    jQuery('ul.accordionContent').slideUp()
    jQuery('h3.accordionButton').removeClass('expanded');
  });

  //HIDE THE DIVS ON PAGE LOAD
  jQuery("ul.accordionContent").hide();

});
