/*	
 *	Expanding Two-Level Menus with auto-collapse on submenus disabled for Indexhibit	
 *  uses jquery
 *	
 *  Fork by Thomas Dunn Nov 2010
 *  Based on expandingMenu.js by Ross Cairns  Mar 2008 and expandingTwoLevelMenus.js by H. Madrona  Aug 2010
 *  
 */
var _ItemsToCollapse = [];

function initializeAllMenus()
{
	/* Initialize menus */
	$("#menu ul.section").each( function (index) { 
		expandingMenu( index );
	} );
	
	/* Initialize submenus */
	$("#menu li.subsection-title").each( function (index) { 
		expandingSubmenu( index ); 
	} );
}

function expandingMenu(num) {
	var speed = 0;

	var menu = $("#menu ul.section").eq(num);
	var item_title = menu.children(":first");
	var items = menu.children( ":not(:first)" );
	
	_ItemsToCollapse.push( items );
	
	/* hide items if not active */

// 	if ( ( menu.is(".active") == false ) && ( items.is(".active") == false  ) && ( items.children( "ul.subsection" ).find( ".active" ).length <= 0 )) {
// 			items.hide();
// 	}
// function displayMenu(action, id)
// {
// if (action == 'show')
// {
// document.getElementById("item_title"+id).style.display = "block";
// document.getElementById("items"+id).href= "javascript:display('hide', "+id+")";
// }
// 
// if (action == 'hide')
// {
// document.getElementById("item_title"+id).style.display = "none";
// document.getElementById("items"+id).href= "javascript:display('show', "+id+")";
// }
// }

	/* add click functions + pointer to title */
	item_title.css({cursor:"pointer"}).toggle(
		function () {
			items.show(speed);
		}, function () {
			items.hide(speed);
		}
	)
}

function expandingSubmenu(num) {
	var speed = 0;

	var menu = $("#menu ul.section").eq(num);
	var item_title = menu.children(":first");
	var items = menu.children( ":not(:first)" );
	var submenu = $("#menu li.subsection-title").eq(num);
	var subitem_title = submenu.children( "span" );
	var subitems = submenu.find( "ul li" );
	
	_ItemsToCollapse.push( subitems );
	
	/* hide items if not active */
// 	
// 	if ( ( menu.is(".active") == false ) && ( submenu.is(".active") == false ) && /*( items.is(".active") == false ) &&*/ ( subitems.is(".active") == false ) && ( item_title.is(".active") == false ) /*&& ( subitem_title.is(".active") == false )*/) {
// 			subitems.hide();
// 	}		
function displayMenu(action, id)
{
if (action == 'show')
{
document.getElementById("subitem_title"+id).style.display = "block";
document.getElementById("subitems"+id).href= "javascript:display('hide', "+id+")";
}

if (action == 'hide')
{
document.getElementById("subitem_title"+id).style.display = "none";
document.getElementById("subitems"+id).href= "javascript:display('show', "+id+")";
}
}
	/* add click functions + pointer to title */
	subitem_title.css({cursor:"pointer"}).toggle(
		function () {
			subitems.show(speed);
		}, function () {
			subitems.hide(speed);
		}
	)
}
