//animate the opening of the branch (span.grower jQueryElement)
function openBranch(jQueryElement, noAnimation) {
		jQueryElement.addClass('tree_open').removeClass('tree_closed');
		if(noAnimation)
			jQueryElement.children('ul').show();
		else
			jQueryElement.children('ul').slideDown();
}
//animate the closing of the branch (span.grower jQueryElement)
function closeBranch(jQueryElement, noAnimation) {
	jQueryElement.addClass('tree_closed').removeClass('tree_open');
	if(noAnimation)
		jQueryElement.children('ul').hide();
	else
		jQueryElement.children('ul').slideUp();
}

//animate the closing or opening of the branch (ul jQueryElement)
function toggleBranch(jQueryElement, noAnimation) {
	if(jQueryElement.hasClass('tree_open'))
		closeBranch(jQueryElement, noAnimation);
	else
		openBranch(jQueryElement, noAnimation);
}

//when the page is loaded...
$(document).ready(function () {
	//to do not execute this script as much as it's called...
	if(!$('ul.tree.dhtml').hasClass('dynamized'))
	{
		//add growers to each ul.tree elements
		$('ul.tree.dhtml ul').addClass('tree_open');
		
		//collapse every expanded branch
		$('ul.tree.dhtml .tree_open').addClass('tree_closed').removeClass('tree_open').hide();
		$('ul.tree.dhtml').show();
		
		//add a fonction on clicks on growers
		$('ul.tree.dhtml li').hover(function(){
			toggleBranch($(this), true);
		});
		//mark this 'ul.tree' elements as already 'dynamized'
		$('ul.tree.dhtml').addClass('dynamized').removeClass('dhtml');
		
	}
});

