﻿// JavaScript Document

$(document).ready(function(){
var closeOthers = true;


// check which sections are open
function checkOpen() {
// how many sections are open
var openCount = $('#container .readMore:visible').length;
// how many sections are there
var totalCount = $('#container .readMore').length;
// set closeOthers var based on if there are 1 or 0 sections open
if (openCount < 2) closeOthers = true;
// change the text in the expand link based on if
// there are more or less than half of the sections open
if (openCount > totalCount/2) {
//$('#container .expand').addClass("btnSwitch2");
$('#container .expand').html("Collapse All");
$('.expand').addClass("btnSwitch2");
}
else {
//$('#container .expand').removeClass("btnSwitch2");
$('#container .expand').html("Expand All");
$('.expand').removeClass("btnSwitch2");
}
}
// hide all sections
$('#container .readMore').hide();
// show the first section
//$('#container .readMore:first').show();


// actions taken upon clicking any headline
$('#container .reviewBtn').click( function() {
//sets default state of button
// set checkSection to the section next to the headline clicked
// zzzzzzzzzzzz  i modified to display "previous" instead of next so the control is below the content zzzzzzzzzzzzzzzzzz
var checkSection = $(this).prev();
// if the section is open, close it, and call checkOpen
if(checkSection.is(':visible')) {
checkSection.slideUp('slow', checkOpen);
//this creates toggle effect when each button pressed individually
$(this).toggleClass("btnSwitch");
return false;
}
// if the section is closed and closeOthers
// is true, close all other open sections
else {
if (closeOthers) {
$('#container .readMore:visible').slideUp('slow');
//this removes the toggle and class when another button is pressed
$('.reviewBtn').removeClass("btnSwitch");
}
//this ensures pressed button maintains active class
$(this).addClass("btnSwitch");
// open the section and call checkOpen
checkSection.slideDown('slow', checkOpen);

return false;
}
});

// actions taken upon clicking the expand link
/* this didn't work
$('#container .expand').click( function() {
if ($('#container .expand').hasClass() == "") {
*/
// actions taken upon clicking the expand link
$('#container .expand').click( function() {
// if the expand link's text is 'expand all', set closeOthers
// to false, open all sections and call checkOpen

if ($('#container .expand').html() == "Expand All") {
closeOthers = false;
$('.expand').addClass("btnSwitch2");
$('#container .readMore').slideDown('slow', checkOpen);
//ensures btnSwitch state is added to all open sections - all sections when this button is used
$('.reviewBtn').addClass("btnSwitch");
}

// if the expand link's text is 'expand all', set closeOthers
// to true, hide all sections, and call checkOpen
else {
closeOthers = true;
//keep this one - it works
//removes the btnSwitch class if "close all" is clicked
$('.reviewBtn').removeClass("btnSwitch");
// the 1 prevents nasty flickering in some browsers
$('#container .readMore').hide(1, checkOpen);
//this creates a smoother transition but doesn't work right in ie - $('#container .readMore').hide('slow', checkOpen);
return false;
}
});

$(".form-slide").click(function(){
$(this).parent().next("div").slideToggle("slow");
$(this).toggleClass("active"); return false;
});

$(".writeResponseBtn").click(function(){
$(this).parent().next("div").slideToggle("slow");
$(this).toggleClass("active"); return false;
});

checkOpen();
});