// Animate the site menu with collapsing sections
// Requires jQuery
// 2010-01-05

var speed = 250;
var classShowing = "showing"; // class for menu items that are visible
var classWorking = "working"; // class for menu items "in transition" (different from :animated)

$(function(){
	 // Only hide menus if we're not yet in that section;
	 // show the section-specific menu if we are there already.
	 
	$(".dropdown").each( function()
	{
	var el = $(this);
	if (! el.hasClass(document.body.className))
		setupMenu(el);
	});
});

function setupMenu(el)
{
	el.children("ul").hide();
	//el.bind("click", function() {toggle(this, !$(this).hasClass(classShowing));});
	el.hover(
		function(event){toggle(this, true);},
		function(event){toggle(this, false);}
	);
}

function toggle(el, state)
{
	el = $(el);
	el.toggleClass(classShowing, state);
	var tc = function()
	{
		el.toggleClass(classWorking, false);
		if (state != el.hasClass(classShowing))
			toggle(el, el.hasClass(classShowing));
	}
	if (! el.hasClass(classWorking))
	{
		var ul = el.children("ul");
		el.toggleClass(classWorking, true);
		if (state) ul.show(speed, tc);
		else ul.hide(speed, tc);
	}
}