function init(){
    sel_projet();
	fct_form();
	fct_liens();
}    

function sel_projet(){
    $(".bloc_projet").mouseenter( 
		function (){ 
			$(this).addClass("bloc_selection", 'slow');
			/*$(this).BgImageTransition( 'template/2010/images/fd_selection.png' );*/
		}
 	);
	 
	$(".bloc_projet").mouseleave( 
		function (){ $(this).removeClass("bloc_selection",'slow');
		} 
	);
}

function fct_form(){
	$("#form_type input:checkbox").click(
		function (){ change_projet(); }
	);
	
	$("#form_type").submit(function () { return false; });
}

function fct_liens(){
	//var valeur = '&type=';
	var valeur = '/';
	var nb = 0;
	$("#form_type input:checkbox").each(function(index) {
		if(this.checked){
			valeur += this.name + '_';
			nb = nb + 1;
		}
		
	});
	
	if(!nb){ return false; }
	valeur = valeur.substr(0,valeur.length-1);

	$("a[rel='projet']").each(function(i){
		$(this).attr("href", this.href+valeur);
	});
}

function change_projet(){
	
	var valeur = '';
	$("#form_type input:checkbox").each(function(index) {
		if(this.checked){
			valeur += this.name + '_';
		}
	});
	
    $.ajax({
        type: "POST",
		data: "type="+valeur,
		//data: "/"+valeur,
        url: "/template/2010/pages/ajax_projet.php",
        beforeSend: function (){
            chargement();
        },
        success: function (msg){
            afficheResult(msg);
			fct_liens();
        }
    });
}

function afficheResult(objets){
   $('#projets_liste').html(objets);
}

function chargement(objets){
    $('#projets_liste').html('<img src="/template/2010/images/separation_projet.png" /><div class="bloc_projet" align="center" style="height:500px"><img src="/template/2010/images/loader.gif" /></div>');
}

function gestionReponse(xhr){
    if (xhr.status == 200){
       alert(xhr.responseText);
    }else{
        alert(xhr.status);
    }
}


$(document).ready( init );
