// togglebranch
//	Place this on any LI elements which contain a UL that you want to be able to open and close
//	When the LI is clicked, the UL will be shown or hidden
function togglebranch( ob, _action ){
	var i = 0;
	var dropper = ob.childNodes[i];
	while(dropper != null && dropper.nodeName.toLowerCase() != "ul")
	{dropper = ob.childNodes[++i];}
		
	if (dropper) {		
		if (_action == "show"){
			dropper.style.display = 'block';
			$(ob).removeClass( "closed" );
			$(ob).addClass( "open" );
		}
		if (_action == "hide"){
			dropper.style.display = 'none';
			$(ob).removeClass( "open" );
			$(ob).addClass( "closed" );
		}
		if( _action == "toggle" ){
			if( dropper.style.display == 'none' )	{
				dropper.style.display = 'block';
				$(ob).removeClass( "closed" );
				$(ob).addClass( "open" );			
			}
			else {
				dropper.style.display = 'none';
				$(ob).removeClass( "open" );
				$(ob).addClass( "closed" );
				// Also collapse any children of the close UL that may be open
				// The child LI elements must have the open class set or they will be ignoted
				// this is so we don't just collapse everything in case we don't just have a simple ul/li tree
				$(dropper).find( "li.open" ).each( function( idx, elem ) { togglebranch( elem, "hide" ); } );					
			}
		}
	}	
}
