

$(document).ready(function() {

	setTimeout(function() {
		/*$(".r-home").fadeOut(function() {
			
		});*/
		//start();
	},5000);

	$(".smoothysegura").click(function(e) {
		e.preventDefault();
		$('html, body').animate({
		    scrollTop: $($.attr(this, 'href')).offset().top
		}, 500);
	});

	$(".clickmenu").click(function(e) {
		e.preventDefault();
		$(".fixed-menu").fadeIn('fast');
	});

	$(".closemenu, .menu-item").click(function(e) {
		e.preventDefault();
		$(".fixed-menu").fadeOut('fast');
	});

	var controller = new ScrollMagic.Controller();
	new ScrollMagic.Scene({
		duration: 100,
		offset: 50	
	}).setPin("#my-sticky-element").addTo(controller); 

});

$(document).on("click",".click_8d", function(e) {
	e.preventDefault();
	welcome();
	$(".r-welcome").addClass('out-pantalla');	
	$(".r-home").fadeIn();
});

function audioVolumeOut(q){
   if(q.volume){
      var InT = 0.4;
      var setVolume = 0;  // Target volume level for old song 
      var speed = 0.05;  // Rate of volume decrease
      q.volume = InT;
      var fAudio = setInterval(function(){
          InT -= speed;
          q.volume = InT.toFixed(1);
          if(InT.toFixed(1) <= setVolume){
             clearInterval(fAudio);
             //alert('clearInterval fAudio'+ InT.toFixed(1));
          };
      },50);
   };
};

$(window).on("load", function() {
	
	//welcome();
	//initial(); 
	$(".r-centrar").show();
	$(document).on("click",".menu-item", function(e) {
		e.preventDefault();
		$(".fixed-menu").fadeOut('fast');
		var h = $(this).attr('href');
		setTimeout(function(){
			var x = h.replace('#','');
			$("html, body").animate({ scrollTop: $("#nav_"+x).offset().top });
		},500);
	});	
	setTimeout(function() {
		/*$(document).scrollTop(114);*/
		$(document).scroll(function (event) {
		    var scroll = $(document).scrollTop();
		    if(scroll > 113) {
		    	//$(".left-logos").addClass("sticky");
		    	$(".right-menu").addClass("sticky");
		    }
		    else {
		    	//$(".left-logos").removeClass("sticky");
		    	$(".right-menu").removeClass("sticky");
		    }

		    var vhhh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);

		    if (scroll > vhhh && audio == null) {
		    	audio = document.getElementById("player15seg");
		    	audio2 = document.getElementById("player15seg2");
		    	setTimeout(function() { audio.volume = 0.28; audio2.volume = 0.28; },300);
		    	setTimeout(function() { audio.volume = 0.24; audio2.volume = 0.24; },600);
		    	setTimeout(function() { audio.volume = 0.20; audio2.volume = 0.20; },900);
		    	setTimeout(function() { audio.volume = 0.16; audio2.volume = 0.16; },1200);
		    	setTimeout(function() { audio.volume = 0.14; audio2.volume = 0.14; },1500);
		    	setTimeout(function() { audio.volume = 0.10; audio2.volume = 0.10; },1800);
		    	setTimeout(function() { audio.volume = 0.05; audio2.volume = 0.05; },2200);
		    	setTimeout(function() { audio.volume = 0; audio2.volume = 0; },2500);

		    }
		});
		slider.slick('refresh');
	}, 1000);


	
});

var fadeInterval = null;
var slider = null;
var audio = null;
var audio2 = null;
function slickSlide() { 
	slider = $('.carr').slick({
	  centerMode: true,
	  slidesToShow: 3,
	  prevArrow: $(".cart-a-back"),
	  nextArrow: $(".cart-a-next"),
	  responsive: [
	    {
	      breakpoint: 768,
	      settings: {
	        arrows: false,
	        centerMode: true,
	        centerPadding: '40px',
	        slidesToShow: 3
	      }
	    },
	    {
	      breakpoint: 480,
	      settings: {
	        arrows: false,
	        centerMode: true,
	        centerPadding: '40px',
	        slidesToShow: 1
	      }
	    }
	  ]
	});
}
slickSlide();

var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

function welcome() {
	$(".ratones").addClass("z");

	document.getElementById("player9seg").volume = 0.3;
	document.getElementById("player9seg").play();

	if (iOS) {
		document.getElementById("player15seg2").volume = 0.3;
		document.getElementById("player15seg2").play();
	}

	$(".r-home .splash").removeClass("rhide");

	setTimeout(function() { $(".r-home .top-logos").removeClass("rhide"); }, 1200);
	setTimeout(function() {	$(".r-home .logo").removeClass("rhide"); }, 1800);
	setTimeout(function() { $(".r-home .bajada").removeClass("rhide"); }, 2300);
	setTimeout(function() {
		$(".r-home .r1").removeClass("rhide");
		$(".r-home .r2").removeClass("rhide");
		$(".r-home .r3").removeClass("rhide");
		$(".r-home .r4").removeClass("rhide");
		$(".r-home .r5").removeClass("rhide");
		$(".r-home .r6").removeClass("rhide");
		$(".r-home .r7").removeClass("rhide");
	}, 3000);
	setTimeout(function() { 
		$(".r-home .star1").removeClass("rhide").find("img").addClass("slide-in-fwd-center"); 
	}, 3400);
	setTimeout(function() { 
		$(".r-home .star2").removeClass("rhide").find("img").addClass("slide-in-fwd-center"); 
	}, 3800);

	setTimeout(function() { 
		$(".r-home .star1 img").removeClass("slide-in-fwd-center").addClass("slide-out-fwd-center"); 
	}, 5400);
	setTimeout(function() { 
		$(".r-home .star2 img").removeClass("slide-in-fwd-center").addClass("slide-out-fwd-center"); 
	}, 6200);
	
	setTimeout(function() { 
		$(".r-home .top-logos").addClass("animated fadeOut");
		$(".r-home .logo").addClass("animated fadeOut");
		$(".r-home .rat").addClass("animated fadeOut");
	}, 6700);


	setTimeout(function() { 
		$(".r-home .splash").addClass("animated fadeOut");
	}, 7500);

	setTimeout(function() { 
		$(".ratones").css('background-image',"url(assets/images/spacer.png)");
		if (!iOS) {
			document.getElementById("player15seg").play();
			document.getElementById("player15seg").volume = 0.3;
		}
	}, 8200); 

	setTimeout(function() { 
		initial();
	}, 9000);
}

function initial() {

	$(".ratones").css('background-image',"url(assets/images/spacer.png)");

	$(".r-home").remove();
	$(".r-step2").show();
	//$(".r-start").show();

	$(".ratones .right-menu").addClass("animated fadeIn");
	$(".ratones .left-logos").addClass("animated fadeIn");
	$(".r-start").addClass("animated fadeIn");
	//$(".r-block").show();

	setTimeout(function() { $(".r-start-home-abs").removeClass("rhide"); }, 0);
	setTimeout(function() { 
		$(".moon").removeClass("rhide"); 
		new WOW().init();
		slider.slick('refresh');
	}, 300);
	setTimeout(function() { $(".moon2").removeClass("rhide").addClass("slide-in-fwd-centerX"); }, 800);
	setTimeout(function() { $(".radio").removeClass("rhide"); }, 1500);
	setTimeout(function() { $(".anim_radio").removeClass("rhide").addClass("animated tada"); }, 3200);
	setTimeout(function() { 
		$(".encuentra").removeClass("rhide"); 
		$(".empresas").removeClass("rhide").addClass("animated fadeInDown");  
		$(".radio-triangle-1").removeClass("rhide");
	}, 3800);
	setTimeout(function() { $(".step1").removeClass("rhide").addClass("animated fadeInDown"); }, 4300);
	setTimeout(function() { $(".step2").removeClass("rhide").addClass("animated fadeInDown"); }, 4300);
	setTimeout(function() { $(".step3").removeClass("rhide").addClass("animated fadeInDown"); }, 4300);
	setTimeout(function() { 
		$(".discover").removeClass("rhide").addClass("animated fadeInDown"); 
		$(".discover_mobile").removeClass("rhide").addClass("animated fadeInDown"); 
	}, 4300);

}