jQuery(document).ready(function(){
	$('.accordion h2').addClass('accordion_head').click(function() {
	  if($(this).hasClass('head_expanded')) {
	    // $('.accordion h2').removeClass('head_expanded').next().hide();
	    $(this).removeClass('head_expanded').next().hide();
		} else {
		  // $('.accordion h2').removeClass('head_expanded').next().hide();
		  $(this).addClass('head_expanded').next().show();
		  window.location.hash = $(this).text().replace(/\s/g,'-').substring(0,31) ;
		  // console.log(this.textContent.replace(/\s/g,'-'));
		};
		return false;
	}).next().addClass('accordion_body').hide();
	
	$('.expand_accordion').click(function() {
		if($(this).hasClass('accordion_expanded')) {
  		$('.expand_accordion').each(function (i) {
          $(this).removeClass("accordion_expanded");
          $(this).html("Expand all");
          $('.accordion h2').removeClass('head_expanded').next().hide();
      });
    } else {
      $('.expand_accordion').each(function (i) {
          $(this).addClass("accordion_expanded");
          $(this).html("Collapse all");
          $('.accordion h2').addClass('head_expanded').next().show();
      });
    };



		return false;
	});
	
	$('.accordion h2').each(function(index){
    if(window.location.hash == '#'+$(this).text().replace(/\s/g,'-').substring(0,31) ){
      $(this).addClass('head_expanded').next().show();
    };
  });
	
});