/* Accordian Menu

1: each menu MUST have a class 'menuLeftSidebar' set. If the menu doesn't have this, the JS won't make it dynamic
2: this script is designed to collapse the group when the parent item is clicked

*/

function initMenus() {
	$('ul.menuLeftSidebar ul').hide();
	$.each($('ul.menuLeftSidebar'), function(){									 
		$('.selected').parent().show();		
	});
	$('ul.menuLeftSidebar li a').click(
		function() {
			var currentListItem = $(this).parent();
			var listGroupClass = $(this).parent().parent().attr('class');
			var currentListClass = $(this).parent().attr('class');
			var checkElement = $(this).next();

			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('.' + listGroupClass + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}		
			
			// makes group collapse when parent item is clicked
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				$('.' + listGroupClass + ' ul:visible').slideUp('normal');
				return false;
			}		
		}
	);

}

$(document).ready(function() {initMenus();});