/**
 * @author monteleonevalentin
 */

 $('document').ready(function(){
 	

	// CONTOLE SI MAC OU PC
	if (BrowserDetect.OS == 'Mac') {
		if (BrowserDetect.browser == 'Firefox') {
			erreurIE();
		}
	}
	
	//PRELOADER DIMAGES///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	jQuery.fn.onImagesLoaded = function(_cb) { 
		  return this.each(function() {
		 
		    var $imgs = (this.tagName.toLowerCase()==='img')?$(this):$('img',this),
		        _cont = this,
		            i = 0,
		    _done=function() {
		      if( typeof _cb === 'function' ) _cb(_cont);
		    };
		 
		    if( $imgs.length ) {
		      $imgs.each(function() {
		        var _img = this,
		        _checki=function(e) {
		          if((_img.complete) || (_img.readyState=='complete'&&e.type=='readystatechange') )
		          {
		            if( ++i===$imgs.length ) _done();
		          }
		          else if( _img.readyState === undefined ) // dont for IE
		          {
		            $(_img).attr('src',$(_img).attr('src')); // re-fire load event
		          }
		        }; // _checki \\
		 
		        $(_img).bind('load readystatechange', function(e){_checki(e);});
		        _checki({type:'readystatechange'}); // bind to 'load' event...
		      });
		    } else _done();
		  });
		};
	
 	
	//DEBUT///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	


	/*
// CACHE LE CONTENU EN TROP
			$('#action').hide();
			$('#actualite').hide();
			$('#magasin').hide();
			$('.surimpression').hide();
			
	
	
	//DECOUVRE MAGASIN
			 $('#magasin_btn').hover(function(){		
					$('#magasin').fadeIn(200).show()
				
			});
		
	//DECOUVRE ACTION
			 $('#action_btn').hover(function(){		
					$('#actualite').fadeIn(200).show()
				
			});
			
			//DECOUVRE ACTION
			 $('#action_btn').hover(function(){		
					$('#action').fadeIn(200).show()
				
			});
*/
		
		homeNewsOver();
		
		// DECOUVRIR LE MAGASIN	
		function homeNewsOver(){
			$('#homeNews img').hover(function() {
				// opacity :
				$(this).css('opacity', '0');
			}, function() {
				$(this).css('opacity', '1');
			});
		}


		
	//HOME///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	
	
	    // HOVER HOME
		$('h2').hover(function(){
				var nomImage = $(this).find('img').attr('src'); //cherche le nom dans les balise img
				nomImage = nomImage.substring(0, nomImage.length - 4); // supprime les 4 dernier caractères
				$(this).find('img').attr({
					'src': nomImage + '_over.png'
				}); // fait apparaitre la seconde image
				// faire apparaitre le titre
				$(this).fadeIn('800');
				
		}, function(){ 
				var nomImage = $(this).find('img').attr('src');
				nomImage = nomImage.substring(0, nomImage.length - 9);
				$(this).find('img').attr({
					'src': nomImage + '.png'
				});
				
			// faire apparaitre le titre
	
		})
	
	//ACUTALITE//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
		// LANCEMENT FONCTION
		actualiteGlisse();
		actualiteCache();
		magasinCache();
			
		// DECOUVRIR L'ACTION
			function actualiteGlisse(){
				$('#actualite_btn').click(function(){
						$('#actualite_btn').hide();	
				});
			}
		
		// DECOUVRIR LE MAGASIN	
		function actualiteCache(){
			$('#action_btn').click(function(){
					$('#actualite_btn').show();
						
			});
		}
		
		// DECOUVRIR LE MAGASIN	
		function magasinCache(){
			$('#magasin_btn').click(function(){
				$('.small_menu img').fadeIn(200).show()
				$('.content_second').hide()
				$('.info_second').hide()
				$('.info_first').hide()
				$('.content_first').hide()
				$('.info_third').hide()
				$('.content_third').hide()
				$('.content_first').hide()
				$('.info_first').fadeIn(100).hide()
				menu_reviens_enplace()
			});
		}
			
		
		
	//MAGASIN///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
		// CACHE LE CONTENU EN TROP
			$('.trait').hide();
			$('.content_second').hide();
			$('.info_second').hide();
			$('.info_first').hide();
			$('.content_first').hide();
			$('.info_third').hide();
			$('.content_third').hide();
	
		// LANCEMENT FONCTION
			var active = true; 
 			acceuilGlisse();
			acceuilGlisse_first();
			acceuilGlisse_second();
			acceuilGlisse_third();
			first();
			second();
			third();
			
			
			
		// DECOUVRIR LE MAGASIN	
			function acceuilGlisse_first(){
				$('#decouvrir_le_magasin').click(function(){
					if (active == true) {
						content_first()
						magasinSecondaryWithe()
						info_first()
						active = false
						$('.small_menu').stop().animate({
							width: "147px"
						}, 800);
					}	
				});
			}
			
			
			//REBOUGE LE MENU
			function menu_reviens_enplace(){
				$('.small_menu').stop().animate({
						width: "545px"
					}, 800);
					active = true
			}
			
			// DECOUVRIR LE MAGASIN	IMAGE
			function acceuilGlisse(){
				$('.small_menu').click(function(){
					if (active == true) {
						content_first()
						magasinSecondaryWithe()
						info_first()
						active = false
						$('.small_menu').stop().animate({
							width: "147px"
						}, 800);
					}	
				});
			}
			
			
			// LIEN
			function first(){
				$('#decouvrir_le_magasin').click(function(){
					if (active == false) {
						$('.trait').hide()
						$('.content_second').fadeIn(100).hide()
						$('.info_second').fadeIn(100).hide()
						$('.info_first').fadeIn(100).hide()
						$('.content_first').fadeIn(100).hide()
						$('.info_third').fadeIn(100).hide()
						$('.content_third').fadeIn(100).hide()
						$('.content_first').fadeIn(200).show()
						$('.info_first').fadeIn(200).show()
						$('.trait').fadeIn(200).show()
						$('.content_first p').fadeIn(200).show()
						$('.small_menu img').hide()
						content_fondgris()
					}	
				});
			}
			
			// CONTENT_FIRST ARRIVE
			function content_first(){
				$('.content_first').show()
				$('.trait').fadeIn('slow').show()
			}
			
			
			// INFO_FIRST ARRIVE
			function info_first(){
				$('.info_first').fadeIn('slow').show()
				$('.trait').fadeIn('slow').show()
			
			}
			
		
			// REMTE LE FOND GRIS SOUS LE TEXT
			function content_fondgris(){
				var id=$('#decouvrir_le_magasin').attr('id'); // récup l'id
				if ($('#linksImg').attr('alt') != id) { // si le alt est différent (c'est pas le même lien que l'on survol)
					$('#linksImg').fadeOut(200, function(){ // on execute le fadeOut
						$('#linksImg img').attr({ // quand le fadeOut est terminé on change l'attribut src et alt
							src: '../images/content/magasin/photo/vign_' + 'default' + '.jpg',
							alt: 'default'
						}) ;
						$('#linksImg').show(); // on execute le fade In
						$('.content_first p').fadeIn(200).show()
					});
				}
			}
		
		
		
		
		// DECOUVRIR PLAN D'ACCES	
			function acceuilGlisse_second(){
				$('#plandacces').click(function(){
					if (active == true) {
						content_second()
						magasinSecondaryWithe()
						info_second()
						active = false
						$('.small_menu').stop().animate({
							width: "147px"
						}, 800);
					}
				});			
				
			}
		
		// LIEN
			function second(){
				$('#plandacces').click(function(){
					if (active == false) {
						$('.trait').hide();
						$('.content_second').fadeIn(100).hide()
						$('.info_second').fadeIn(100).hide()
						$('.info_first').fadeIn(100).hide()
						$('.content_first').fadeIn(100).hide()
						$('.info_third').fadeIn(100).hide()
						$('.content_third').fadeIn(100).hide()
						$('.content_first p').fadeIn(100).hide()
						$('.content_second').fadeIn(200).show()
						$('.info_second').fadeIn(200).show()
						$('.trait').fadeIn(200).show()
						$('.small_menu img').hide()
					}	
				});
			}
			
			
					// CNOTENT_FIRST ARRIVE
						function content_second(){
							$('.content_second').show()
							$('.trait').fadeIn('slow').show()
						}
					
					
					// INFO_FIRST ARRIVE
						function info_second(){
							$('.info_second').fadeIn('slow').show()
							$('.trait').fadeIn('slow').show()
						}	
		
		// DECOUVRIR HORAIRE	
			function acceuilGlisse_third(){
					$('#horaire').click(function(){
						if (active == true) {
							content_third()
							magasinSecondaryWithe()
							info_third()
							active = false
							$('.small_menu').stop().animate({
								width: "147px"
							}, 800);
						}
					});
			}
			
			// LIEN
			function third(){
				$('#horaire').click(function(){
					if (active == false) {
						$('.trait').hide();
						$('.content_second').fadeIn(100).hide()
						$('.info_second').fadeIn(100).hide()
						$('.info_first').fadeIn(100).hide()
						$('.content_first').fadeIn(100).hide()
						$('.info_third').fadeIn(100).hide()
						$('.content_third').fadeIn(100).hide()
						$('.content_first p').fadeIn(100).hide()
						$('.content_third').fadeIn(200).show()
						$('.info_third').fadeIn(200).show()
						$('.trait').fadeIn(200).show()
						$('.small_menu img').hide()
()
					}	
				});
			}
		
			
					// CNOTENT_FIRST ARRIVE
						function content_third(){
							$('.content_third').show()
							$('.trait').fadeIn('slow').show()
						}
					
					
					// INFO_FIRST ARRIVE
						function info_third(){
							$('.info_third').fadeIn('slow').show()
							$('.trait').fadeIn('slow').show()
						}	
		
				
		// ACCEUIL DEVIENT BLANC
			function magasinSecondaryWithe(){
				$('.small_menu img').fadeOut('slow')
			}	
				
				
	//GALLERIE///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				

		$('.photo a').mouseenter(function(){ // au survol
		
		
		$('.content_first p').die();

		var id=$(this).attr('id'); // récup l'id
		if ($('#linksImg').attr('alt') != id) { // si le alt est différent (c'est pas le même lien que l'on survol)
 			
			$('#linksImg').show(200, function(){ // on execute le fadeOut
				$('#linksImg img').attr({ // quand le fadeOut est terminé on change l'attribut src et alt
					src: '../images/content/magasin/photo/vign_' + id + '.jpg',
					alt: id
					
				}) ;
				 $('#linksImg').onImagesLoaded(function(_img){
				    $(_img).show();
				  });

				
				$('.content_first p').hide();
				
			});
			
		}
		});
		
			
		
	//ACTION_nd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
		// CACHE LE CONTENU EN TROP
			$('.trait_nd').hide();
			$('.content_second_nd').hide();
			$('.info_second_nd').hide();
			$('.info_first_nd').hide();
			$('.content_first_nd').hide();
			$('.info_third_nd').hide();
			$('.content_third_nd').hide();
	
		// LANCEMENT FONCTION
			var active_nd = true; 
 			acceuilGlisse_nd();
			acceuilGlisse_first_nd();
			acceuilGlisse_second_nd();
			acceuilGlisse_third_nd();
			first_nd();
			second_nd();
			third_nd();
			
			
			
		// DECOUVRIR LE MAGASIN	
			function acceuilGlisse_first_nd(){
				$('#decouvrir_le_magasin_nd').click(function(){
					if (active_nd == true) {
						content_first_nd()
						magasinSecondaryWithe_nd()
						info_first_nd()
						active_nd = false
						$('.small_menu_nd').stop().animate({
							width: "147px"
						}, 800);
					}	
				});
			}
			
			
			// DECOUVRIR LE MAGASIN	IMAGE
			function acceuilGlisse_nd(){
				$('.small_menu_nd').click(function(){
					if (active_nd == true) {
						content_first_nd()
						magasinSecondaryWithe_nd()
						info_first_nd()
						active_nd = false
						$('.small_menu_nd').stop().animate({
							width: "147px"
						}, 800);
					}	
				});
			}
			
			
			// LIEN
			function first_nd(){
				$('#decouvrir_le_magasin_nd').click(function(){
					if (active_nd == false) {
						$('.trait_nd').hide();
						$('.content_second_nd').fadeIn(100).hide()
						$('.info_second_nd').fadeIn(100).hide()
						$('.info_first_nd').fadeIn(100).hide()
						$('.content_firs_ndt').fadeIn(100).hide()
						$('.info_third_nd').fadeIn(100).hide()
						$('.content_third_nd').fadeIn(100).hide()
						$('.content_first_nd').fadeIn(200).show()
						$('.info_first_nd').fadeIn(200).show()
						$('.trait_nd').fadeIn(200).show()
						content_fondgris_nd()
					}	
				});
			}
			
			// CONTENT_FIRST ARRIVE
			function content_first_nd(){
				$('.content_first_nd').show()
				$('.trait_nd').fadeIn('slow').show()
			}
			
			
			// INFO_FIRST ARRIVE
			function info_first_nd(){
				$('.info_first_nd').fadeIn('slow').show()
				$('.trait_nd').fadeIn('slow').show()
			
			}
			
			
			
			// REMTE LE FOND GRIS SOUS LE TEXT
			function content_fondgris_nd(){
				var id=$('#decouvrir_le_magasin_nd').attr('id'); // récup l'id
				if ($('#linksImg_nd').attr('alt') != id) { // si le alt est différent (c'est pas le même lien que l'on survol)
					$('#linksImg_nd').fadeOut(200, function(){ // on execute le fadeOut
						$('#linksImg_nd img').attr({ // quand le fadeOut est terminé on change l'attribut src et alt
							src: '../images/content/magasin/photo/vign_' + 'default' + '.jpg',
							alt: 'default'
						}) ;
						$('#linksImg_nd').show(); // on execute le fade In
						$('.content_first_nd p').fadeIn(200).show()
					});
				}
			}
			
					
		// DECOUVRIR PLAN D'ACCES	
			function acceuilGlisse_second_nd(){
				$('#plandacces_nd').click(function(){
					if (active_nd == true) {
						content_second_nd()
						magasinSecondaryWithe_nd()
						info_second_nd()
						active_nd = false
						$('.small_menu_nd').stop().animate({
							width: "147px"
						}, 800);
					}
				});			
				
			}
		
		// LIEN
			function second_nd(){
				$('#plandacces_nd').click(function(){
					if (active_nd == false) {
						$('.trait').hide();
						$('.content_second_nd').fadeIn(100).hide()
						$('.info_second_nd').fadeIn(100).hide()
						$('.info_first_nd').fadeIn(100).hide()
						$('.content_first_nd').fadeIn(100).hide()
						$('.info_third_nd').fadeIn(100).hide()
						$('.content_third_nd').fadeIn(100).hide()
						$('.content_second_nd').fadeIn(200).show()
						$('.info_second_nd').fadeIn(200).show()
						$('.trait_nd').fadeIn(200).show()
					}	
				});
			}
			
			
					// CNOTENT_FIRST ARRIVE
						function content_second_nd(){
							$('.content_second_nd').show()
							$('.trait_nd').fadeIn('slow').show()
						}
					
					
					// INFO_FIRST ARRIVE
						function info_second_nd(){
							$('.info_second_nd').fadeIn('slow').show()
							$('.trait_nd').fadeIn('slow').show()
						}	
		
		// DECOUVRIR HORAIRE	
			function acceuilGlisse_third_nd(){
					$('#horaire_nd').click(function(){
						if (active_nd == true) {
							content_third_nd()
							magasinSecondaryWithe_nd()
							info_third_nd()
							active_nd = false
							$('.small_menu_nd').stop().animate({
								width: "147px"
							}, 800);
						}
					});
			}
			
			// LIEN
			function third_nd(){
				$('#horaire_nd').click(function(){
					if (active_nd == false) {
						$('.trait_nd').hide();
						$('.content_second_nd').fadeIn(100).hide()
						$('.info_second_nd').fadeIn(100).hide()
						$('.info_first_nd').fadeIn(100).hide()
						$('.content_first_nd').fadeIn(100).hide()
						$('.info_third_nd').fadeIn(100).hide()
						$('.content_third_nd').fadeIn(100).hide()
						$('.content_third_nd').fadeIn(200).show()
						$('.info_third_nd').fadeIn(200).show()
						$('.trait_nd').fadeIn(200).show()
					}	
				});
			}
		
			
					// CNOTENT_FIRST ARRIVE
						function content_third_nd(){
							$('.content_third_nd').show()
							$('.trait_nd').fadeIn('slow').show()
						}
					
					
					// INFO_FIRST ARRIVE
						function info_third_nd(){
							$('.info_third_nd').fadeIn('slow').show()
							$('.trait_nd').fadeIn('slow').show()
						}	
		
				
		// ACCEUIL DEVIENT BLANC
			function magasinSecondaryWithe_nd(){
				$('.small_menu_nd img').fadeOut('slow')
			}	
				
				
	//GALLERIE_nd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				
		
		$('.photo_nd a').mouseenter(function(){ // au survol
	
		
		$('.content_first_nd p').die();

		var id=$(this).attr('id'); // récup l'id
		if ($('#linksImg_nd').attr('alt') != id) { // si le alt est différent (c'est pas le même lien que l'on survol)
 			
			$('#linksImg_nd').show(200, function(){ // on execute le fadeOut
				$('#linksImg_nd img').attr({ // quand le fadeOut est terminé on change l'attribut src et alt
					src: '../images/content/magasin/photo/vign_' + id + '.jpg',
					alt: id
				}) ;
				 $('#linksImg_nd').onImagesLoaded(function(_img){
				    $(_img).show();
				  });

				
				$('.content_first_nd p').hide();
				
			});
			
		}
		});
		
		
	
		
		
	//GENERAL///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	    // HOVER MENU PRINCIPAL
		$('#mainmenu li').hover(function(){
				var nomImage = $(this).find('img').attr('src'); //cherche le nom dans les balise img
				nomImage = nomImage.substring(0, nomImage.length - 4); // supprime les 4 dernier caractères
				$(this).find('img').attr({
					'src': nomImage + '_over.png'
				}); // fait apparaitre la seconde image
				// faire apparaitre le titre
				$(this).fadeIn('slow');
				
		}, function(){ 
				var nomImage = $(this).find('img').attr('src');
				nomImage = nomImage.substring(0, nomImage.length - 9);
				$(this).find('img').attr({
					'src': nomImage + '.png'
				});
				
			// faire apparaitre le titre
	
		})
		
		
	//CONTACT///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
	
	// CACHE LE HAUT
		$('#footer').animate({
			 marginBottom: "-250px"
		},1);
		

	// DESECNDRE INFO
	descendreInfo();
	
	
	// FN descend le div info à son margintop 0
		function descendreInfo() {
			$('#secondary_navig_contact').click(function() {
				$('#footer').stop().animate({
					 marginBottom: "0px"
				},1000, afficheContenu());
			});
			
			$('#acceuil').click(function() {
				$('#footer').stop().animate({
					 marginBottom: "0px"
				},1000, afficheContenu());
			});
	
			function afficheContenu() {
				remonterInfo();
			}
		}
		
		// FN monte le div info à son margintop -165
		function remonterInfo() {
			
			$('#footer').click(function() {
				$('#footer').stop().animate({
					 marginBottom: "-250px"
				},1000, descendreInfo());
			});
			
			$('#body').click(function() {
				$('#footer').stop().animate({
					 marginBottom: "-250px"
				},1000, descendreInfo());
			});
			
		
			
			function masqueContenu() {
				
				descendreInfo();
			}
		}


});


/**
 * Initialisation du erreur IE
 */

function erreurIE (){
		
		

/*
alert('you use a wrond navigator | ' + BrowserDetect.browser + ' | ' + BrowserDetect.version + ' | ' + BrowserDetect.OS);
*/



	$('.small_menu img').css({top: '-88px' });
	$('.small_menu_nd img').css({top: '-88px' });
	$('#actualite_btn').css({top: '-146px' });
	$('#footer').css({paddingBottom: '20px' });
	
}

