/*	Expanding Menus for Indexhibit
 *		uses jquery
 *
 *	Origional Creator Ross Cairns  Mar 2008
 *  acordian & styleing - Ben Rush 2010
*/


function expandingMenu(num) {

	var speed = 200;
	
	 // ie. first child be the title with the class .section-title unless the user turned it off 
	// this causes problems if we turn the 'Display Section Title' to off
	var menu_title = $("#menu ul").eq(num).children(":first");
	
	var menu_items = $("#menu ul").eq(num).children().filter(function (index) { return index > 0; }); 
	// ie. any li NOT in position 0, below li.section-title
				
	//Add a class to the active list so we can style it.	
	if (menu_items.is(".active") === true) {
			menu_title.addClass("active_menu"); 
		}			
	
	// this if prevents interference with users who turn off the section titling
	if (menu_title.is(".section-title") === true){ 
	
		// hide the inactive exhibits
		if ((menu_items.is(".active") === false) && (menu_items.is(":visible"))  )  {
					menu_items.hide();					}	
					
				
			$('li').click(function (){
					if ( (menu_items.is(".section-title") === false) && (menu_title.is(":visible") === true)  ){
			   		menu_items.hide(speed);
			   		}
			   		if ( (menu_title.is(":hidden") === true )  ){// ?! without this second condition things break down. . .
			   		menu_items.show(speed);
					}
					});						
	
					menu_title.css({cursor:"pointer"}).toggle( // add click functions + pointer to menu_title
						function (){
							menu_items.show(speed);//Open it up
							}, 
						function () {
							//menu_items.hide(speed); //Close it down
						}
						);		
							
		}		
}
