//codice per header fisso al top della pagina
$(window).scroll(function() {
if ($(this).scrollTop() > 1){  
    $('header').addClass("affix");
  }
  else{
	$('header').removeClass("affix");
   
  }
var top = $(window).scrollTop();
if (top == 0) {
	$('body').removeClass('scrolled');
} else {
	$('body').addClass('scrolled');
}
		
if ($(this).scrollTop() > 300){  
    $('#scroll-up').addClass("is-visible");
  }
  else{
	$('#scroll-up').removeClass("is-visible");
   
  }
});

$(document).ready(function() {

		$('#scroll-up').click(function(e){
			e.preventDefault();
			$('html, body').stop().animate({	
				scrollTop: 0 
			},800)
			return false;
		});	
});


// codice per menu mobile
$('.btn-navbar').on('click', function(e) {
	$(this).toggleClass('active');
	$('.header-nav').toggleClass('active fadeInDown');
	$('.header').toggleClass('active');
	e.preventDefault();
});



$('.fade1').waypoint(function() {
	$('.fade1').addClass('animated fadeIn');
}, {
	offset: '60%'
});
$('.fade2').waypoint(function() {
	$('.fade2').addClass('animated fadeIn delay-5s');
}, {
	offset: '60%'
});




$('.ani1').waypoint(function() {
	$('.ani1').addClass('animated bounceInLeft');
}, {
	offset: '60%'
});
$('.ani2').waypoint(function() {
	$('.ani2').addClass('animated bounceInRight delay-5s');
}, {
	offset: '60%'
});
$('.ani3').waypoint(function() {
	$('.ani3').addClass('animated bounceInLeft');
}, {
	offset: '60%'
});
$('.ani4').waypoint(function() {
	$('.ani4').addClass('animated bounceInRight');
}, {
	offset: '60%'
});
$('.ani5').waypoint(function() {
	$('.ani5').addClass('animated bounceInLeft');
}, {
	offset: '60%'
});
$('.ani6').waypoint(function() {
	$('.ani6').addClass('animated bounceInRight delay-5s');
}, {
	offset: '60%'
});
$('.ani7').waypoint(function() {
	$('.ani7').addClass('animated bounceInLeft');
}, {
	offset: '60%'
});
$('.ani8').waypoint(function() {
	$('.ani8').addClass('animated bounceInRight delay-5s');
}, {
	offset: '60%'
});


$('.aniB0').waypoint(function() {
	$('.aniB0').addClass('animated fadeIn');
}, {
	offset: '100%'
});
$('.aniB1').waypoint(function() {
	$('.aniB1').addClass('animated bounceIn delay-5s');
}, {
	offset: '100%'
});
$('.aniB2').waypoint(function() {
	$('.aniB2').addClass('animated bounceInDown');
}, {
	offset: '100%'
});
$('.aniB3').waypoint(function() {
	$('.aniB3').addClass('animated flipInX');
}, {
	offset: '100%'
});
$('.aniB4').waypoint(function() {
	$('.aniB4').addClass('animated flipInX delay-5s');
}, {
	offset: '100%'
});
$('.aniB5').waypoint(function() {
	$('.aniB5').addClass('animated flipInX delay-10s');
}, {
	offset: '100%'
});
$('.aniB6').waypoint(function() {
	$('.aniB6').addClass('animated flipInX delay-15s');
}, {
	offset: '100%'
});
$('.aniB7').waypoint(function() {
	$('.aniB7').addClass('animated flipInX delay-20s');
}, {
	offset: '100%'
});

$('.aniB8').waypoint(function() {
	$('.aniB8').addClass('animated flipInX delay-25s');
}, {
	offset: '100%'
});
$('.aniB9').waypoint(function() {
	$('.aniB9').addClass('animated flipInX delay-30s');
}, {
	offset: '100%'
});





$('.news1').waypoint(function() {
	$('.news1').addClass('animated fadeInUp');
}, {
	offset: '100%'
});
$('.news2').waypoint(function() {
	$('.news2').addClass('animated fadeInUp delay-5s');
}, {
	offset: '100%'
});
$('.news3').waypoint(function() {
	$('.news3').addClass('animated fadeInUp delay-10s');
}, {
	offset: '100%'
});
$('.news4').waypoint(function() {
	$('.news4').addClass('animated fadeInUp delay-15s');
}, {
	offset: '100%'
});
$('.news5').waypoint(function() {
	$('.news5').addClass('animated fadeInUp delay-20s');
}, {
	offset: '100%'
});
$('.news6').waypoint(function() {
	$('.news6').addClass('animated fadeInUp delay-25s');
}, {
	offset: '100%'
});
$('.news7').waypoint(function() {
	$('.news7').addClass('animated fadeInUp delay-30s');
}, {
	offset: '100%'
});
$('.news8').waypoint(function() {
	$('.news8').addClass('animated fadeInUp delay-35s');
}, {
	offset: '100%'
});
$('.news9').waypoint(function() {
	$('.news9').addClass('animated fadeInUp delay-40s');
}, {
	offset: '100%'
});
$('.news10').waypoint(function() {
	$('.news10').addClass('animated fadeInUp delay-45s');
}, {
	offset: '100%'
});
$('.news11').waypoint(function() {
	$('.news11').addClass('animated fadeInUp delay-50s');
}, {
	offset: '100%'
});
$('.news12').waypoint(function() {
	$('.news12').addClass('animated fadeInUp delay-55s');
}, {
	offset: '100%'
});
$('.news13').waypoint(function() {
	$('.news13').addClass('animated fadeInUp delay-60s');
}, {
	offset: '100%'
});
$('.news14').waypoint(function() {
	$('.news14').addClass('animated fadeInUp delay-65s');
}, {
	offset: '100%'
});
$('.news15').waypoint(function() {
	$('.news15').addClass('animated fadeInUp delay-70s');
}, {
	offset: '100%'
});
$('.news16').waypoint(function() {
	$('.news16').addClass('animated fadeInUp delay-75s');
}, {
	offset: '100%'
});
$('.news17').waypoint(function() {
	$('.news17').addClass('animated fadeInUp delay-80s');
}, {
	offset: '100%'
});
$('.news18').waypoint(function() {
	$('.news18').addClass('animated fadeInUp delay-85s');
}, {
	offset: '100%'
});
$('.news19').waypoint(function() {
	$('.news19').addClass('animated fadeInUp delay-90s');
}, {
	offset: '100%'
});
$('.news20').waypoint(function() {
	$('.news20').addClass('animated fadeInUp delay-95s');
}, {
	offset: '100%'
});
$('.news21').waypoint(function() {
	$('.news21').addClass('animated fadeInUp delay-100s');
}, {
	offset: '100%'
});
$('.news22').waypoint(function() {
	$('.news22').addClass('animated fadeInUp delay-105s');
}, {
	offset: '100%'
});
$('.news23').waypoint(function() {
	$('.news23').addClass('animated fadeInUp delay-110s');
}, {
	offset: '100%'
});
$('.news24').waypoint(function() {
	$('.news24').addClass('animated fadeInUp delay-115s');
}, {
	offset: '100%'
});
$('.news25').waypoint(function() {
	$('.news25').addClass('animated fadeInUp delay-120s');
}, {
	offset: '100%'
});


$('.aniC1').waypoint(function() {
	$('.aniC1').addClass('animated fadeInUp');
}, {
	offset: '100%'
});

$('.aniC2').waypoint(function() {
	$('.aniC2').addClass('animated fadeInUp delay-5s');
}, {
	offset: '100%'
});

$('.aniC3').waypoint(function() {
	$('.aniC3').addClass('animated fadeInUp delay-10s');
}, {
	offset: '100%'
});


// video you tube
var player,
    time_update_interval = 0;

function onYouTubeIframeAPIReady() {
    player = new YT.Player('video-placeholder', {
		frameborder: 0,
        //videoId: 'OIrKycPnmyQ',
		videoId: 'JsL9-i1iDjs',
        playerVars: {'rel':0, 'modestbranding':1, 'autoplay': 1, 'version':3, 'loop':1, 'playlist':'JsL9-i1iDjs', 'controls': 0, 'showinfo':0, 'branding':0,  'autohide':0, 'enablejsapi':1 },
		
        events: {
			onReady: function(e) {
				e.target.mute();
				onReady: initialize
			  }  
        }
		
    });
}


$('#mute-toggle').on('click', function() {
    var mute_toggle = $(this);

    if(player.isMuted()){
        player.unMute();
		$('#mute-toggle').removeClass('off');
        $('#mute-toggle').addClass('on');
    }
    else{
        player.mute();
		$('#mute-toggle').removeClass('on');
        $('#mute-toggle').addClass('off');
    }
});


function onPlayerReady(event) {
        event.target.playVideo();
      }


function initialize(){
    updateTimerDisplay();
    updateProgressBar();
    clearInterval(time_update_interval);
    time_update_interval = setInterval(function () {
        updateTimerDisplay();
        updateProgressBar();
		player.playVideo();
    }, 1000);
}



var caroselloSwiper = new Swiper('.swiper-carosello', {
	pagination: $('.swiper-carosello .swiper-pagination'),
	paginationClickable: true,
	slidesPerView: 5,
	spaceBetween: 0,
	breakpoints: {
		1000: {slidesPerView: 4},
		740: {slidesPerView: 3},
		560: {slidesPerView: 2},
		340: {slidesPerView: 1}
	}
});


var caroselloSwiper = new Swiper('.swiper-inst', {
	pagination: $('.swiper-inst .swiper-pagination'),
	paginationClickable: true,
	autoplay:2000,
	slidesPerView: 4,
	spaceBetween: 0,
	breakpoints: {
		1200: {slidesPerView: 3},
		740: {slidesPerView: 2},
		400: {slidesPerView: 1}
	}
});