$(document).ready(function(){	
	
	
	/* Comportement changement vignette dans fiche produit */
	$("#fiche-vignettes a").bind("click",function(event){
		$("#fiche-vignettes a").removeAttr("class");
		
		var maSource=$(this).attr("href");
		var maLegende=$(this).attr("title");
		
		$(this).attr("class","actif");
		
		$("#fiche-photo").attr("src",maSource);
		$("p.legende").html(maLegende);
		
		event.preventDefault();
	});
	
	$("div#recherche > form > fieldset > select").bind("change",function(event){
		$("#resultatRecherche").html('<div style="padding:55px 10px; text-align:center;"><img src="img/loader.gif" /></div>');
		var loading =  $("div#recherche > form").attr("title")+".php";
		var fields = $("div#recherche > form > fieldset > select").serializeArray();
		$("#resultatRecherche").load(loading,fields,function(){
			tb_init('#resultatRecherche a.thickbox');//pass where to apply thickbox
			imgLoader = new Image();// preload image
			imgLoader.src = tb_pathToImage;
		});
		
		event.preventDefault();
	});
	
	$("div#recherche > form").bind("submit",function(event){
		$("#resultatRecherche").html('<div style="padding:55px 10px; text-align:center;"><img src="img/loader.gif" /></div>');
		var loading =  $("div#recherche > form").attr("title")+".php";
		var fields = $("div#recherche > form > fieldset > select").serializeArray();
		$("#resultatRecherche").load(loading,fields,function(){
			tb_init('#resultatRecherche a.thickbox');//pass where to apply thickbox
			imgLoader = new Image();// preload image
			imgLoader.src = tb_pathToImage;
		});
		
		event.preventDefault();
	});
	
	
		
	
	/* Comportement Rollover avec class="rollover" et actif */
	attachRollOverEvent("img.rollover");
	attachActif("img.actif");
	
});

/* Comportement Rollover avec class="rollover" */
attachRollOverEvent = function(imageId){
	$(imageId).mouseover( function(){ $(this).attr("src", $(this).attr("src").replace('.','_roll.')) } );
	$(imageId).mouseout( function(){ $(this).attr("src", $(this).attr("src").replace('_roll','')) } );
}

/* Change image pour les "actif" */
attachActif = function(imageId){
	$(imageId).attr("src", $(imageId).attr("src").replace('.','_actif.'));
}

