/*
 * jQuery LPSLIDER v1
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Copyright © 2011 Loïc Pennamen   www.loicpennamen.com
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/
		// fonctions du slider
		var lpSliderTransition='easeInOutCubic';
		
		// creer et positionner les elements du slider
		function lpSliderInit(){
			var largeurPage=$(window).width();
			var length = $('#slideContainer .slide').length;
			var slide, i;
			
			if(typeof(document.lpSliderRunning)=='undefined'){
				document.lpSliderRunning=1;
			}
			
			// place chaque bloc
			for(i=1; i<=length; i++){
				slide=$('#slideContainer .slide').eq(i-1);
				// slide.css({ left: (largeurPage*(i-1))+'px' });
				slide.css({ left: (largeurPage*(i-document.lpSliderRunning))+'px' });	// ce calcul magique permet d'initialiser lanim' au resize sans bugs ni reload
			}
			
			// animer la slide seulement s'il n'y a pas d'auto en cours (evite de relancer les anim' au resize de la page)
			if(!document.lpAutoSlide){
				// animation de la slide
				animerLaSlide(document.lpSliderRunning);	// fonction in-page
			}
		}
		// déplacement
		function lpMoveSliderRight(speed){
			if(!speed) speed=700;
			
			document.lpSliderRunning++;
			
			// def vars
			var largeurPage=$(window).width();
			var length = $('#slideContainer .slide').length;
			var newLeft=0;
			
			// mvt si slider en cours n'est pas le dernier
			if(document.lpSliderRunning <= length){
				for(i=1; i<=length; i++){
					slide=$('#slideContainer .slide').eq(i-1);
					newLeft = parseInt((i -1)*largeurPage - ((document.lpSliderRunning-1)*largeurPage)) +'px';		// nouvelle left
					slide.animate({left: newLeft}, speed, lpSliderTransition);
				}
			}
			// mvt si dernier
			else{
				document.lpSliderRunning=1;
				for(var i=1; i<=length; i++){
					slide=$('#slideContainer .slide').eq(i-1);
					newLeft=parseInt(largeurPage*(i-1)) +'px';		// nouvelle left
					slide.animate({left: newLeft}, speed, lpSliderTransition );
				}
			}
			
			// animation de la slide
			animerLaSlide(document.lpSliderRunning);	// fonction in-page
			
			// Si un Dragger est lié, animation du Dragger // position du draglinker (fond blanc)
			var posx= $('.draglinker:eq('+(document.lpSliderRunning -1)+')').offset().left -$('.draglinker:first').offset().left;
			$('#lpsliderdragger .dragmover').animate({ left:posx+'px' }, { queue:false, duration:200 } );
			
		}
		// déplacement gauche
		function lpMoveSliderLeft(speed){
			if(!speed) speed=700;
			
			document.lpSliderRunning--;
			
			// def vars
			var largeurPage=$(window).width();
			var length = $('#slideContainer .slide').length;
			var newLeft=0;
			
			// mvt si slider en cours n'est pas le premier
			if(document.lpSliderRunning > 0){
				for(i=1; i<=length; i++){
					slide=$('#slideContainer .slide').eq(i-1);
					// alert(i+' : position : '+ (document.lpSliderRunning-i)*(-1)*largeurPage);
					newLeft = parseInt((document.lpSliderRunning-i)*(-1)*largeurPage) +'px';		// nouvelle left */
					slide.animate({left: newLeft}, speed, lpSliderTransition);
					// alert(i+' recul : '+newLeft)
				}
			}
			// mvt si premier
			else{
				document.lpSliderRunning=length;
				for(var i=1; i<=length; i++){
					slide=$('#slideContainer .slide').eq(i-1);
					newLeft=parseInt(-(length-i)*largeurPage) +'px';		// nouvelle left
					slide.animate({left: newLeft}, speed, lpSliderTransition );
				}
			}
			
			// animation de la slide
			animerLaSlide(document.lpSliderRunning);	// fonction in-page
		}
		// déplacement precis
		function lpSliderMoveTo(n, speed){
			if(!speed) speed=700;
			
			lpSliderStop();
			document.lpSliderRunning = n;
			
			// def vars
			var largeurPage=$(window).width();
			var length = $('#slideContainer .slide').length;
			var newLeft=0;
			
			// mvt si slider en cours n'est pas le premier
			if(document.lpSliderRunning > 0){
				for(i=1; i<=length; i++){
					slide=$('#slideContainer .slide').eq(i-1);
					// alert(i+' : position : '+ (document.lpSliderRunning-i)*(-1)*largeurPage);
					newLeft = parseInt((document.lpSliderRunning-i)*(-1)*largeurPage) +'px';		// nouvelle left */
					slide.animate({left: newLeft}, speed, lpSliderTransition);
					// alert(i+' recul : '+newLeft)
				}
			}
			// mvt si premier
			else{
				document.lpSliderRunning=length;
				for(var i=1; i<=length; i++){
					slide=$('#slideContainer .slide').eq(i-1);
					newLeft=parseInt(-(length-i)*largeurPage) +'px';		// nouvelle left
					slide.animate({left: newLeft}, speed, lpSliderTransition );
				}
			}
			
			// animation de la slide
			animerLaSlide(document.lpSliderRunning);	// fonction in-page
		}
		// auto start
		function lpSliderAuto(speed){
			if(!speed) speed=4000;
			
			if(typeof(document.lpSliderAutoRun)=='undefined'){document.lpSliderAutoRun=true;}
			document.lpSliderAutoRun=true;
			
			document.lpAutoSlide=setTimeout("lpMoveSliderRight()", speed)
			document.lpAutoSlideNext=setTimeout("lpSliderAuto("+speed+")", speed)
		}
		// stop auto start
		function lpSliderStop(){
			clearTimeout(document.lpAutoSlide);
			clearTimeout(document.lpAutoSlideNext);
		}
		
		
		
		
