/* 
jQuery Collapsible Categories Menu for WordPress
Inspired by: http://www.i-marco.nl/weblog/
Modifications by: Stacy London 
Created: 2010.05.27
Description: Removes use of cookies and instead uses the class names 
assigned by WordPress to auto-expand selected category on page load
*/
function initCategories() {
	
	$('ul.menu ul').hide(); // hide all the subcategories
	$('ul.menu li.current-cat-parent ul').show(); // show the currently selected category's subcategories
	
	$('ul.menu li a').click(							
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id; // = sidenav
//alert('checkElement className: ' + checkElement[0].className); // = children
			// for the visible ul			
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal'); // slide up all the visible ul in sidenav
				return false;
			}
			// for the hidden ul			
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal'); // slide up all the visible ul in sidenav
				checkElement.slideDown('normal'); // slide down the the children of this clicked category
				return false;
			}
		}
	);
	
}

$(document).ready(function() {initCategories();});

