// --------------------------------------------------------------------------------------------------
//		Initialisation de variables
//		 
// --------------------------------------------------------------------------------------------------  
		//	vitesse de l'annimation 
		var vitesseSlide='slow';  
		//	largeur d'une image 
		var tailleMoveSlide=580; 
		var taillemax= 2900; // 5x580
		var indice=1;
		var indice1=1;
		var indice2=1;
                	var indice3=1;

// --------------------------------------------------------------------------------------------------
//
//			Fonction Slider
// -------------------------------------------------------------------------------------------------- 

		function slider(txt,indice) 
		{ 
			//$(txt).animate({right: indice}, vitesseSlide)
			// $(txt).animate({right: tailleMoveSlide*(indice)}, vitesseSlide)
    			//$('#slideInner').animate({'marginLeft' : step*(-currentPosition)},tempsTransition); 
    			$('#slideInner').animate({'marginLeft' : -indice}, vitesseSlide);   
		}
// --------------------------------------------------------------------------------------------------
//
//			Fonction Fade Out/IN
// -------------------------------------------------------------------------------------------------- 
		function fade(txt,indice){
		 	$(txt).fadeOut("slow");	
		 	$(txt).eq(indice).fadeIn("slow");									
		}
// --------------------------------------------------------------------------------------------------
//
//			Fonction Slide Up/Down
// -------------------------------------------------------------------------------------------------- 

		function slideup(txt,indice){
		 	$(txt).slideUp("slow");	
		 	$(txt).eq(indice).slideDown("slow");
									
		}

// --------------------------------------------------------------------------------------------------
//
//		Fonction Auto Slider
// -------------------------------------------------------------------------------------------------- 
		function autoSlider(indice2) 
		{ 	
			var ind2 =0;
			var slds = $("#content_autoslider .slidebox img");
			ind2=indice2;
			taillemax = slds.length * tailleMoveSlide;
			$(".slidebox").css({'position': 'relative','height': 370, 'width': taillemax,'text-align' : 'left'});
			//si on est à la derniere image, on revient a la premiere position.
			if( ind2 == slds.length){ind2=0;}
			$('#content_autoslider .slidebox').animate({right: tailleMoveSlide*ind2}, vitesseSlide); 
			return ++ind2;
		} 
// --------------------------------------------------------------------------------------------------
//
//		Fonction Auto Fade Out/IN
// -------------------------------------------------------------------------------------------------- 
		function autoFade(indice){
			var slides = $("#content_autofade .slide0");
			var ind =0;
			ind=indice;
			if( ind == slides.length){ind=0;}
		 	$("#content_autofade .slide0").fadeOut("slow");	
		 	$("#content_autofade .slide0").eq(ind).fadeIn("slow");
			return ++ind;						
		}
// --------------------------------------------------------------------------------------------------
//
//		Fonction Auto Slide Up/Down
// -------------------------------------------------------------------------------------------------- 

		function autoSlide(indice1){
			var slides = $("#content_autoslideup .slide0");
			var ind1 =0;
			ind1=indice1;
			if( ind1 == slides.length){ind1=0;}
		 	$("#content_autoslideup .slide0").slideUp("slow");	
		 	$("#content_autoslideup .slide0").eq(ind1).slideDown("slow");
			return ++ind1;						
		}
// --------------------------------------------------------------------------------------------------
//
//		Fonction popupDisplay
// -------------------------------------------------------------------------------------------------- 

		function popupDisplay(txt,indice){

			//var ind2 =0;
			//ind2=indice2 -1;
		 	$(txt).hide();
			$(txt).css({ "position": "absolute", "top": 100,"left": 150 });  				
		 	$(txt).eq(indice).toggle("slow");
		}

// --------------------------------------------------------------------------------------------------
//
//		Fonction popupHide
// -------------------------------------------------------------------------------------------------- 

		function popupHide(txt){

		 	$(txt).fadeOut("slow");
		}
// --------------------------------------------------------------------------------------------------
//
//			Script pour les onglets
// --------------------------------------------------------------------------------------------------
		function onglet(){
 
	   		$(".tabbed_area .content").not(":first").hide(); 
			$(".tabbed_area .content:first").addClass("actif");

    			$(".tabbed_area ul.tabs a").click(function(){ 
				$(".tabbed_area ul.tabs a").parent("li").removeClass("actif");
        				$(".tabbed_area .content").fadeOut("slow"); 
        				$(this.hash).fadeIn("slow");   
				$(this).blur().parent("li").addClass("actif"); 
        				return false; 
    			});
		}

// --------------------------------------------------------------------------------------------------
//
//			Fonction slideBar
// --------------------------------------------------------------------------------------------------
		function slideBar(){

			$("#content_galery #slider").slider({
				value: 20,
				min: 0,
				max: 12000,
				step: 1,
				animate:true,
				change: function(event, ui) {
					slider('#content_galery #slideInner',ui.value);
				} 
			}); 
		}

// --------------------------------------------------------------------------------------------------
//
//		Fonction Image Rotative
// -------------------------------------------------------------------------------------------------- 
		function imageRotative(txt){
			var slides = $(txt);
			var ind =0;
			var indice =0;
			indice = Math.round( slides.length*Math.random()); 
			ind=indice;
			if( ind == slides.length){--ind;}
		 	$(txt).hide();	
		 	$(txt).eq(ind).show();
			return ++ind;						
		}


// --------------------------------------------------------------------------------------------------
//
//		Fonction Diapo
// -------------------------------------------------------------------------------------------------- 
		function diapo(){
// ---------------------------------------------------------------------------------------------------
//             Initialisation diapo
// ---------------------------------------------------------------------------------------------------
		//Configuration
		  var retour = true;
		  var tempsTransition = 1000;
		  var affichePlayPause = false;
		  var lectureAutomatique = false;
		  	var tempsAttente = 6000;			
		  var icones = new Array();
		  		icones['play'] = 'images/play_slider.png';
		  		icones['pause'] = 'images/pause_slider.png';				
		  var currentPosition = 0;
		  var slideWidth = 820;
		  var step = 290;
		  var slides = $('.slide');
//		  var numberOfSlides = slides.length;
		  var numberOfSlides = 40;
		  var interval;
		  var lectureEnCours = false;
 	 		// Supprime la scrollbar en JS
  			$('#slidesContainer').css('overflow', 'hidden');
 
  			// Attribue  #slideInner  à toutes les div .slide
  			slides
    			.wrapAll('<div id="slideInner"></div>')
    			// Float left to display horizontally, readjust .slides width
			.css({
		      		'float' : 'left',
      				'width' : slideWidth
   			 });
 
 			 // Longueur de #slideInner égale au total de la longueur de tous les slides
  			$('#slideInner').css('width', slideWidth * numberOfSlides);
 
 			 // Insert controls in the DOM
  			$('#slideshow')
    			.prepend('<span class="control" id="leftControl">Précédent</span>')
    			.append('<span class="control" id="rightControl">Suivant</span>');
 
 
  
 			 // Hide left arrow control on first load
 			 manageControls(currentPosition);
 
 			 //Crée un écouteur d'évènement de type clic sur les classes .control
  			$('.control')
    .bind('click', function(){
		
    // Determine la nouvelle position
	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
	if(currentPosition == numberOfSlides && retour == false ){
		currentPosition--;
		pause();
	}
	
	// Cache ou montre les controles
    manageControls(currentPosition);
    // Fais bouger le slide
    $('#slideInner').animate({
      'marginLeft' : step*(-currentPosition)
    },tempsTransition);
  });
 
  // manageControls: Cache ou montre les flêches de controle en fonction de la position courante
  function manageControls(position){
    // Cache la fleche "précédent" si on est sur le premier slide
	if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
	// Cache la fleche "suivant" si on est sur le dernier slide (et que le retour automatique n'est pas activé)
    if(position==numberOfSlides-1 && retour == false){
		$('#rightControl').hide();
	} else {
		$('#rightControl').show();
	}
	if(position == numberOfSlides && retour == true){
		currentPosition = 0;
		 $('#leftControl').hide();
	}
  }
  function suivant(){
	$('#rightControl').click();
	}
  function start() {
  	lectureEnCours = true;
    interval = setInterval(suivant, tempsAttente );
  }
  function pause() {
  	lectureEnCours = false;
   clearInterval(interval);
  }
  
 //Si le diapo est activé 
if(lectureAutomatique == true){
  start();
}
if(affichePlayPause == true){
	$('#slidesContainer').prepend('<img id="navDiapo" src="" alt="Navigation diaporama" />');
	if(lectureAutomatique == true){
		$('#navDiapo').attr('src',icones['pause']);
	}else{
		$('#navDiapo').attr('src',icones['play']);	
	}
	$('#navDiapo').bind('click', function(){
		if(lectureEnCours == true){
			$(this).attr('src',icones['play']);
			pause();
		}else{
			$(this).attr('src',icones['pause']);
			start();
		}
	});
}
}


// --------------------------------------------------------------------------------------------------
//
//		au chargement de la page 
// -------------------------------------------------------------------------------------------------- 

		$(document).ready(function(){
			imageRotative("#content_home .slide0");
// ---------------------------------------------------------------------------------------------------------------
//
//			Initialisation de  l'animation Autoslider, on la lance en boucle toutes les (2000 milisecondes)
// --------------------------------------------------------------------------------------------------------------- 
			$(".slidebox").css({'position': 'relative','height': 620, 'width': 5400,'text-align' : 'left'});
// ---------------------------------------------------------------------------------------------------------------
//
//			Initialisation du slide bar
// --------------------------------------------------------------------------------------------------------------- 
			slideBar();
			diapo();
		});
