/* ---------------------------------------------------------------
	ACCUEIL
 --------------------------------------------------------------- */
function affichageAccueil() {
	// Mise en forme
	$('#menu_droite a').each( function(noeud){ $(this).removeAttr("style");	});
	$('#menu_gauche a').each( function(noeud){ $(this).removeAttr("style");	});
	$('#choix_menu_1').each( function(noeud){ $(this).removeAttr("style");	});

	var myAjax = $.ajax({
		url: 'ajax/accueil.php',
		type: 'POST',
		success: function(retour){$('#zone_contenu').html(retour);},
		complete: function(){
		}
	});
}
/* ---------------------------------------------------------------
	INSERTION DU CONTENU
 --------------------------------------------------------------- */
function affichageContenu(menu) {
	var myAjax = $.ajax({
		url: 'ajax/' + menu + '.php',
		type: 'POST',
		success: function(retour){
			$('#zone_contenu').html(retour);
			switch(menu){
				case "le_reseau": 
				$('#fml_region select').each( function(noeud){
					$(this).change(function(){
						var valeurId = $(this).attr('value');
						affichageContenu(valeurId)
					}); 
				});	
				break;
				case "store_interieur":
				$('#vignette a').each( function(noeud){
					$(this).click(function(){
						var valeurId = $(this).attr('id');
						affichageContenu(valeurId)
					}); 
				});	
				break;
				case "store_exterieur":
					$('#vignette a').each( function(noeud){
						$(this).click(function(){
							var valeurId = $(this).attr('id');
							affichageContenu(valeurId);
						}); 
					});	
				break;
				case "reference":
					$('#vignette a').each( function(noeud){
						$(this).click(function(){
							var valeurId = $(this).attr('id');
							affichageContenu(valeurId);
						}); 
					});	
				break;

				case "groupe":
					$("#groupe_reference").click(function(){affichageContenu("reference");}); 
					$("#groupe_prestation").click(function(){affichageContenu("prestation");}); 
					$("#groupe_reseau").click(function(){affichageContenu("le_reseau");}); 
				break;
				case "plan_site":
					$('#zone_plan_site a').each( function(noeud){
						$(this).click(function(){
							var valeurId = $(this).attr('plan');
							affichageContenu(valeurId);
						}); 
					});	
				break;
				case "contact":
					$("#fml_contact").validate({
						debug: true,
						rules: {
							secteur: { required: true },
							nom: { required: true },
							email: { email: true, required:true },
							fonction: { required: true }
							},				
						submitHandler: function(form) {
							var options = { 
								url: "ajax/trt_contact.php", type: 'post',	dataType: 'json',
								complete: function(){ // A MODIFIER
									affichageContenu('confirmation_contact');
								}
							}; 
							$("#fml_contact").ajaxSubmit(options); 
							return false; 
					   }
					});
				break;
			}
		}
	});
}
/* ---------------------------------------------------------------
	FONCTIONS A LANCER LORS DU CHARGEMENT DE LA PAGE
 --------------------------------------------------------------- */
$(document).ready(function(){
	// Affichage de l'accueil du site
	affichageAccueil();
	// Surveillance du logo pour retour accueil
	$("#retour_accueil").attr('onclick' ,'return false');
	$("#retour_accueil").focus(function() { $(this).blur(); } );
	$("#retour_accueil").click(affichageAccueil);
	// Surveillance du CARTE FRANCE
	$("#carte_click").attr('onclick' ,'return false');
	$("#carte_click ").focus(function() { $(this).blur(); } );
	$("#carte_click").click(function(){
		affichageContenu('le_reseau');
		$('#le_reseau').attr("style", "background-position: left bottom;color:#CC3333;");
	});
	
	// Surveillance menu haut
	$('#menu_haut a').each( function(noeud){
		$(this).attr('onclick' ,'return false');
		$(this).focus(function() { $(this).blur(); } );
		$(this).click( function(){
			$('#menu_droite a').each( function(noeud){ $(this).removeAttr("style");	});
			$('#menu_gauche a').each( function(noeud){ $(this).removeAttr("style");	});
			$('#choix_menu_1').each( function(noeud){ $(this).removeAttr("style");	});
			// Affichage du choix								   
			var valeurId = $(this).attr('id');
			affichageContenu(valeurId);		
		}); 
	});	
	// Surveillance menu bas
	$('#menu_bas a').each( function(noeud){
		$(this).attr('onclick' ,'return false');
		$(this).focus(function() { $(this).blur(); } );
		$(this).click( function(){
			$('#menu_droite a').each( function(noeud){ $(this).removeAttr("style");	});
			$('#menu_gauche a').each( function(noeud){ $(this).removeAttr("style");	});
			$('#choix_menu_1').each( function(noeud){ $(this).removeAttr("style");	});
			// Affichage du choix								   
			var valeurId = $(this).attr('id');
			affichageContenu(valeurId);		
		}); 
	});	
	// Surveillance du menu de gauche
	$('#menu_gauche a').each( function(noeud){
		$(this).attr('onclick' ,'return false');
		$(this).focus(function() { $(this).blur(); } );
		$(this).addClass("choix_ko");
				
		$(this).click( function(){
			// Mise en forme
			$('#menu_droite a').each( function(noeud){ $(this).removeAttr("style");	});
			$('#menu_gauche a').each( function(noeud){ $(this).removeAttr("style");	});
			$(this).attr("style", "background-position: left bottom;color:#FF9933;");
			$('#choix_menu_1').attr("style", "background-position: left bottom;color:#CC3333;");
			// Affichage du choix								   
			var valeurId = $(this).attr('id');
			affichageContenu(valeurId);		
		}); 
	});	
	// Surveillance du menu de droite
	$('#menu_droite a').each( function(noeud){
		$(this).attr('onclick' ,'return false');
		$(this).focus(function() { $(this).blur(); } );
				
		$(this).click( function(){
			// Mise en forme
			$('#menu_droite a').each( function(noeud){ $(this).removeAttr("style");	});
			$('#menu_gauche a').each( function(noeud){ $(this).removeAttr("style");	});
			$('#choix_menu_1').each( function(noeud){ $(this).removeAttr("style");	});
			$(this).attr("style", "background-position: left bottom;color:#CC3333;");
			// Affichage du choix								   
			var valeurId = $(this).attr('id');
			affichageContenu(valeurId);		
		}); 
	});	
});
// -------------------------------------------------------------