/*	Expanding Menus for Indexhibit
 *		uses jquery
 *
 *	Created by Ross Cairns  Mar 2008
*/


function expandingMenu(num) {
	var speed = 300;
	
	var item_title = $("#menu ul").eq(num).children(":first");
	var items = $("#menu ul").eq(num).children().filter(function (index) { return index > 0; });
	
	currentmenu = -1;
	
	/* hide items if not active */
	if (items.is(".active") == false) {
		//alert("active=false num="+num);
		items.hide();
	}
	else
	{
		currentmenu = num;
	}

	/* add click functions + pointer to title */
	item_title.css({cursor:"pointer"}).toggle(
		function (){
			if (currentmenu > -1)
			{
				var itemstoclose = $("#menu ul").eq(currentmenu).children().filter(function (index) { return index > 0; });
				itemstoclose.hide(speed);
			}
			
			currentmenu = num;
			items.show(speed);
		}, function () {
			
			if (currentmenu == num)
			{
				currentmenu = -1;
				items.hide(speed);
			}
			else
			{
				if (currentmenu > -1)
				{
					var itemstoclose = $("#menu ul").eq(currentmenu).children().filter(function (index) { return index > 0; });
					itemstoclose.hide(speed);
				}
				
				currentmenu = num;
				items.show(speed);
			}
			
		}
	)
}