function init_projects()
{
	$('#box1').attr('checked',1);
	$('#box2').attr('checked',1);
	$('#box3').attr('checked',1);
	$('#box4').attr('checked',1);
	$('#box5').attr('checked',1);
	display_projects();
}

function display_projects()
{	
//	alert('display dat shit');
	var i=0;
	$('.box_ul li').each(function(i){
		i++;
		$(this).animate({opacity: 1.0}, i*100).fadeIn("slow", function(){
		  	// callback here	
		  });
	});
	
	$(function(){
		$(".box_ul li").hover(function (e) { 
				$("#projet_list").append("<div id='infobulle'><h3>Info Bulle Titre</h3><p>Description</p></div>");			
	    		$("#infobulle").html($(this).children("div.infos").html());
	    		$("#infobulle")
	     			.css("left", (e.pageX+10) +"px")
	     			.css("top", (e.pageY+10) +"px")
//	     			.show('normal');
	     			.fadeIn('fast');
	   	},function(){
			//alert("out");
			$("#infobulle").remove();

//			fadeOut(0).css("display", "none");
			//$("#tooltip").fadeOut('fast');
		});
		
		$(".box_ul li").mousemove(function(e){
			$("#infobulle")
	     			.css("left", (e.pageX+10) +"px")
	     			.css("top", (e.pageY+10) +"px");
		});				    	   	
	});	
	// masque le loading
	$('#loading_anim').removeClass("on");
	$('#loading_anim').addClass("off");
	// debloque toutes les checkboxes
	$('#box1').attr('disabled',0);
	$('#box2').attr('disabled',0);
	$('#box3').attr('disabled',0);
	$('#box4').attr('disabled',0);
	$('#box5').attr('disabled',0);
	
}

function refresh_proj(id)
{				
	// on coche toutes les cases si on a coché tous
	if(id == 'box1'){
		
		if($('#box1').attr('checked')) {
			$('#box2').attr('checked',1);
			$('#box3').attr('checked',1);
			$('#box4').attr('checked',1);
			$('#box5').attr('checked',1);
		}else { // on decoche toutes les cases si on a decoché tous
			$('#box2').attr('checked',0);
			$('#box3').attr('checked',0);
			$('#box4').attr('checked',0);
			$('#box5').attr('checked',0);
		}
	}
	
	// si toutes les cases sont cochées on coche tous
	if( $('#box2').attr('checked') && $('#box3').attr('checked') && $('#box4').attr('checked') && $('#box5').attr('checked') ) {		
		$('#box1').attr('checked',1);		
	} else $('#box1').attr('checked',0); // toutes les cases ne sont pas cochées on decoche tous
	
	var cat = [];
	
	if( $('#box2').attr('checked') ) cat.push('sante');
	if( $('#box3').attr('checked') ) cat.push('habitat');
	if( $('#box4').attr('checked') ) cat.push('education');
	if( $('#box5').attr('checked') ) cat.push('equipements');
			
	// appel ajax			
	if (cat == '') $('#projet_list').html('');
	else {
		// affiche le loading
		$('#loading_anim').removeClass("off");
		$('#loading_anim').addClass("on");
		// bloque toutes les boxes
		$('#box1').attr('disabled',1);
		$('#box2').attr('disabled',1);
		$('#box3').attr('disabled',1);
		$('#box4').attr('disabled',1);
		$('#box5').attr('disabled',1);
		
		refresh_ajax(cat);
	}
}

function refresh_ajax(cat)
{		
	var i;
	var resultat='';
		
	$.ajax({
	    url: '../category/projets/',
	    type: 'POST',	  
	    data: "categories="+cat,  
	    dataType: "html",
	    timeout: 3000,	    
	    error: function(){	    
//	    	alert('ajax error');	
	        refresh_ajax(cat);
	    },
	    success: function(result){	    
				$('#projet_list').html(result);
				display_projects();		        
	    }
	});					
}

/*  Projets reliés - Page Single   */

function init_related()
{	
	$(function(){
		$("#projets-relies ul li").hover(function (e) { 
		
			$("#projets-relies").append("<div id='infobulle'><h3>Info Bulle Titre</h3><p>Description</p></div>");
	    		$("#infobulle").html($(this).children("div.infos").html());
	    		$("#infobulle")
	     			.css("left", (e.pageX+10) +"px")
	     			.css("top", (e.pageY+10) +"px")
	     			.fadeIn('fast');
	   	},function(){
			//alert("out");
//			$("#infobulle").fadeOut('fast');
			$("#infobulle").remove();
//			.css("display", "none");
			//$("#tooltip").fadeOut('fast');
		});
		
			
		$("#projets-relies ul li").mousemove(function(e){
			$("#infobulle")
	     			.css("left", (e.pageX+10) +"px")
	     			.css("top", (e.pageY+10) +"px");
		});				    	   	
	});			
}

