// source --> https://wpencryption.com/wp-content/themes/the-consult/js/custom.js?ver=1.1.49 
jQuery(document).ready(function ($) {
  setTimeout(function () {
    $('#page').removeClass('hold');
  }, 100);

  function init() {
    var vidDefer = document.getElementsByTagName('iframe');
    for (var i = 0; i < vidDefer.length; i++) {
      if (vidDefer[i].getAttribute('data-src')) {
        vidDefer[i].setAttribute('src', vidDefer[i].getAttribute('data-src'));
      }
    }
  }
  window.onload = init;

  // $('.main-slider').owlCarousel({

  //   autoplay: true,

  //   controls: true,

  //   autoplayHoverPause: true,

  //   items: 1,

  //   loop: true,

  //   dots: false,

  //   nav: true,

  //   navText: ["<i class='fa fa-angle-left'></i>", "<i class='fa fa-angle-right'></i>"],

  // })

  // $('.consulting-project-slider').owlCarousel({

  //   loop: true,

  //   margin: 25,

  //   responsiveClass: true,

  //   autoplay: true,

  //   dots: false,

  //   nav: true,

  //   navText: ["<i class='fa fa-chevron-left'></i>", "<i class='fa fa-chevron-right'></i>"],

  //   responsive: {

  //     0: {

  //       items: 1,

  //     },

  //     500: {

  //       items: 2,

  //     },

  //     768: {

  //       items: 2,

  //     },

  //     992: {

  //       items: 3,

  //     },

  //     1200: {

  //       items: 3,

  //     }

  //   }

  // })

  // /* Testimonial Carousel */

  // $('.testimonial').owlCarousel({

  //   loop: true,

  //   responsiveClass: true,

  //   autoplay: true,

  //   navText: ["<i class='fa fa-chevron-left'></i>", "<i class='fa fa-chevron-right'></i>"],

  //   responsive: {

  //     0: {

  //       items: 1,

  //     },

  //     768: {

  //       items: 1,

  //     },

  //     992: {

  //       items: 1,

  //     },

  //     1200: {

  //       items: 1,

  //     }

  //   }

  // });

  // Scroll Top

  $('#ed-top').css('bottom', -65);

  $(window).scroll(function () {
    if ($(this).scrollTop() > 300) {
      $('#ed-top').css('bottom', 0);
    } else {
      $('#ed-top').css('bottom', -65);
    }
  });

  $('#ed-top').click(function () {
    $('html,body').animate(
      {
        scrollTop: 0,
      },
      600
    );
  });

  //Counter

  // $('.bt-achievements .counter').counterUp({

  //   delay: 20,

  //   time: 2000

  // });

  //Navigation Icon

  $('.icon').click(function () {
    $('.main-navigation').toggleClass('toggled');
  });

  //fixed Header

  ///$("#masthead").sticky();

  //header search

  $('#masthead').on('click', '.search-toggle', function (e) {
    var selector = $(this).data('selector');

    $(selector).toggleClass('show').find('.search-field').focus();

    $(this).toggleClass('active');

    e.preventDefault();
  });

  // $('#buyprobutton a').click(function () {
  //   gtag('event', 'pro_purchase', {
  //     event_category: 'wpencryptionsite',
  //     event_label: 'buy button click',
  //     value: 40,
  //   });
  // });

  // $('#mixedscan-upgrade a').click(function () {
  //   gtag('event', 'pro_purchase', {
  //     event_category: 'wpencryptionsite',
  //     event_label: 'mixed scan upgrade',
  //     value: 40,
  //   });
  // });

  function isLifetime() {
    if ($('.plan-toggler input').is(':checked')) {
      return true;
    }

    return false;
  }

  var Prohandler = new FS.Checkout({
    plugin_id: '5090',
    plan_id: '8210',
    public_key: 'pk_f6a07c106bf4ef064d9ac4b989e02',
    image: 'https://gowebsmarty.com/wp-letsencrypt.png',
    //checkout_style: 'legacy', //removed
    billing_cycle_selector: 'responsive_list',
    ///billing_cycle_selector: 'list',
  });

  var lcns;
  $('.wpen-pricing-btn,#reviews-buy,#mixedscan-upgrade a').on(
    'click',
    function (e) {
      let plan = 'annual';
      if (isLifetime()) {
        plan = 'lifetime';
      }
      lcns = $(this).attr('data-license');
      var evlu = 49;
      var lc = 1;

      if ($(this).attr('id') == 'bannerbutton') {
        lcns = 'banner';
      } else if ($(this).attr('id') == 'reviews-buy') {
        lcns = 'reviewsbuy';
      } else if ($('body').hasClass('page-id-537')) {
        lcns = 'mxscanpagebuy';
      }

      if (lcns == 'three') {
        evlu = 129;
        lc = 3;
      } else if (lcns == 'unlimited') {
        evlu = 299;
        lc = 0;
      }

      // gtag('event', 'pro_purchase', {
      //   event_category: 'wpencryptionsite',
      //   event_label: plan + '-' + lcns,
      //   value: evlu,
      // });

      Prohandler.open({
        licenses: lc,
        billing_cycle: plan,
        track: function (event, data) {
          const product = data.product;
          const user = data.user;

          switch (event) {
            case 'load':
              // Checkout loaded.
              if (typeof gtag !== 'undefined') {
                console.log('WP Encryption view cart');
                gtag('event', 'add_to_cart', {
                  currency: 'USD',
                  value: 0,
                  items: [
                    {
                      item_id: '5090',
                      item_name: 'WP Encryption',
                      item_category: 'Button-' + lcns,
                    },
                  ],
                });
                gtag('event', 'view_cart', {
                  currency: 'USD',
                  value: evlu,
                  items: [
                    {
                      item_id: '5090',
                      item_name: 'WP Encryption',
                      item_category: 'Button-' + lcns,
                    },
                  ],
                });
              }
              break;
            case 'review-order':
            case 'paypal-express-checkout':
              // User moved to review mode
              if (typeof gtag !== 'undefined') {
                console.log('WP Encryption review order / paypal');
                //console.log(data); //price info not available
                gtag('event', 'begin_checkout', {
                  currency: data.currency.toUpperCase(),
                  value: 1,
                  items: [
                    {
                      item_id: '5090',
                      item_name: 'WP Encryption',
                      item_category: 'Button-' + lcns,
                      item_variant: data.plan.id.toString(),
                      location_id: data.user.country.toString(),
                      price: 1,
                      quantity: 1,
                    },
                  ],
                });
              }
              break;
          }
        },
        purchaseCompleted: function (response) {
          var isTrial = null != response.purchase.trial_ends,
            storeName = 'WP Encryption';
          (isSubscription = null != response.purchase.initial_amount),
            (total = isTrial
              ? 0
              : (isSubscription
                  ? response.purchase.initial_amount
                  : response.purchase.gross
                ).toString());

          if (typeof gtag !== 'undefined') {
            console.log('WP Encryption purchase completed');
            gtag('event', 'purchase', {
              transaction_id: response.purchase.id.toString(), // Transaction ID. Required.
              affiliation: storeName, // Affiliation or store name.
              value: total, // Grand Total.
              shipping: 0, // Shipping.
              tax: 0, // Tax.
              currency: response.purchase.currency.toUpperCase(), // Currency.
              items: [
                {
                  item_id: response.purchase.plugin_id.toString(), // SKU/code.
                  item_variant: response.purchase.plan_id.toString(), // SKU/code.
                  item_name: storeName, // Product name. Required.
                  item_category: 'Button-' + lcns, // Category or variation.
                  price: total, // Unit price.
                  quantity: 1, // Quantity
                  currency: response.purchase.currency.toUpperCase(), // Currency.
                },
              ],
            });

            gtag('event', 'page_view', {
              page_title: '/purchase-completed/',
              page_location: 'wpencryption.com/purchase-completed/',
            });
            gtag('event', 'conversion_event_purchase', {
              value: total,
            });
          }
        },
        success: function (response) {
          // alert(response.user.email);
        },
      });
      e.preventDefault();
    }
  );

  // var Firehandler = FS.Checkout.configure({
  //   plugin_id: '6804',
  //   plan_id: '11103',
  //   public_key: 'pk_b824ba308ac965647594a63abe601',
  //   image: 'http://gowebsmarty.com/wp-letsencrypt.png'
  // });

  $('#buyfirewallcdn,.buyfirewallcdn').on('click', function (e) {
    gtag('event', 'cdn_purchase', {
      event_category: 'wpencryptionsite',
      event_label: 'buy firewall',
      value: 36,
    });

    // Firehandler.open({
    //   licenses: 1,
    //   success: function (response) {
    //     // alert(response.user.email);
    //   }
    // });
    // e.preventDefault();
  });

  $('.showdiff').click(function () {
    $('#wpen-pricing').toggleClass('free');
  });

  // $("#buy-triple-suite a").click(function () {
  //   gtag('event', 'click', {
  //     'event_category': 'wpencryptionsite',
  //     'event_label': 'buy triple suite click',
  //   });
  //   gtag('event', 'conversion', {
  //     'send_to': 'AW-981723734/hRIRCOjs-NEBENbUj9QD',
  //     'transaction_id': ''
  //   });
  // });

  $('.plan-toggler input').change(function () {
    console.log('Plan switch');

    if (isLifetime()) {
      // $(".single-plan large").html("$39<sup>.99</sup>");
      // $(".triple-plan large").html("$109<sup>.99</sup>");
      // $(".unlimited-plan large").html("$249<sup>.99</sup>");
      // $(".lifetime-sticky").text("Lifetime License");
      $('.planprice.lifetime').show();
      $('#wpen-pricing .annuals').hide();
    } else {
      $('#wpen-pricing .annuals').show();
      $('.planprice.lifetime').hide();
      // $(".single-plan large").html("$27<sup>.99</sup>");
      // $(".triple-plan large").html("$79<sup>.99</sup>");
      // $(".unlimited-plan large").html("$199<sup>.99</sup>");
      // $(".lifetime-sticky").text("Annual License");
    }
  });

  // $('#comsites').change(function () {
  //   var chosenval = $(this).val();
  //   var price = $('.dolprice span');
  //   var buylink = $('.comodo .p2-button a');

  //   if (chosenval == 1) {
  //     price.text(33);
  //     buylink.attr(
  //       'href',
  //       'https://checkout.freemius.com/mode/dialog/plugin/11510/plan/19608/licenses/1/'
  //     );
  //   } else if (chosenval == 5) {
  //     price.text(173);
  //     buylink.attr(
  //       'href',
  //       'https://checkout.freemius.com/mode/dialog/plugin/11510/plan/19608/licenses/5/'
  //     );
  //   } else if (chosenval == 10) {
  //     price.text(353);
  //     buylink.attr(
  //       'href',
  //       'https://checkout.freemius.com/mode/dialog/plugin/11510/plan/19608/licenses/10/'
  //     );
  //   } else if (chosenval == 25) {
  //     price.text(753);
  //     buylink.attr(
  //       'href',
  //       'https://checkout.freemius.com/mode/dialog/plugin/11510/plan/19608/licenses/25/'
  //     );
  //   }
  // });

  // $('.p2-button a').click(function () {
  //   gtag('event', 'pro_purchase', {
  //     event_category: 'wpencryptionsite',
  //     event_label: 'pricingv2 buy',
  //     value: 0,
  //   });
  // });

  // $('#reviews-buy').click(function () {
  //   gtag('event', 'pro_purchase', {
  //     event_category: 'wpencryptionsite',
  //     event_label: 'reviewsv2 buy',
  //     value: 0,
  //   });
  // });

  // $("body").niceScroll({
  //   cursorcolor: "#005AE9",
  //   scrollspeed: "60",
  //   cursorborder: "1px solid #eee",
  // });

  $('.gws-tilt img').tilt({
    glare: true,
    maxGlare: 0.3,
    maxTilt: 10,
  });

  var hsh = window.location.hash;
  $(window).on('load', function () {
    if (hsh) {
      //setTimeout(function () {
      var ofs = $(hsh).offset();
      $('html,body').animate(
        {
          scrollTop: ofs.top - 20,
        },
        600
      );
      return false;
      //}, 500);
    }
  });

  /*
   * Light YouTube Embeds by @labnol
   * Credit: https://www.labnol.org/
   */

  function labnolIframe(div) {
    var iframe = document.createElement('iframe');
    iframe.setAttribute(
      'src',
      'https://www.youtube.com/embed/' + div.dataset.id + '?autoplay=1&rel=0'
    );
    iframe.setAttribute('frameborder', '0');
    iframe.setAttribute('allowfullscreen', '1');
    iframe.setAttribute(
      'allow',
      'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
    );
    div.parentNode.replaceChild(iframe, div);
  }

  function initYouTubeVideos() {
    console.log('Videos init');
    var playerElements = document.getElementsByClassName('youtube-player');
    for (var n = 0; n < playerElements.length; n++) {
      var videoId = playerElements[n].dataset.id;
      var div = document.createElement('div');
      div.setAttribute('data-id', videoId);
      var thumbNode = document.createElement('img');
      thumbNode.src = '//i.ytimg.com/vi/ID/hqdefault.jpg'.replace(
        'ID',
        videoId
      );
      div.appendChild(thumbNode);
      var playButton = document.createElement('div');
      playButton.setAttribute('class', 'play');
      div.appendChild(playButton);
      div.onclick = function () {
        labnolIframe(this);
      };
      playerElements[n].appendChild(div);
    }
  }

  initYouTubeVideos();

  //document.addEventListener('DOMContentLoaded', initYouTubeVideos);
});

jQuery(window).on('load', function () {
  jQuery('#reviewsv2-slides .elementor-widget-wrap').bxSlider({
    auto: true,
    //autoHover: true,
    slideMargin: 40,
    speed: 10000,
    pause: 10000,
    pager: false,
    minSlides: 1,
    maxSlides: 4,
    moveSlides: 1,
    slideWidth: 400,
    //preloadImages: 'all',
    //shrinkItems: true
  });
});

jQuery(document).ready(function () {
  // Set the date we're counting down to
  var countDownDate = new Date().getTime() + 6 * 60 * 60 * 1000;

  // Update the count down every 1 second
  var x = setInterval(function () {
    var now = new Date().getTime();
    var distance = countDownDate - now;

    // Time calculations for hours, minutes and seconds
    var hours = Math.floor(
      (distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
    );
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    // Output the result in an element with id="countdown"
    jQuery('#wple-sales-countdown').html(
      hours + ' : ' + minutes + ' : ' + seconds
    );

    // If the count down is finished, write some text
    // if (distance < 0) {
    //     clearInterval(x);
    //     $('#countdown').html("EXPIRED");
    // }
  }, 1000);
});