"use strict"
$(document).ready(function () {

    $('#screen_slider').owlCarousel({
        loop:false,
        margin:0,
        nav:false,
        items:1,
        startPosition: 0,

    });

    $('.screenshots .screenshot').click(function () {

        $('#screen_slider').trigger('to.owl.carousel', $(this).data('screen'))

    });


    $('#screen_slider').on('changed.owl.carousel', function(event) {
        var current = event.item.index;

        $('.screenshots .screenshot').removeClass('active');
        $('.screenshots .screenshot[data-screen='+current+']').addClass('active');
    });

    $(".nav-link, .btn-download").on('click',function(e) {
        $('html,body').animate({
                scrollTop: $($(this).attr('href')).offset().top},
            'slow');
        e.preventDefault();
    });


    $('#videoModal').on('show.bs.modal', function (e) {
        var idVideo = $(e.relatedTarget).data('id');
        $('#videoModal .embed_video').html('<iframe width="100%" height="450px" src="https://www.youtube.com/embed/' + idVideo + '?autoplay=true&rel=0&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>');
        setTimeout(setVideoHeight , 1000);

    });
//on close remove
    $('#videoModal').on('hidden.bs.modal', function () {
        $('#videoModal .embed_video').empty();
    });

    $(window).resize(function () {
        setVideoHeight();
    })

    function  setVideoHeight() {
        var videoWidth = $('.modal-body iframe').width();
        var ratio = Math.round((videoWidth/16)*9);
        $('.modal-body iframe').css('height',  ratio  + 'px');
    }

    // if (window.location.pathname.split('/')[1]) {
    //     var path = window.location.pathname.split('/')[1];
    //     if (!path.includes("index") && !path.includes("disclosure") && !path.includes("privacy") && !path.includes("business") && !path.includes("store")) {
    //         window.location.href="pay.html?tag="+path;
    //     }
    // }
});

$(window).on('load', function (e) {
  var url = document.location.toString();
  if ( url.match('#') && url.split('#')[1] == 'feesFaq') {
       var element = url.split('#')[1];
       $('#'+element).click();
       setTimeout(scrollToFaq(element) , 1000);
  }
});

function scrollToFaq(element) {
  $('html, body').animate({
       scrollTop: $('#'+element).offset().top
   }, 500);
}

function updateOdometer() {
    $.get('/api/v1/wos_stats', function (data) {
        if (data && data.c) {
            odometer.innerHTML = data.c;
        }
    });
}

updateOdometer();
setInterval(function(){
    updateOdometer();
}, 60000);