function ouvrirCat(id){
	$(".catProduit").css("display", "none");
	if(id == "all"){
		$(".catProduit").fadeIn(500);
		$(".catProduit").data("all", true);
		//$(".catProduit .contenu").hide();
		$(".catProduit .contenu").hide();
	}else{
		$("#cat"+id).fadeIn(500);
		//$(".catProduit").data("all", false);
		$(".catProduit").css("backgroundColor", "#FFFFFF");
		
		$(".catProduit .contenu").show();
	}
	
	
	$(".item").each(function(i){
		if($(this).hasClass('selected')){
			$(this).removeClass('selected');
		}
	});
	$("#itemCat"+id).addClass('selected');
	$(".nouvelle:last").css("border", "none");
	ajusterHeights();
	
}

function ajusterHeights(){	 
	if(parseInt($("#leContenu").height()) < 350){
		$("#boiteBlancheContenu").animate({height:'350px'},500);
		$("#contenuBordGaucheRepeat").animate({height:'258px'},500);
		$("#contenuBordDroiteRepeat").animate({height:'258px'},500);
		$("#contenu").animate({height:'302px'},500);
	}else{
		$("#boiteBlancheContenu").animate({height:$("#leContenu").height()},500);
		$("#contenuBordGaucheRepeat").animate({height:(parseInt($("#leContenu").height())-92)+'px'},500);
		$("#contenuBordDroiteRepeat").animate({height:(parseInt($("#leContenu").height())-92)+'px'},500);
		$("#contenu").animate({height:(parseInt($("#leContenu").height())-48)+'px'},500);
		//$("#boiteBlancheContenu").css("height", $("#leContenu").css("height"));
	}
}

$(window).load(function () {
						 var h = parseInt($("#boiteBlanche").height()) - 250;					   
	
	//var h = document.getElementById("boiteBlanche").offsetHeight - 250;
	$("#boiteBlancheContenu").height(h+"px");
	$("#contenu").height(h+"px");
	//document.getElementById("contenu").style.height = h+"px";

	$("#contenuBordGauche").height("70px");
	$("#contenuBordDroite").height("70px");

	//document.getElementById("contenuBordGauche").style.height = document.getElementById("contenu").offsetHeight+"px";
	//document.getElementById("contenuBordDroite").style.height = document.getElementById("contenu").offsetHeight+"px";

	h = parseInt($("#contenu").height()) - 40;
	//var h = document.getElementById("contenuBordDroite").offsetHeight - 70;
	$("#contenuBordDroiteRepeat").height(h+"px");
	$("#contenuBordGaucheRepeat").height(h+"px");

	/*document.getElementById("contenuBordDroiteRepeat").style.height = temp+"px";
	temp = document.getElementById("contenuBordGauche").offsetHeight - 70;
	document.getElementById("contenuBordGaucheRepeat").style.height = temp+"px";*/
	ajusterHeights();
	
	$(".catProduit").data("ouvert", false);
	//$(".catProduit").css("cursor", "pointer");
	$(".catProduit").click(function(event){
		//alert(event.target);
		//alert(this);
		if($(this).data("all") && $(this).data("ouvert") == false){
			
			$(".catProduit .contenu").hide();
			$(".catProduit").data("ouvert", false);
			$(".catProduit").css("backgroundColor", "#ffffff");
			$(this).data("ouvert", true);
			$(this).find(".contenu").slideToggle("fast", function(){
				$(this).parent().css("backgroundColor", "#fff5df");
				ajusterHeights();
			});
		}
		
	});
	
	$(".catProduit").mouseover(function(){
		if($(this).data("all") && $(this).data("ouvert") == false){
			$(this).css("backgroundColor", "#fef9ed");
		}
	});
	
	$(".catProduit").mouseleave(function(){
		if($(this).data("all") && $(this).data("ouvert") == false){
			$(this).css("backgroundColor", "#FFFFFF");
		}
	});
  // run code
});

$(document).ready(function(){
	
});
