//CHARTON STYVEN
//2008

function Premiere(chaine){
			return chaine.substr(0,1).toUpperCase()+	chaine.substr(1,chaine.length).toLowerCase()		}
 
//alert(Premiere('dfEZRZSDGFSD4E'))

// INITIALISATION LORS DE L'OUVERTURE DU SITE
function init() {
	new Event.observe(window, "load", function () {
		$$(".btn").each(function(el) {
			new Event.observe(el, 'click', function(evt) {
				Event.stop(evt);
				appearBox(el, $("blank"), "contenant", "");
			});
			
			new Event.observe(el, 'mouseover', function(evt) {
                var nom_menu = (el.id).split("_");
				nom_menu = nom_menu[1];
                
				if(el.up().id != "mentionsLegales") {
                    el.previous().show();
                }
				//$("msgMenu").update(Premiere(nom_menu));
			});	
			
			new Event.observe(el, 'mouseout', function(evt) {
                if(el.up().id != "mentionsLegales") el.previous().hide();
				//$("msgMenu").update("");
			});
            
		});
		
		

		/*$$(".aff").each(function(el) {
			new Event.observe(el, 'click', function(evt) {
				Event.stop(evt);
				appearInfos();
			});
			
			new Event.observe(el, 'mouseover', function(evt) {
				var nom_menu = (el.id).split("_");
				nom_menu = nom_menu[1];
				$("msgMenu").update(nom_menu);
			});	
			
			new Event.observe(el, 'mouseout', function(evt) {
				$("msgMenu").update("");
			});
		});
		*/
		
		//Fermer une couche
		new Event.observe("fermer", 'click', function(evt) {
			Event.stop(evt);
			appearSelect();
			disappearBox($("blank"), "contenant");
		});
		
		//Fermer une couche
		new Event.observe("secondFermer", 'click', function(evt) {
			Event.stop(evt);
			appearSelect();
			disappearBox($("secondBlank"), "secondContenant");
		});
		
		//Fermer deux couches
		new Event.observe("retourAccueil", 'click', function(evt) {
			Event.stop(evt);
			appearSelect();
			disappearBox($("blank"), "contenant");
			disappearBox($("secondBlank"), "secondContenant");
		});
		
		//Gestion du contact
		$$(".contact").each(function(elt) {
			new Event.observe(elt, 'click', function(evt) {
				Event.stop(evt);
				loading("start");
				if ($("secondFermer").getStyle("display") != "none") $("secondFermer").hide();
				if ($("fermer").getStyle("display") != "none") $("fermer").hide();
				if ($("retourAccueil").getStyle("display") != "none") $("retourAccueil").hide();
				new Effect.toggle ($("contactBox"), 'slide',
					{
						afterFinish: function() {
							loading("stop");
							if ($("logoGrisContact")) $("logoGrisContact").appear();
						}
					}
				);
			});
			
			new Event.observe(elt, 'mouseover', function(evt) {
				//$("msgMenu").update(Premiere("contact"));
			});	
			
			new Event.observe(elt, 'mouseout', function(evt) {
				//$("msgMenu").update("");
			});
		});
		
		//Appel du formulaire de contact
		new Ajax.Updater("contactBox", "xhr/xhr_contact.php", {
				method: 'post',
				evalScripts: true
		});
		

		
	});
}

// GESTION DU CHARGEMENT/LOADER
function loading(mode) {
	if (mode == "start") {
		$("loader").update('<img alt="" id="imgLoader" src="media/site/images/loader.gif" />');
	} else if (mode == "stop") {
		$("loader").update("");
	}
}

// APPARITION DE LA PREMIERE COUCHE
function appearBox(el, monobjet, contenant, params) {
	if (monobjet.getStyle("display") == "none") {
		new Effect.Appear(monobjet,
			{
				duration: 0.5,
				beforeStart:function() {
					loading("start");
					disappearSelect();
					var monid = el.id;
					var xhr = monid.split("_");
					var url = "xhr/xhr_"+xhr[1]+".php";
					new Ajax.Updater(contenant, url, {
						method: 'post',
						parameters: params,
						evalScripts: true
					});
				},
				afterFinish:function() {
					loading("stop");
				}
			}
		);
	} else if (el.id == "picto_mentions") {
		if ($("secondBlank").getStyle("display") == "none") {
			new Ajax.Updater("contenant", "xhr/xhr_mentions.php", {
				method: 'post',
				parameters: params,
				evalScripts: true
			});
		} else {
			new Ajax.Updater("secondContenant", "xhr/xhr_mentions.php", {
				method: 'post',
				parameters: params,
				evalScripts: true
			});
		}
	} else if (el.id == "navEquipe") {
		if ($("secondBlank").getStyle("display") == "none") {
			new Ajax.Updater("contenant", "xhr/xhr_equipe.php", {
				method: 'post',
				parameters: params,
				evalScripts: true
			});
		} else {
			new Ajax.Updater("secondContenant", "xhr/xhr_equipe.php", {
				method: 'post',
				parameters: params,
				evalScripts: true
			});
		}
	}
}

// DISPARITION DE LA PREMIERE COUCHE
function disappearBox(monobjet, contenant) {
	if (monobjet.getStyle("display") != "none") {
		new Effect.Fade(monobjet,
			{
				duration: 0.5,
				beforeStart:function() {
					loading("start");
				},
				afterFinish:function() {
					loading("stop");
					$(contenant).update("");
				}
			}
		);
	}
}

// APPARITION DES INFOS SUR LA PAGE D'ACCUEIL
function appearInfos() {
	var monobjet = $("blabla");
	if (monobjet.getStyle("display") == "none") {
		new Effect.Appear(monobjet,
			{
				duration: 1.5
			}
		);

	}
}
	
//APPARITION DE TOUS LES SELECTS DU SITE
function appearSelect() {
	$$("select").each(function(el) {
		new Effect.Appear((el.ancestors())[0],
			{
				duration: 0.3
			});
	});
}

//DISPARITION DE TOUS LES SELECTS DU SITE
function disappearSelect() {
	$$("select").each(function(el) {
		new Effect.Fade((el.ancestors())[0],
			{
				duration: 0.3
			});
	});
}