var Wick = Wick || {};
Wick.BackToTop = (function () {
  var $backToTop = $('#back-to-top'),
    scrollTrigger = 200,
    actionSpeed = 700;

  function checkScrollPosition () {
    $(window).scrollTop() > scrollTrigger
      ? $backToTop.fadeIn(300)
      : $backToTop.fadeOut(300);
  }

  $(window).on('scroll', _.debounce(checkScrollPosition, 200));

  $backToTop.click(function () {
    $backToTop.prop("disabled", true);

    setTimeout(function () {
      $backToTop.prop("disabled", false);
    }, actionSpeed);

    $('html, body').animate({
      scrollTop: 0
    }, actionSpeed);
  });
})();
