$(document).ready(function(){
						   
						   /* grab the extra path */
	var expand = jQuery.url.param("expand");
	
	if(!expand)
	{
		expand = $.cookie("persisted");
		/*alert(expand);*/
	}

						   
	/* automatically add classes to each accordion h3 header */
	var i = 0;
    $("div.accordion h4").each(function() {
    	i++;
		$(this).addClass("accordhead"+i);
    });
	
	
	/* automatically add classes to each accordion p expanded */
	var j = 0;
    $("div.accordion div.acc-content").each(function() {
    	j++;
		$(this).addClass("accordexpand"+j);
    });
	
	$(".accordion div.acc-content").hide();
	
	
	if(expand){
		$(".accordion h4.accordhead"+expand).addClass("active");
		$(".accordion div.accordexpand"+expand).show();
		
		$.cookie('persisted', expand);
	}
	
	/*$(".accordion h3:first").addClass("active");*/
	/*$(".accordion p:not(:first)").hide();*/

	$(".accordion h4").click(function(){
		$(this).next("div.acc-content").slideToggle("fast")
		.siblings("div.acc-content:visible").slideUp("fast");
		$(this).toggleClass("active"); /* make header active */
		
		/* grab the classname of the header so we can extract the id */
		var arrayOfClasses = $(this).attr('class').split(' '); 
		currclass=arrayOfClasses[0];
		/*alert(currclass);*/
		
		/* match the last numbers in the class string */
		myexp = /\d{1,3}$/;
		currclassnum = currclass.match(myexp);
		/*alert(currclassnum);*/
		
		/* set the cookie to the number so it will open this up on a re-visit */
		$.cookie('persisted', currclassnum);
		
		$(this).siblings("h4").removeClass("active");
	});

});
