// JavaScript Document
<!--
// this tells jquery to run the function below once the DOM is ready
$(document).ready(function() {

// choose text for the show/hide link
var showText="View content list";
var hideText="Hide content list";
var showText1="View list of sponsoring agencies";
var hideText1="Hide list of sponsoring agencies";
var showText2="View list of administrator types";
var hideText2="Hide list of administrator types";
var showText3="View list of locations";
var hideText3="Hide list of locations";
var showText4="View definitions and list of activity types";
var hideText4="Hide definitions and list of activity types";
var showText5="View notes";
var hideText5="Hide notes";

// hide all of the elements with a class of 'toggle'
	$(".toggle").hide();
	
// append show/hide links to the element directly preceding the element with a class of "toggle"
	$(".h_agency").prev().append('<p class="content_list">[<a href="#" class="toggleLink_h_agency">'+hideText1+'</a>]</p>');
	$(".agency").prev().append('<p class="content_list">[<a href="#" class="toggleLink_agency">'+hideText1+'</a>]</p>');
	$(".loc").prev().append('<p class="content_list">[<a href="#" class="toggleLink_loc">'+hideText3+'</a>]</p>');
	$(".admin").prev().append('<p class="content_list">[<a href="#" class="toggleLink_admin">'+hideText2+'</a>]</p>');
	$(".acty").prev().append('<p class="content_list">[<a href="#" class="toggleLink_acty">'+hideText4+'</a>]</p>');
	$(".gen").prev().append('<p class="content_list">[<a href="#" class="toggleLink_gen">'+hideText+'</a>]</p>');
	$(".toggle").prev().append('<a href="#" class="toggleLink2 tbtn">'+showText5+'</a>');

// local navigation link
	$("a.toggleLink_h_agency").click(function() {	
	// change the link text depending on whether the element is shown or hidden
		if ($(this).text() == hideText1) {
				$(this).text(showText1);
				$(".h_agency").slideUp("slow");
				$.cookie('c_h_agency', 'collapsed');
				return false;
			}else {
				$(this).text(hideText1);
				$(".h_agency").slideDown("slow");
				$.cookie('c_h_agency', 'expanded');
				return false;
		}
		// toggle the display
		//$(this).parent().next('.localnav').slideToggle('fast');			
	});

// local navigation link
	$("a.toggleLink_agency").click(function() {	
	// change the link text depending on whether the element is shown or hidden
		if ($(this).text() == hideText1) {
				$(this).text(showText1);
				$(".agency").slideUp("slow");
				$.cookie('c_agency', 'collapsed');
				return false;
			}else {
				$(this).text(hideText1);
				$(".agency").slideDown("slow");  
				$.cookie('c_agency', 'expanded');
				return false;
		}			
	});
	
// local navigation link
	$("a.toggleLink_admin").click(function() {	
	// change the link text depending on whether the element is shown or hidden
		if ($(this).text() == hideText2) {
				$(this).text(showText2);
				$(".admin").slideUp("slow");
				$.cookie('c_admin', 'collapsed');
				return false;
			}else {
				$(this).text(hideText2);
				$(".admin").slideDown("slow");  
				$.cookie('c_admin', 'expanded');
				return false;
		}			
	});		
	
// local navigation link
	$("a.toggleLink_loc").click(function() {	
	// change the link text depending on whether the element is shown or hidden
		if ($(this).text() == hideText3) {
				$(this).text(showText3);
				$(".loc").slideUp("slow");
				$.cookie('c_loc', 'collapsed');
				return false;
			}else {
				$(this).text(hideText3);
				$(".loc").slideDown("slow");  
				$.cookie('c_loc', 'expanded');
				return false;
		}	
	});	
	

// local navigation link
	$("a.toggleLink_acty").click(function() {	
	// change the link text depending on whether the element is shown or hidden
		if ($(this).text() == hideText4) {
				$(this).text(showText4);
				$(".acty").slideUp("slow");
				$.cookie('c_acty', 'collapsed');
				return false;
			}else {
				$(this).text(hideText4);
				$(".acty").slideDown("slow");  
				$.cookie('c_acty', 'expanded');
				return false;
		}		
	});	

// local navigation link
	$("a.toggleLink_gen").click(function() {	
	// change the link text depending on whether the element is shown or hidden
		if ($(this).text() == hideText) {
				$(this).text(showText);
				$(".gen").slideUp("slow");
				$.cookie('c_gen', 'collapsed');
				return false;
			}else {
				$(this).text(hideText);
				$(".gen").slideDown("slow");  
				$.cookie('c_gen', 'expanded');
				return false;
		}		
	});	


	// capture clicks on the toggle links
	$('a.toggleLink2').click(function() {
	
	// change the link text depending on whether the element is shown or hidden
		if ($(this).text()==showText5) {
				$(this).text(hideText5);
			}else {
				$(this).text(showText5);
		}	
		// toggle the display	
		$(this).parent().next('.toggle').slideToggle('fast');	
		// return false so any link destination is not followed
		return false;	
	});



///////////////////////////////////////
// COOKIES

var pageNav = $.cookie('c_agency');
	if (pageNav == 'collapsed') {
		$("a.toggleLink_agency").text(showText1);
		$('.agency').hide();
	};

var pageNav1 = $.cookie('c_loc');
	if (pageNav1 == 'collapsed') {
		$("a.toggleLink_loc").text(showText3);
		$('.loc').hide();
	};
	
var pageNav2 = $.cookie('c_admin');
	if (pageNav2 == 'collapsed') {
		$("a.toggleLink_admin").text(showText2);
		$('.admin').hide();
	};

var pageNav3 = $.cookie('c_acty');
	if (pageNav3 == 'collapsed') {
		$("a.toggleLink_acty").text(showText4);
		$('.acty').hide();
	};

var pageNav4 = $.cookie('c_gen');
	if (pageNav4 == 'collapsed') {
		$("a.toggleLink_gen").text(showText);
		$('.gen').hide();
	};

var pageNav5 = $.cookie('c_h_agency');
	if (pageNav5 == 'collapsed') {
		$("a.toggleLink_h_agency").text(showText1);
		$('.h_agency').hide();
	};
	

var myCookieJar = $.cookieJar('myCookieJar');
	myCookieJar.set('c_agency', 'c_admin', 'c_loc', 'c_acty', 'c_gen');
//alert(myCookieJar.get('test1'));
});

// -->