window.addEvent('domready', function() {
	var menu = $('menu');
	var logo= $('logo');
	var trait = $$('.trait');
	var header = $('header');
	var header_fondu = header.get('tween', {property: 'opacity', duration: 'long', link:'chain'});
	
	var anim_menu = menu.get('tween', {duration: 'short', transition: Fx.Transitions.Quart.easeInOut});
	header_fondu.start(100);
	setTimeout("$('menu').tween('margin-top','-100px');",1000);
	
	anim_menu.addEvent('complete', function (){
			
			var anim_logo = logo.get('tween', {duration: 'long', transition: Fx.Transitions.Elastic.easeOut});
			logo.tween('margin-top','-300px');
			
			anim_logo.addEvent('complete', function (){
				var anim_menu2 = menu.get('tween', {duration: 'long', transition: Fx.Transitions.Quart.easeOut});
				trait.get('tween', {duration: 'long', transition: Fx.Transitions.Quart.easeOut});
				trait.tween('margin-bottom','-5px');
				menu.tween('margin-top', '-40px');
				anim_menu2.addEvent('complete', function (){
					var anim_menu3 = menu.get('tween', {duration: 'short', transition: Fx.Transitions.Cubic.easeIn});
					trait.get('tween', {duration: 'short', transition: Fx.Transitions.Cubic.easeIn});
					trait.tween('margin-bottom','15px');
					menu.tween('margin-top', '-117px');			
				
					anim_menu3.addEvent('complete', function (){	
						header.get('tween', {duration: 'long', transition: Fx.Transitions.Elastic.easeOut});	
						var anim_menu4 = menu.get('tween', {duration: 'short', transition: Fx.Transitions.Elastic.easeOut});
						var anim_logo2 = logo.get('tween', {duration: 'long', transition: Fx.Transitions.Elastic.easeOut});
						header.tween('margin-top', '10px');	
						logo.tween('margin-top','0px');
						menu.tween('margin-top', '195px');
						anim_menu4.addEvent('complete', function (){
							demarrage();
						});
						
					});
				});
			});
										
					
			
	});
function demarrage(){								   
	($$('#menu li .conteneur')).each(function (conteneur, numero) {
		//definition des varaiables
		var menu = $('menu');
		var menu_li = conteneur.getParent();
		var en_tete = menu_li.getFirst();
		var title = en_tete.getFirst();
		var trait = en_tete.getLast();
		var contenu = conteneur.getFirst();
		//definition des tween 
		trait.set('tween', {duration: 'short'});
			menu.set('tween', {duration: 'short'});
			contenu.set('tween', {duration: 'short'});
		var visite;
		
		//Animation survol des éléments du menu
			
		// Animation lorsque click sur un élément du menu
		(menu_li).addEvent('mouseenter', function() {
				trait.tween('margin-top','-7px');  // Au survol du li le trait prend tel properties
		});		
		(menu_li).addEvent('mouseleave', function() {
			trait.tween('margin-top','-24px'); // Au plus survol du li le trait prend tel properties
		});
		
		
		
		(en_tete).addEvent('click', function () {
			//Initialisation des differents li
			$$('.contenu').setStyle('display','none');
			$$('.title').setStyle('color', '#444444');
			$$('.trait').setStyle('background-color', '#444444');
			$$('.trait').tween('margin-top','-24px');
			$$('#menu li').addEvent('mouseleave', function(){
				$$('.trait').tween('margin-top','-24px');
				trait.tween('margin-top','-7px');
			});
			$$('.conteneur').tween('height', '0px');
			//réglage de résolution
			if((screen.height) >940){
				
				menu.tween('margin-top','30px');
			}else{
				menu.tween('margin-top','-20px'); 
			}
			if((screen.height) < 810){
				var header = $('header');
				var anim_header = header.get('tween', {duration: 'short'} );
				header.tween('margin-top', '-80px');
				$('header').addEvent('mouseenter', function () {
					header.tween('margin-top', '10px');
				});
				$('header').addEvent('mouseleave', function () {
					header.tween('margin-top', '-80px');
				});
				
			}
			//Modification du li cliqué
			
			conteneur.tween('height', '320px');
			afficher_contenu.delay(500);
			
			title.setStyle('color', '#F5467A');
			trait.setStyle( 'background-color', '#F5467A');
			trait.tween('margin-top','-7px');
			
			(menu_li).addEvent('mouseleave', function() {
				trait.tween('margin-top','-7px'); // Au plus survol du li le trait prend tel properties
			});
			$('logo').addEvent('click', function () {
				$$('.contenu').setStyle('display','none');
				$$('.title').setStyle('color', '#444444');
				$$('.trait').setStyle('background-color', '#444444');
				$$('.trait').tween('margin-top','-24px');
				$$('.conteneur').setStyle('height','0px');
				$('menu').tween('margin-top', '195px');
				(menu_li).addEvent('mouseenter', function() {
					trait.tween('margin-top','-7px');  // Au survol du li le trait prend tel properties
				});		
				(menu_li).addEvent('mouseleave', function() {
					trait.tween('margin-top','-24px'); // Au plus survol du li le trait prend tel properties
				});
			});
		});
							   
		
		function afficher_contenu (){
			contenu.tween('display','block');
			afficher_slide(contenu);
		}
	});				 
							 
}
							 
});


function afficher_slide (contenu){
		var texte = contenu.getLast();
		var sous_menu = contenu.getFirst();
		$$('.mesSlide').set('tween', {duration: 'normal'}); 
		menu_selec=(contenu.getParent()).getParent();
		
		
		if($('bio')===menu_selec || $('competence')===menu_selec){	
		
		sous_menu.getChildren().each(function (sous_menu_li, num){
			$$('.mesSlide').setStyle('margin-top','0px');
			sous_menu.getChildren().setStyle('cursor', 'pointer');	
			init_bio();
			sous_menu_li.addEvent('click', function (){
				sous_menu.getChildren().setStyle('color', '#444444');
				margin = (num+1)*(-180);
				
				$$('.mesSlide').tween('margin-top', margin);
				sous_menu_li.tween('color','#F5467A');
							
				//survol et couleur des titre de contenu
				var apres = sous_menu_li.getAllNext();
				var avant = sous_menu_li.getAllPrevious();
				var other_li = apres.extend(avant);
				other_li.each(function (li){
					li.addEvent('mouseenter', function() {
						li.setStyles({'color': '#C0C0C0', 'cursor': 'pointer'}); // Au survol du li le trait prend tel properties
					});		
					li.addEvent('mouseleave', function() {
						li.setStyle('color', '#444444'); // Au plus survol du li le trait prend tel properties
					});
				});	
				sous_menu_li.addEvent('mouseenter', function() {
					sous_menu_li.setStyle('color', '#F5467A');
					sous_menu_li.setStyle('cursor', 'default');// Au survol du li le trait prend tel properties
				});	
				sous_menu_li.addEvent('mouseleave',function() {
					sous_menu_li.setStyle('color','#F5467A');
				});
				sous_menu_li.setStyle('color', '#444444'); 
			});
			sous_menu.getChildren().setStyle('color', '#444444');
			
		});
		}
		
		if ($('realisation')===menu_selec){ 
			var bloc_realisation = sous_menu.getChildren();
			init_bloc_global();
			$$('.texte_retour').each(function (retour){
					var btn = retour.getParent();
					btn.addEvent('mouseenter', function () {
						btn.tween('text-indent', '0px');
						retour.get('tween', {property: 'opacity', duration: 'short', link:'chain'}).start(100);
					});
					btn.addEvent('mouseleave', function () {
						btn.tween('text-indent', '60px');
						retour.get('tween', {property: 'opacity', duration: 'short', link:'chain'}).start(0);
			
					});						
											
											
			});
			bloc_realisation.each(function (bloc_image, num){
					var id = num % 3;
					
					var destroy = function () {
						var apres = bloc_image.getAllNext();
						var avant = bloc_image.getAllPrevious();
						var other_bloc = apres.extend(avant);
						
						
						other_bloc.each(function (bloc_no_hover){
							var bloc_fondu = bloc_no_hover.get('tween', {property: 'opacity', duration: 'short', link:'chain'});
							bloc_fondu.start(0);
							bloc_fondu.addEvent('complete', function (){
								var deplacement_bloc = bloc_image.get('tween', {duration: 'normal', link:'chain'});
								if (num ===3){
									bloc_image.tween('margin-top', '-150px');
								}else if(num===4){
									bloc_image.tween('margin', '-150px 75px 20px -207px');								
								}else if(num===5){
									bloc_image.tween('margin', '-150px 75px 20px -413px');
								}else if(num===2){
									bloc_image.tween('margin-left', '-413px');
								}else if(num===1){
									bloc_image.tween('margin-left', '-207px');
								}else if(num===0){
									$(''+num+'').get('tween', {property: 'opacity', duration: 'normal'}).start(100);
								}
								deplacement_bloc.addEvent('complete', function (){
									$(''+num+'').get('tween', {property: 'opacity', duration: 'normal'}).start(100);
									
								});
								$('bloc_retour').setStyle('display', 'block');
							});
						}); 
						
						
						$$('.bouton_retour').addEvent('click', function (){
							init_bloc(num, id, bloc_image, other_bloc, destroy);
						});
						
						$('bloc_retour').addEvent('click', function (){
														   
							init_bloc(num, id, bloc_image, other_bloc, destroy);
							
						});
						
					};
				bloc_image.addEvent('click', destroy);
				
					
					
			});
			
		
		
		}
		if ($('contact')===menu_selec){
			document.formulaire.nom.addEvent('keyup', function() {
				$('label_nom').innerHTML = document.formulaire.nom.value; 													 
			});
			document.formulaire.email.addEvent('keyup', function() {
				$('label_email').innerHTML = document.formulaire.email.value; 													 
			});
			
			//$$('.champ_contact input')	
			
		}
		
		
		
		
		function init_bloc(num, id, bloc_image, other_bloc, destroy) {
				var texte_fondu = $(''+num+'').get('tween', {property: 'opacity', duration: 'short'});
				texte_fondu.start(0);
				$('bloc_retour').setStyle('display', 'none');
				texte_fondu.addEvent('complete', function (){
					var deplacement_bloc_retour = bloc_image.get('tween', {duration: 'normal', link:'chain'});
					if (num===3){
						bloc_image.tween('margin', '0px 75px 20px 0px');
					}else if(num===4){
						bloc_image.tween('margin', '0px 75px 20px 0px');
					}else if(num===5){
						bloc_image.tween('margin', '0px 75px 20px 0px');
					}else if(num===2){
						bloc_image.tween('margin-left', '0px');
					}else if(num===1){
						bloc_image.tween('margin-left', '0px');
					}else if(num===0){
						bloc_image.tween('margin-left', '0px');
					}
					deplacement_bloc_retour.addEvent('complete', function (){
						other_bloc.each(function (bloc_pas_hover){
							bloc_pas_hover.setStyle('margin', '0px 75px 20px 0px');
							bloc_pas_hover.get('tween', {property: 'opacity', duration: 'normal'}).start(100);
							bloc_image.get('tween', {property: 'opacity', duration: 'normal'}).start(100);
							
						}); 
					});				
				});
				
				
		}
		 
		function init_bloc_global(){
			$$('.texte_realisation').setStyle('visibility', 'hidden');
			$$('.image').setStyles({
					'margin' : '0px 75px 20px 0px',
					'visibility' : 'visible',
					'opacity' : '100'
			});
		}
		
		function init_bio(){
		
			$$('.sous_menu li').each(function (li){
				li.addEvent('mouseenter', function() {
					li.setStyles({'color': '#C0C0C0', 'cursor': 'pointer'}); // Au survol du li le trait prend tel properties
				});		
				li.addEvent('mouseleave', function() {
					li.setStyle('color', '#444444'); // Au plus survol du li le trait prend tel properties
				});
			});	
		
		}
		
		
		
		
	}
	
	
function verification_formulaire (){
	adresse = document.formulaire.email.value;
	var place = adresse.indexOf("@",1);
	var point = adresse.indexOf(".",place+1);
	if ((place >! -1)&&(adresse.length >!2)&&(point > 1)){
		if(document.formulaire.nom.value == "") {
  			$('label_nom').innerHTML = "votre nom";
  		return false;
		}
		if(document.formulaire.texte.value == "") {
			document.formulaire.texte.value = "Veuillez entrer votre message";
		return false;
 		}
		return(true);
	}else{
		$('label_email').innerHTML = "Votre email";
		document.formulaire.email.value="";
		return(false);
	}

}

function tween_contact(){
	$('envoyer').tween('text-indent', '25px');
	$('envoyer').setStyle('background-position', 'left bottom');

	$('envoyer').addEvent('mouseleave', function () {
		$('envoyer').tween('text-indent', '-300px');
		$('envoyer').setStyle('background-position', 'left top');
	});
		
}
