//animate the opening of the branch (span.grower jQueryElement)
function openBranch(jQueryElement, noAnimation) {
		jQueryElement.addClass('OPEN').removeClass('CLOSE');
		if(noAnimation)
			jQueryElement.parent().find('ul:first').show();
		else
			jQueryElement.parent().find('ul:first').slideDown();
}
//animate the closing of the branch (span.grower jQueryElement)
function closeBranch(jQueryElement, noAnimation) {
	jQueryElement.addClass('CLOSE').removeClass('OPEN');
	if(noAnimation)
		jQueryElement.parent().find('ul:first').hide();
	else
		jQueryElement.parent().find('ul:first').slideUp();
}

//animate the closing or opening of the branch (ul jQueryElement)
function toggleBranch(jQueryElement, noAnimation) {
	if(jQueryElement.hasClass('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').prev().before("<span class='grower OPEN'> </span>");
		
		//dynamically add the '.last' class on each last item of a branch
		$('ul.tree.dhtml ul li:last-child, ul.tree.dhtml li:last-child').addClass('last');
		
		//collapse every expanded branch
		$('ul.tree.dhtml span.grower.OPEN').addClass('CLOSE').removeClass('OPEN').parent().find('ul:first').hide();
		$('ul.tree.dhtml').show();
		
		//open the tree for the selected branch
			$('ul.tree.dhtml .selected').parents().each( function() {
				if ($(this).is('ul'))
					toggleBranch($(this).prev().prev(), true);
			});
			toggleBranch( $('ul.tree.dhtml .selected').prev(), true);
		
		//add a fonction on clicks on growers
		$('ul.tree.dhtml span.grower').click(function(){
			toggleBranch($(this));
		});
		//mark this 'ul.tree' elements as already 'dynamized'
		$('ul.tree.dhtml').addClass('dynamized');
		$('ul.tree.dhtml li span.grower.OPEN').parent().addClass('selected');

		$('ul.tree.dhtml').removeClass('dhtml');
	}
	$("div#categories_block_left ul ul li ul").hide();
	
	
	
	
	//mod alex
	//ajout
	
	//pas de sous menu de 3e niveau pour les pages boutiques éphémères 
	if( 	$('body').attr('class') != "category_102" && 
			$('body').attr('class') != "category_100" && 
			$('body').attr('class') != "class_les_princesses_viennent" &&
			$('body').attr('class') != "category_13"){
				
		$("div#categories_block_left ul ul li").hover(
		 function () {
			$(this).find('ul').show();
		  },
		   function () {
			$(this).find('ul').hide();
		  }
		);
		
		//correction bug css safari
		$("div#categories_block_left ul ul li#menuItem14.menuItem14").hover(
		 function () {
			$("div#categories_block_left.block div.block_content ul.tree li#menuItem10.menuItem10 ul.niveau_8 li#menuItem14.menuItem14 a").css("border-radius",'0');
		  },
		   function () {
			$("div#categories_block_left.block div.block_content ul.tree li#menuItem10.menuItem10 ul.niveau_8 li#menuItem14.menuItem14 a").css("border-radius",'0 0 0 5px');
		  }
		);
		//end correction bug css safari
		
	}
	$('div#categories_block_left ul.tree li.defaultopen ul').show();
	
	
	
	
	
	$("#categories_block_left ul ul").hide();
	$("#categories_block_left ul li.selected ul").show();
	$("#categories_block_left ul li.defaultopen ul").show();
	$("#categories_block_left ul ul ul").hide();
	
	//correction bug menu qui ne s'affiche pas pour les produits lorsqu'on est pas passé par un lien du menu principal
	//$("#product #categories_block_left ul li.menuItem10 ul").show();
	//$("#product #categories_block_left ul li.menuItem10 ul ul").hide();
	
	//end mod alex
});

