/*
For usage notes check:
http://www.i-marco.nl/weblog/jquery-accordion-menu-redux/
It's not the same script but works the same way.
*/

jQuery(function($) {
	$('ul.menu ul').hide();	
	
	selected = $('ul.menu ul .selected')
	if (selected.length){
		selected.parent('ul').show();
	} else {
		$('ul.menu.expandfirst').find('ul:first').show();
		$('#more-team').show();
	}

	$('ul.menu a:has(~ul)').click(function(){

		var target = $(this).next('ul');
		var parent = $(this).parents('ul');
		
		if (parent.hasClass('noaccordion')) {
			target.slideToggle('normal', onSlideEnd);
		} 

		else if (target.is(':visible')) {
			if(parent.hasClass('collapsible')) {
				target.slideUp('normal', onSlideEnd);
			}
		} 

		else if (!target.is(':visible')) {
			parent.find('ul:visible').slideUp('normal');
			target.slideDown('normal', onSlideEnd);
		}

		return false;
		
	});

	// A place to add handlers after slider (up/down) has finished.
	var onSlideEnd = function(){ 
		/*	Now this is slightly ugly.
			Since we're also using jScrollPane, and it doesn't have a hook to re-init itself,
			we have to do it manually, as a callback, when the sliding has ended. */		
		if ($.jScrollPane && barOptions){
			$('#menuList').jScrollPane(barOptions);	
		}
	};	
	
});
