
// Variable Carrousel
var carrousel = {
	
	nbSlide : 0,
	nbCurrent : 1,
	elemCurrent : null,
	elem : null,
	timer : null,
	
	init : function(elem){
		this.nbSlide = elem.find('.slide').length;
		
		// Créer la pagination
		elem.append('<div class="navigation"></div>')
		for(var i=1;i<=this.nbSlide;i++){
			elem.find('.navigation').append('<span>'+i+'</span>')
			}
			
			elem.find('.navigation span').click(function(){ carrousel.gotoSlide($(this).text());})
			
			// Initialisation du carrousel
			this.elem=elem;
			elem.find('.slide').hide();
			elem.find('.slide:first').show();
			this.elemCurrent = elem.find('.slide:first');
			this.elem.find('.navigation span:first').addClass('active');
			
			// On créer le timer
			carrousel.play();
			
			//Stop au survol
			elem.mouseover(carrousel.stop);
			elem.mouseout(carrousel.play);

			//next et prev
			elem.find('#fleche_gauche').click(function(){carrousel.prev()});
			elem.find('#fleche_droite').click(function(){carrousel.next()});

		},
	
		gotoSlide : function(num){
			
				if(num==this.nbCurrent){return false;}
				
				/*
				// V1 : Animation en fadeIn/fadeOut (pb IE7 et Chrome) --------
				this.elemCurrent.fadeOut();
				this.elem.find('#slide'+num).fadeIn();
				*/

				// V2 : Animation en slide  ------------------------------------
				var sens = 1;
				if (num<this.nbCurrent){ sens = -1 }
				var cssDeb = { 'left' : sens*this.elem.width() }
				var cssFin = { 'left' : sens*-this.elem.width() }
				this.elem.find('#slide'+num).show().css(cssDeb);
				this.elem.find('#slide'+num).animate({'top':0,'left':0}, 1000, 'easeInOutQuint');
				this.elemCurrent.animate(cssFin, 1000, 'easeInOutQuint');

				/*
				// V3 : Animation barre titre  ------------------------------------
				this.elemCurrent.find('.visu').fadeOut();
				this.elem.find('#slide'+num).show();
				this.elem.find('#slide'+num+'.visu').hide().fadeIn();
			
				var titleHeight = this.elemCurrent.find('.title').height();

				this.elemCurrent.find('.title').animate({'bottom': -titleHeight},500);
				this.elem.find('#slide'+num+'.title').css('bottom', -titleHeight).animate({'bottom':0},500);
				*/

				this.elem.find('.navigation span').removeClass('active');
				this.elem.find('.navigation span:eq('+ (num-1) +')').addClass('active');
				this.nbCurrent = num;
				this.elemCurrent = this.elem.find('#slide'+num);

		},

		next : function(){
			var num = this.nbCurrent +1;
			if (num > this.nbSlide){
				num = 1;
			}
			this.gotoSlide(num);
		},
		
		prev : function(){
			var num = this.nbCurrent -1;
			if (num < 1){
				num = this.nbSlide;
			}
			this.gotoSlide(num);
		},
		
		stop : function(){
			window.clearInterval(carrousel.timer);
		},
		
		play : function(){
			window.clearInterval(carrousel.timer);
			carrousel.timer = window.setInterval('carrousel.next()', 5000);
		},

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Value champs textes
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	function f_effaceValue(ID_cible) {
	document.getElementById(ID_cible).value='';
}
	function f_retabliValue(ID_cible,valeurDefaut) {
		var cible=document.getElementById(ID_cible);
		if(cible.value==''){
			cible.value=valeurDefaut;
	}
}

$(document).ready(function() {


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MainNav
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	$('#Nav > li').hover(function() {
		if($(this).find('ul').css('display')=='none'){
		$(this).find('ul').slideDown('fast');
		}
	}, function() {
		$(this).find('ul').slideUp('fast');
	});
	
	$('#Nav > li').hover(function() {
		$(this).find('a').css('background','#555');		
		$(this).find('a').css('color','#fff');
	}, function(){
		$(this).find('a').css('background','#fff');		
		$(this).find('a').css('color','#000');
	});

	$('#Nav > li >ul>li').hover(function() {
		$(this).find('a').css('background','#fff');		
		$(this).find('a').css('color','#555');
	}, function(){
		$(this).find('a').css('background','#555');		
		$(this).find('a').css('color','#fff');
	});


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Nav Galerie
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	$('ul.menuGalerie a').hover(function() {
		$(this).stop().animate({ backgroundColor:'#fff', color:'#333' }, 'fast');
		$(this).children('img').stop().animate({ opacity:'1', marginRight:'15px', paddingLeft:'5px', },500);
	},
		function() {
		$(this).stop().animate({ backgroundColor:'#999', color:'#fff' }, 500);
		$(this).children('img').stop().animate({ opacity:'0', marginRight:'0px', paddingLeft:'0px', },500);
	});
	

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Mosaique Photoq 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
	$('li.photoMosaique').hover(function() {
		$('img.photoHover', this).stop().animate({opacity: 1 }, 500);
	},
		function() {
		$('img.photoHover', this).stop().animate({opacity: 0 }, 500);
	});
	
	
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Scroll animé
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	$('a[href^=#]').click(function(){
		cible=$(this).attr('href');
		//alert(cible);
		if($(cible).length>=1){
			// Si le lien est un lien de type <a href="header">
			hauteur=$(cible).offset().top;
			}
			//alert(hauteur);
			else{
			// Si le lien est un lien de type <a href="#top">
			hauteur=$("a[name="+cible.substr(1,cible.length-1)+"]").offset().top;
			//alert(hauteur);
			$('html,body').animate({scrollTop:hauteur},1500, 'easeInOutQuint');
			return false;
			}
	});


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Carrousel
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	$(function() {
		carrousel.init($('#carrousel'));
	//	alert(carrousel.nbSlide);
	});


});


