/*
----------------------------------------
Sidebar Slide-down script by Logic Alley
----------------------------------------
If JavaScript is turned off, all ULs are expanded and they're minus-icons are displayed for a graceful degrade. 
I refer to each rounded gray box containing page links as a "group". */

	jQuery(document).ready(function(){

		// Contract *all* ULs
		jQuery('.roundcont ul').hide();

		// Change all icons to plus
		jQuery('.roundcont ul').parent().find('.slider-element').toggleClass("closed");

		// Change icon to minus on group that has WordPress .current_page_item class
		jQuery('.roundcont ul:has(.current_page_item)').parent().find('.slider-element').toggleClass("closed");

		// Show the UL that has the WordPress .current_page_item class
		jQuery('.roundcont ul:has(.current_page_item) ').show();
			
		// Expand the first group and change icon to minus if there are groups with .current_page_item
		// Good if there is only one page group. Also nice to have a 
		// page group open when the user first enters the page. 
		if(jQuery('.roundcont ul:has(.current_page_item)').length == 0) {
			jQuery('.roundcont ul:first').show();
			jQuery('.roundcont ul:first').parent().find('.slider-element').toggleClass("closed");
		}
			
		// Click Event: user wishes to expand or contract a group
		jQuery('.slider-element').click(function(event) {
			
			// Toggle the +/- icon image on .slider-element
			jQuery(event.target).toggleClass("closed");
			
			// Slide the children of the group UL in or out (could be coded more cleanly)
			jQuery('#'+event.target.id+'ul').slideToggle();
		});
	});
