// JavaScript Document
  /************************* DIAPO INTRO ******************************/

	  $(function(){
	   /*Tableau avec les images, largueur, hauteur, url, point de départ, point d'arrivé, durée, temps d'attente*/
	   var animations = [
	
	   {width : "1350px" , height: "452px", url: "images/intro1.jpg" , start: {"margin-left": 0,"margin-top": 0}, end: {"margin-left": -300,"margin-top": 0}, duration: 6000, delay : 500},  
	   {width : "974px", height: "730px", url: "images/intro2.jpg" , start: {"margin-left": 0, "margin-top": 0}, end: {"margin-left": 0, "margin-top": -200}, duration: 6000, delay : 500},
	   {width : "971px", height: "729px", url: "images/intro4.jpg" , start: {"margin-left": 0, "margin-top": 0}, end: {"margin-left": 0, "margin-top": -200}, duration: 6000, delay : 500},
	   {width : "971px", height: "729px", url: "images/intro5.jpg" , start: {"margin-left": 0, "margin-top": 0}, end: {"margin-left": 0, "margin-top": -200}, duration: 6000, delay : 500},
	   {width : "1350px" , height: "466px", url: "images/intro6.jpg" , start: {"margin-left": 0,"margin-top": 0}, end: {"margin-left": -300,"margin-top": 0}, duration: 6000, delay : 500}
		
		
	   ];
	   
	   
	  function _animate(i){
		  
		  
		  var precedent = (i==0 ? animations[animations.length-1] :  animations[i-1] );
		  
		  if (!animations[i]){
			  
			return _animate(0)
				  
		   }
		  		
		return function(){	

			var d =  animations[i];
		
			var css = {width: d.width, height: d.height, backgroundImage: "url("+d.url+")"};
			
			
			if (d.url!=precedent.url){				
				$("#photo").css(css).css(d.start);	
				
				/*$("#photo").fadeIn()
				$("#photo")					
					.fadeOut("slow", function(){$("#photo").css(css)})*/
					
					
				console.log(d.url + "!=" + precedent.url)
				
			}
			
		
											
			var animate_options = {
				duration: d.duration,
   				easing: "linear",
    			complete:  animations.length > i-1 ? _animate(++i) : undefined ,
    			queue: true,
			/*	step : function(now, fx) {
					
					var p = "margin-left";
									
					if (fx.prop == "bpl"){
						
						var pos = $(fx.elem).css(p).split(" ");
												
						pos[0] = "" + parseInt(now, 10) + "%";
			
						$(fx.elem).css(p, pos.join(" "));
									
			
					}
					
				if (fx.prop == "bpt"){
						
						var pos = $(fx.elem).css(p).split(" ");
												
						pos[0] = "" + parseInt(now, 10) + "%";
			
						$(fx.elem).css(p, pos.join(" "));
									
			
					}				
					
					console.log($(fx.elem).css(p));
					
					
				}*/
			}
						
					
			
			$("#photo")
			.css(d.start)
			.animate(d.end, animate_options)
			
		}
			
	  } 
	   
	  _animate(0)()
	   
	   
});
 
 
 
  /************************* Fin DIAPO INTRO ******************************/
