$(document).ready(function() {
		
	$('a.zoombox').zoombox({
    	gallery     : false
    });
	
	function fr(){
	$('.en').hide();
	$('.fr').show();
	};
	
	function en(){
	$('.fr').hide();
	$('.en').show();
	};
	
	fr();
	var langue = 0;
	
	$('#fLangue').click(function(){
		if (langue == 0){
			en();
			langue = 1;
		} else if (langue == 1){
			fr();
			langue = 0;
		}
	});

/*---------------------------------------------------------------------
-------------------------------- MENU ---------------------------------
---------------------------------------------------------------------*/	
	$('.enter').hover(function(){
	$(this).find('img').stop().animate({opacity : 0}, 500);
	}, function(){
	$(this).find('img').stop().animate({opacity : 1}, 1000);			
	});
	
	$('#btAccueil').click(function(){
		$('#btAccueil').animate({opacity : 0}, 1000, function (){$(this).hide(0)});
		$('#menu').animate({top : 0}, 1000);
		$('#footer').animate({opacity: 1, bottom : 0}, 1000);
		$('#lueur').animate({opacity : 1}, 1000, function(){news3();});
		$('#menuG, #menuD').delay(1000).animate({opacity : 1}, 1000);
		carrouselNews.init($('#carrouselNews'));
	});
	
	$('.news').click(function(){
		news();
		work2();
		about2();
		contact2();
	});
	
	$('.about').click(function(){
		about();
		work2();
		news2();
		contact2();
	});
	
	$('.work').click(function(){
		work();
		news2();
		about2();
		contact2();
	});
	
	$('.contact').click(function(){
		contact();
		work2();
		news2();
		about2();
	});
	
	$('.work, .about, .contact, .news').hover(function(){
		$(this).stop().animate({opacity : 1}, 500);		
	}, function(){
		$(this).stop().animate({opacity : 0}, 1000);
	});
	
	function news(){
		$('#newsR').delay(400).show(0).animate({opacity: 1, top: '45%'}, 500, 'easeOutCirc');
	}
	
	function news2(){
		$('#newsR').animate({opacity: 0,top: '50%'}, 500, 'easeOutCirc', function (){$(this).animate({top: '40%'}, 0, function (){$(this).hide(0)})});
	}
	
	function news3(){
		$('#newsR').delay(400).show(0).animate({opacity: 1, top: '45%'}, 1000, 'easeOutCirc');
	}
			
	function about(){
		$('#aboutR').delay(400).show(0).animate({opacity: 1}, 500, 'easeOutCirc');
		$('#texteAbout').delay(400).animate({top: 0}, 500, 'easeOutCirc');
		$('#like').delay(400).animate({top: 180}, 500, 'easeOutCirc');
		$('#clients').delay(400).animate({top: 180}, 500, 'easeOutCirc');
	}
	
	function about2(){
		$('#aboutR').animate({opacity: 0}, 500, function (){$(this).hide(0)});
		$('#texteAbout').animate({top: 100}, 500, 'easeOutCirc', function (){$(this).animate({top: -100})});
		$('#like').animate({left: -100}, 500, 'easeOutCirc', function (){$(this).animate({top: 280, left: 0})});
		$('#clients').animate({right: -100}, 500, 'easeOutCirc', function (){$(this).animate({top: 280, right: 0})});
	}
	
	function work(){
		$('#workR').delay(400).show(0).animate({opacity: 1}, 800, 'easeOutCirc');
		$('#w1').delay(400).animate({left: 0}, 800, 'easeOutCirc');
		$('#w2').delay(400).animate({left: 0}, 800, 'easeOutCirc');
		$('#w3').delay(400).animate({left: 0}, 800, 'easeOutCirc');
	}
	
	function work2(){
		$('#workR').animate({opacity: 0,top: '45%'}, 500, 'easeOutCirc', function (){$(this).hide(0)});
		$('#w1').animate({left: -100}, 800, 'easeOutCirc', function (){$(this).animate({left: 100})});
		$('#w2').animate({left: 100}, 800, 'easeOutCirc', function (){$(this).animate({left: -100})});
		$('#w3').animate({left: -100}, 800, 'easeOutCirc', function (){$(this).animate({left: 100})});
	}
	
	function contact(){
		$('#contactR').delay(400).show(0).animate({opacity: 1}, 500, 'easeOutCirc');
		$('#boiteForm').delay(400).animate({right: 0}, 500, 'easeOutCirc');
		$('#texteContact').delay(400).animate({left: 0}, 500, 'easeOutCirc');
	}
	
	function contact2(){
		$('#contactR').animate({opacity: 0}, 500, function (){$(this).hide(0)});
		$('#boiteForm').animate({top: 100}, 500, 'easeOutCirc', function (){$(this).animate({top: 0, right: -100})});
		$('#texteContact').animate({top: -100}, 500, 'easeOutCirc', function (){$(this).animate({top: 0, left: -100})});
	}
	
/*---------------------------------------------------------------------
-------------------------------- MENU ---------------------------------
---------------------------------------------------------------------*/	
var carrouselNews = {
	 nbSlide: 0,
	 nbCurrent: 1,
	 elementCurrent: null,
	 elem: null,
	 timer: null,
	 
	 init: function(elem){ 
		 this.nbSlide = elem.find('.slide').length;
		 
	$('#carrouselNews').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(){carrouselNews.gotoSlide($(this).text());})
	
		 this.elem = elem;
		 elem.find('.slide2').hide();
		 elem.find('.slide3').hide();
		 elem.find('.slide4').hide();
		 elem.find('.slide5').hide();
		 elem.find('.slide:first').animate({opacity:1});
		 this.elementCurrent = elem.find('.slide:first');
		 this.elem.find('.navigation span:first').addClass('active');
		 
		 carrouselNews.timer = window.setInterval(function(){carrouselNews.next()}, 4000);
		 
		 $('#carrouselNews').hover(function(){
			carrouselNews.stop();
			}, function(){
			carrouselNews.play();		
		});
	 },
	 
	 gotoSlide : function(num){
		 if(num==this.nbCurrent){return false;}
		 this.elementCurrent.css('z-index', '616').animate({opacity:0}, 2000, 'easeOutCirc', function(){$(this).hide()});
		 this.elem.find('.slide'+num).css('z-index', '626').animate({opacity:0},0).show(0).animate({opacity:1}, 2000, 'easeOutCirc');
		 $('#carrouselNews .titleNews').slideToggle(250, 'easeOutCirc');
		 $('#carrouselNews .titleNews').delay(250).slideToggle(500, 'easeOutCirc');
		 this.elem.find('.navigation span').removeClass('active');
		 this.elem.find('.navigation span:eq('+(num-1)+')').addClass('active');
		 this.nbCurrent = num; 
		 this.elementCurrent = this.elem.find('.slide'+num);
	 },
	 
	 next : function(){
		var num = Number(this.nbCurrent)+1;
		if(num > this.nbSlide){
			num = 1;
			} 
		this.gotoSlide(num);
	 },
	 
	 prev : function(){
		var num = Number(this.nbCurrent)-1;
		if(num < 1){
			num = this.nbSlide;
			} 
		this.gotoSlide(num);
	 },
	 
	 stop : function(){
		 window.clearInterval(carrouselNews.timer);
	 },
	 
	 play : function(){
		 window.clearInterval(carrouselNews.timer);
		 carrouselNews.timer = window.setInterval(function(){carrouselNews.next()}, 4000);
	 }
}

/*---------------------------------------------------------------------
-------------------------------- WORK ---------------------------------
---------------------------------------------------------------------*/
	$('#workR .btWork').hover(function(){
		$(this).find('img').stop().animate({marginTop: -30}, 250);
	}, function(){
		$(this).find('img').stop().animate({marginTop: 0}, 250);			
	});

/*---------------------------------------------------------------------
------------------------------ CONTACT --------------------------------
---------------------------------------------------------------------*/		
	$('#nom').blur(function(){
		if($('#nom').val()==""){
			$('#nom').css('border-color', '#D00');
		} else {
			$('#nom').css('border-color', '#8D8');
		}
	});
	
	$('#email').blur(function(){
		if(!$('#email').val().match(/^[a-z0-9\-_.]+@[a-z0-9\-_.]+\.[a-z]{2,3}$/i)){
			$('#email').css('border-color', '#D00');
		} else {
			$('#email').css('border-color', '#8D8');
		}
	});
	
	$('#sujet').blur(function(){
		if($('#sujet').val()==""){
			$('#sujet').css('border-color', '#D00');
		} else {
			$('#sujet').css('border-color', '#8D8');
		}
	});
	
	$('#message').blur(function(){
		if($('#message').val()==""){
				$('#message').css('border-color', '#D00');
		} else {
			$('#message').css('border-color', '#8D8');
		}
	});
	
	function resetF(){
		$('#nom').val('');
		$('#email').val('');
		$('#sujet').val('');
		$('#message').val('');
		$('#nom').css('border-color', '#888');
		$('#email').css('border-color', '#888');
		$('#sujet').css('border-color', '#888');
		$('#message').css('border-color', '#888');
	}
	
	function confirmation(){
		$('#confirmation').delay(500).show(0).animate({opacity: 1}, 1000, 'easeOutCirc');
		$('#cacheContact').show(0).animate({opacity: 0.7}, 1000, 'easeOutCirc');
		$('#confirmation').delay(5000).animate({opacity: 0}, 500, function (){$(this).hide(0)});
		$('#cacheContact').delay(5500).animate({opacity: 0}, 500, function (){$(this).hide(0)});
	}
	
	$('.reset').click(function(){
		$('#nom').css('border-color', '#888');
		$('#email').css('border-color', '#888');
		$('#sujet').css('border-color', '#888');
		$('#message').css('border-color', '#888');
	});
	
	$('.envoyer').click(function(){
		if(!$('#nom').val()=="" && !$('#sujet').val()=="" && !$('#message').val()=="" && $('#email').val().match(/^[a-z0-9\-_.]+@[a-z0-9\-_.]+\.[a-z]{2,3}$/i)){
		} else {
			$('.notification .fr').text('Formulaire invalide');
			$('.notification .en').text('Invalid formular');
			return false;
		}
	});
	
	$('#boiteForm').ajaxForm({ 
	// target identifies the element(s) to update with the server response 
	//target: '.notification', 
		success: function() { 
			resetF();
			confirmation();
			$('.notification .fr').text('Merci !');
			$('.notification .en').text('Thank you !');
		}
	});

/*---------------------------------------------------------------------
------------------------------- FOOTER --------------------------------
---------------------------------------------------------------------*/
	$('#fFollow').hover( function(){
		$('#fLinks').show().stop().animate({opacity: 1}, 250);
		$('#fTW').stop().animate({bottom: 10}, 250, 'easeOutCirc');
		$('#fFB').stop().animate({bottom: 100}, 250, 'easeOutCirc');
		$('#fFL').stop().animate({bottom: 55}, 250, 'easeOutCirc');
		
	});
	
	$('#overlay, #fLangue, #fReserved').hover( function(){
		$('#fLinks').stop().animate({opacity: 0}, 500, function(){$('#fLinks').hide()});
		$('#fTW').stop().animate({bottom: -25}, 500, 'easeOutCirc');
		$('#fFB').stop().animate({bottom: -25}, 500, 'easeOutCirc');
		$('#fFL').stop().animate({bottom: -25}, 500, 'easeOutCirc');
	});
		
});
