/* SALUT ALEX / ANTOINE ! */



$(document).ready(function(){ 

		 // $("img").lazyload({
		 // placeholder : "/wp-content/uploads/scripts/lazyload.gif",
		 // effect : "fadeIn",
		 // placeholder : "http://www.nicolasmillot.net/site/wp-content/themes/ubertext/gfx/placeholder.png",
		 // });

		// Définition des vitesse de changement de l'opacité et de scroll
		var vitesseop = 0;
		var vitessesl = 300;
		var opbasse = 0.25;
		
				$(".supercontent").children("p").children("img:last").addClass("last");
		

		
		


		// --
		

		// No Javascript
		
		$(".content").css({
				'overflow' : 'hidden',
		});
		

		
		// --

		
		// Apparition du footer
		
		$("#footer").click(function() {

			$("html, body").animate({scrollTop: 0}, vitessesl,function(){
			
			
			});
			

		})

		if(window.scrollY > 1){

			$("#footer").css({
					'display' : 'block'	
			});
			
		}else{

			$("#footer").css({
					'display' : 'none'
					});

		}

		$(document).scroll(function() {

				if(window.scrollY > 1){
				
					$("#footer").css({
							'display' : 'block'
					});
					
				}else{
				
					$("#footer").css({
							'display' : 'none'
					});

				}
		})
		
		// --
		
		
		// Gestion de la hauteur en fonction du browser

		$("#spacer").css({
				'height' : screen.height/2,
				'position' : 'relative'
		});
		
		// --

		
		// Gestion de la largeur du contenu en fonction du browser 

		$(".content").each(function() {

				var pfirstimg = $(this).children(".supercontent").children("p").children("img:first").offset();
				var plastimg = $(this).children(".supercontent").children("p").children("img:last").offset();
				var wlastimg = $(this).children(".supercontent").children("p").children("img:last").width();
				var wbrowser = $("html, body").width();

				// $(this).children(".supercontent").children("p").children("img").animate({opacity: opbasse}, vitesseop, function() {
				

						$("img:first").addClass("active");
						
						
				// });
				
				$(this).children(".supercontent").css({
						'width' : plastimg.left-pfirstimg.left+wlastimg+wbrowser,
						'position' : 'relative'
				});

		});	
		
		// --
		
		
		// Navigation début / fin

		$(".cat-back").click(function() {
				var imgpos = $(this).parent(".cat-menu").parent(".infracontent").offset();
				var move = $(this).parent(".cat-menu").next(".content");
				var anchor = $(this).parent(".cat-menu").parent(".infracontent").children(".cat-anchor").attr("id");
				
				// alert((window.scrollY)+"    "+(imgpos.top-139))
				if((window.scrollY)==(imgpos.top-139)){
				
							
						$("img").removeClass("active");
						move.animate({scrollLeft: 0}, vitessesl*2, function(){
							$(this).children(".supercontent").children("p").children("img:first").addClass("active");
						})
						
						// $("img:not(.active)").animate({opacity: opbasse}, vitesseop);
						// move.children(".supercontent").children("p").children("img:first").animate({opacity: 1}, vitesseop);
				
				
				}else{
				
						$("html, body").animate({scrollTop: imgpos.top-139}, vitessesl, function() { 
						
									
								$("img").removeClass("active");
								move.animate({scrollLeft: 0}, vitessesl*2, function(){
									$(this).children(".supercontent").children("p").children("img:first").addClass("active");
									})
								// $("img:not(.active)").animate({opacity: opbasse}, vitesseop);
								// move.children(".supercontent").children("p").children("img:first").animate({opacity: 1}, vitesseop);
											
						});
				
				
				}
				
				

		})
		

		$(".cat-front").click(function() {
				var imgpos = $(this).parent(".cat-menu").parent(".infracontent").offset();
				var plastimg = $(this).parent(".cat-menu").next(".content").children(".supercontent").children("p").children("img:last").offset();
				var pfirstimg = $(this).parent(".cat-menu").next(".content").children(".supercontent").children("p").children("img:first").offset();
				var wlastimg = $(this).parent(".cat-menu").next(".content").children(".supercontent").children("p").children("img:last").width();
				var anchor = $(this).parent(".cat-menu").prev(".cat-anchor").attr("id");
				
				var move = $(this).parent(".cat-menu").next(".content");
				

				
				if((window.scrollY)==(imgpos.top-139)){
				
								
								$("img").removeClass("active");
								move.animate({scrollLeft: plastimg.left-pfirstimg.left}, vitessesl*2, function(){
								$(this).children(".supercontent").children("p").children("img:last").addClass("active");
								
								
								})
								
								// $("img:not(.active)").animate({opacity: opbasse}, vitesseop);
								
								// move.children(".supercontent").children("p").children("img:last").animate({opacity: 1}, vitesseop);
				
				
				
				}else{
				
						$("html, body").animate({scrollTop: imgpos.top-139}, vitessesl, function() { 
						
								
								$("img").removeClass("active");
								move.animate({scrollLeft: plastimg.left-pfirstimg.left}, vitessesl*2, function(){
								$(this).children(".supercontent").children("p").children("img:last").addClass("active");
								
								
								})
								// $("img:not(.active)").animate({opacity: opbasse}, vitesseop);
								
								// move.children(".supercontent").children("p").children("img:last").animate({opacity: 1}, vitesseop);
								
						});
				
				
				}


		})
		
		
		
		// --
		
		
		// Navigation par click
		 $(".content").children(".supercontent").children("p").children("img").click(function() {
		 
				 
				var pfirstimg = $(this).parent("p").children("img:first").offset();
				var plastimg = $(this).parent("p").children("img:last").offset();
				var wlastimg = $(this).parent("p").children("img:last").width();
				var wbrowser = $("html, body").width();
				var imgpos = $(this).offset();
				var wimg = $(this).width();
				var anchor = $(this).parent("p").parent(".supercontent").parent(".content").parent(".infracontent").children(".cat-anchor").attr("id");
						
				// alert((window.scrollY)+"    "+(imgpos.top-169))
			   if($(this).hasClass("active") ){
						var act = $(this);
					   var move = $(this).parent("p").parent(".supercontent").parent(".content")
					   
					   if((window.scrollY)==(imgpos.top-169)){
								if(act.hasClass("last") ){
										move.animate({scrollLeft: 0}, vitessesl*2, function(){
												$("img").removeClass("active");
												act.parent("p").children("img:first").addClass("active");
										
								
								
								});
								
								}else{
										move.animate({scrollLeft: imgpos.left-pfirstimg.left+wimg+10}, vitessesl, function(){
												$("img").removeClass("active");
												act.next("img").addClass("active");
										
										});
								
								
								
								
								
								};
					   
					   }else{
					   
								$("html, body").animate({scrollTop: imgpos.top-169}, vitessesl, function() {
								
										if(act.hasClass("last") ){
											
												move.animate({scrollLeft: 0}, vitessesl*2, function(){
														$("img").removeClass("active");
														act.parent("p").children("img:first").addClass("active");
												});
										
										}else{
																			 
											   move.animate({scrollLeft: imgpos.left-pfirstimg.left+wimg+10}, vitessesl, function(){
														$("img").removeClass("active");
														act.next("img").addClass("active");

											   });
										
										
										
										}
										
								
							   

									   
							   })
					   
					   
					   }

					   
					   
					   
			   }else{
			   
						var move = $(this).parent("p").parent(".supercontent").parent(".content");
						var imgprec = $(this);
			   

						// $(".top").animate({height: "150px"}, vitessesl, function(){
						
						
			   
						
						// $("img").not(this).animate({opacity: opbasse}, vitesseop)
						// $(this).animate({opacity: 1}, vitessesl)
					
					
						if((window.scrollY)==(imgpos.top-169)){
								
								
								move.animate({scrollLeft: imgpos.left-pfirstimg.left}, vitessesl, function(){
								
										imgprec.css({
												'cursor' : "w-resize",
										});
										$("img").removeClass("active");
										imgprec.addClass("active");
								
								});
						
						
						}else{
						
								$("html, body").animate({scrollTop: imgpos.top-169}, vitessesl, function() { 
								
										
										move.animate({scrollLeft: imgpos.left-pfirstimg.left}, vitessesl);
										imgprec.css({
												'cursor' : "w-resize",
										});
										$("img").removeClass("active");
										imgprec.addClass("active");
								


											
								});	
						
						}
					// })
				}
		 })
		 
		 // --
		 
		 
		 
		
		
		// Mouseover / mouseout
		 
		 
		$(".content").children(".supercontent").children("p").children("img").mouseover(function(e) {
				var imgpos = $(".content").children(".supercontent").children("p").children(".active").offset();
				
				var debimg = imgpos.top-window.scrollY;
				var chnimg = e.pageY-window.scrollY;
				var wimg = $(this).width();
				var himg = $(this).height();
				
				
				$(this).addClass("over");
				// $(this).animate({opacity: 1}, vitesseop);


				// if(chnimg-debimg<himg+1){
				
							// if(chnimg<debimg){
								
									// if(e.pageX <150){
									
											// $(this).css({
										
													// 'cursor' : "se-resize"
										
											// });
									
									// }else{
											// if(e.pageX >300){
											
													// $(this).css({
												
															// 'cursor' : "sw-resize"
												
													// });
											
											
											
											// }else{
											
													// $(this).css({
														
															// 'cursor' : "s-resize"
														
													// });
											
											// }

									
									// }
							
							
							
							// } else {
							
							
									
									
											// $(this).css({
											
													// 'cursor' : "w-resize"
										
											// });

									
									
								
							// }
				
				
				// }else{
				
							// if(e.pageX <150){
									
											// $(this).css({
										
													// 'cursor' : "sw-resize"
										
											// });
									
									// }else{
									
											// if(e.pageX >300){
											
													// $(this).css({
												
															// 'cursor' : "se-resize"
												
													// });
											
											
											
											// }else{
											
													// $(this).css({
														
															// 'cursor' : "s-resize"
														
													// });
											
											// }
									
											
									
									// }
				
						
				
				
				// }
				
				
				


				

				
				

		});
		


		$(".content").children(".supercontent").children("p").children("img").mouseout(function() {

				$(this).removeClass("over");
				
				if($(this).hasClass("active") ){}else{
						// $(this).animate({opacity: opbasse}, vitesseop);
				}
				
		});
		
		// --
		
		
		// Navigation par hash
		  
		$(window).hashchange()
		
		// --

		//---- SMOOTH SCROLL -- jQuery.LocalScroll d'Ariel Flesler http://flesler.blogspot.com

		$.localScroll({});
					
			



			
});

  
  

