/* Author: De Gevigney - Abies Interactive
*/
$(document).ready(function() {
	//alert("test");
	//Control RollOver / RollOut Footer Link;
	$('footer a').css({backgroundPosition: "0 0"});
	
	$('footer a').hover(function () {
		if($(this).is('.link-email')){
			$(this).stop().animate({backgroundPosition:"(0px 15px)"}, 400);
		}
		else{
			$(this).stop().animate({backgroundPosition:"(0px 19px)"}, 400);
		}
	},function () {
		 $(this).stop().animate({backgroundPosition:"(0px 0px)"}, 200); 
	});
	
	
	$('#logo-interactive span').css('opacity', 0);
	$('#logo-interactive').hover(function () {  
	        $('#logo-interactive span').stop().fadeTo(500, 1); 
	   	    }, function () {  
			$('#logo-interactive span').stop().fadeTo(500, 0);  
	    });  
	   
	 $('#logo-institut span').css('opacity', 0);
	 $('#logo-institut').hover(function () {  
	         $('#logo-institut span').stop().fadeTo(500, 1); 
	    	    }, function () {  
	 		$('#logo-institut span').stop().fadeTo(500, 0);  
	     }); 
	  
	  haloBouton();
	  
	  
	  
	  function haloBouton(){
	     $('#bouton a span').animate({opacity: 'toggle'}, 1000, 'linear', function() {
	        haloBouton();
	    	}
	    );
	  }
	  
	 $('a.enter span').css('opacity', 0);
	 $('a.enter').hover(function () {  
	         $(this).find('span').stop().fadeTo(500, 1); 
	    	    }, function () {  
	 		$(this).find('span').stop().fadeTo(500, 0);  
	     });   
	  
	 
	 	
		

	function brille(st){
		//Retard aléatoire entre 0 et 2 secondes
		var r = Math.floor(Math.random() * 3000);
		var change = Math.floor(Math.random() * 4000)+2000;
		st.delay(r).animate({opacity:1},4000,function(){brilleOut(st);});
	}
	function brilleOut(st){
		var r = Math.floor(Math.random() * 3000);
		var change = Math.floor(Math.random() * 4000)+1000;
		st.delay(r).animate({opacity:0},change,function(){brille(st);});
	}
	
//	$('#stars-body li').each(function(index) {
//	  	 if($(this).is('#s3') || $(this).is('#s6') || $(this).is('#s9') || $(this).is('#s11') || $(this).is('#s7') || $(this).is('#s14') || $(this).is('#s15') || $(this).is('#s17')){
//	  	 	brille($(this));
//	  	 }
//	  	  else {
//	  	  	brilleOut($(this));
//	  	  }
//	 });  
	 
	
	 
	// setInterval(function() {itistime();}, 700);
	 function itistime (){
	 	sdfs
	 }

	var univers = 1;
	$('#header').css( "opacity","0" );
	
	$('#bouton a').click(function() {
		hideUnivers();
	});
	function hideUnivers(){
		var logo = "#logo-interactive";
		var text = "#p-interactive";
		if(univers == 1){
			logo = "#logo-institut";
			text = "#p-institut";
		}
		$('#texte-down').stop().animate({opacity:'toggle'},500);
		$(text).stop().delay(200).animate({left: '-=100',opacity: 'hide'},500);
		
		$(logo).stop().delay(200).animate(
		{top: '-=100',opacity: 'hide'},
		{duration: 700,specialEasing: {top: 'easeOutCirc',opacity: 'linear'}});
		
		$('#stars').stop().animate({opacity:0},1000);
		if(univers == 0) univers = 1;
		else univers = 0;
		
		switchBG();
	}
	
	function switchBG(){
		var op=''+univers;
		$('#header2').animate(
		{opacity: op},
		{
		duration: 1000,
		specialEasing: {opacity: 'linear'},
		complete: function() {showUnivers();}
		}
		);
	}
	
	function showUnivers(){
		var logo = "#logo-interactive";
		var text = "#p-interactive";
		var t ="( Vers Abies Institut )";
		if(univers == 1){
			logo = "#logo-institut";
			text = "#p-institut";
			t = "( Vers Abies Interactive )";
		}
		$('#texte-down').text(t);
		$('#texte-down').stop().animate({opacity:'toggle'},500);
		$(logo).hide();
		$(logo).css("top",-50);
		$(logo).stop().animate(
		{top: '+=100',opacity: 'show'},
		{duration: 500,specialEasing: {top: 'easeOutCubic',opacity: 'linear'}});
		
		$(text).hide();
		$(text).css("left",-100);
		$(text).stop().delay(100).animate({left: '0',opacity: 'show'},500);
		$('#stars').stop().delay(700).animate({opacity:1},10000);
	}
	
	
	
	});























