function show_liste_produits(r, c, id_categorie){
console.log(c);
var phrase ='';
var add_color;
for (var i = 0; i < r.length; i++) {					
var url_photo = "ressources/fichiers_produits/"+r[i].nom_photo;
//console.log(r[i].nom+'--->'+url_photo);
if (r[i].nom_photo == null) {url_photo='images/non_dispo.jpg'};
var phrase_photo_produit = '';
$.ajax({
	url: 'ajax_photo.php',
	data: "url="+url_photo,
	async: false,
	success: function (reponse) {
		phrase_photo_produit = reponse;
	},
	error: function () {}
});
if (r[i].type == "produit"){
	console.log(r[i].sous_titre);
	if (r[i].sous_titre != null) 
		add_phrase = '
'+r[i].sous_titre+'
';
	else
		add_phrase = '';
	phrase = phrase+(''+phrase_photo_produit+''+add_phrase+'
 ');
}
else{ 
	var id_cat = c[i].nodeId;
	if (r[i].id == id_categorie){ 
	alert(id_cat);
		add_color = ' style="color: red"'; 
		$('#treeview')
			.treeview('collapseAll', { silent: true } )
			.treeview('revealNode', [id_cat, { silent: true }])	
			.treeview('expandNode', [id_cat, { silent: true }]);
	}
	else add_color = '';
	cat = true;
	//console.log('id_cat:'+r[i].nom+'--------->'+r[i].id);
	phrase = phrase+('');
	
//click_img_categorie();
	
}
}
$(".chargement").html(phrase);	
$('.portfolio-item').click(function(){
		var id_noeud = $(this).attr('data-id_noeud');
		var idc = $(this).attr('data-id_cat');
		node = $('#treeview').treeview('getNode', parseInt(id_noeud));
		children=node['nodes'];
		console.log(node);
		get_liste_produits(idc, children);
		$('#treeview')
			.treeview('collapseAll', { silent: true } )
			.treeview('revealNode', [parseInt(id_noeud), { silent: true }])	
			.treeview('expandNode', [parseInt(id_noeud), { silent: true }]);		
	});		
	$('.portfolio-item > div').each(function(){
		var $this = $(this),
			$index = $this.index(),
			contents = $this.find('.img-over');
		$this.hover(function(){
			contents.fadeIn(400).find('.link').removeClass('animated fadeOutUp').addClass('animated fadeInDown');
			contents.find('.zoom').removeClass('animated fadeOutDown').addClass('animated fadeInUp');
			return false;
		},function(){
			contents.fadeOut(400).find('.link').removeClass('animated fadeInDown').addClass('animated fadeOutUp');
			contents.find('.zoom').removeClass('animated fadeInUp').addClass('animated fadeOutDown');
			return false;
		});
	});	
}
			
			/*	function scroller() {
$(window).scrollTop($('#341').offset().top);
}*/
 function search(mot) {
	mode = 1;
	var options = {
	  ignoreCase: true,     // case insensitive
	  exactMatch: true,    // like or equals
	  revealResults: true,  // reveal matching nodes
	};
	var r = $('#treeview').treeview('search', [ mot, options ]);
	return r;
}
function get_liste_produits(id, children, id_categorie){
	var data = "get_produits=true&id="+id+"";
	var resultat;
   	 $.ajax({
        url: 'catalogue.php',
		data: data,
		async: false,
		success: function (response) {
			resultat =  $.parseJSON(response);
			//console.log(resultat[1].nom);
			show_liste_produits(resultat, children, id_categorie);
						
		},
		error: function () {}
    });
   	//console.log(resultat);
   	return resultat;
}
function getTree(id){
	 var data = "show_tree=true&id="+id;
	 console.log(data);
	 var resultat;
   	 $.ajax({
        url: 'catalogue.php',
		data: data,
		async: false,
		success: function (response) {
			resultat = response;
			//ajout des crochets dans le json
		$cnt=0;
		while (resultat.indexOf('nodes":{') > 0){
			resultat=resultat.replace('nodes":{', 'nodes":[{');
			if($cnt>200) break
		}
		$cnt=0;
		while (resultat.indexOf('}}') > 0){
			resultat=resultat.replace('}}', '}]}');
			if($cnt>200) break;
		}
	//	console.log($.parseJSON(resultat));
		},
		error: function () {}
    });
   	 	
	return resultat;
}
function chargement_tree(id){
	$('#treeview').
	treeview({
		levels: 1,
 		data: getTree(id),
		onNodeSelected: function(event, node) {
			mode = 0;
			//fonction ajax pour l'affichage des produits de cette catégorie
			$(this).treeview('expandNode', [node.nodeId, { silent: true }]);
			//$(this).treeview('clearSearch');
			//$(this).treeview('remove');
			//chargement_tree(node.id);
			console.log(node);
			children=node['nodes'];
			get_liste_produits(node.id,children);
			//console.log(children[0].nodeId);
		},			
		onNodeExpanded: function (event, node) {
			},
		onNodeUnselected: function (event, node) {
			
			}
		});
	/*$('#test_fay').on("click", function(){
		console.log('mlkù');
		$('#treeview')
			.treeview('collapseAll', { silent: true } )
			.treeview('revealNode', [805, { silent: true }])
					
	});*/
}