//TODO: needs refactoring in future, gather tother with range-type.js for common script
var Wick = Wick || {};

Wick.RangeTypes = (function () {
  var $button = $('.range-cards-wrapper .range-types__load-button'),
    $rangeCards = $('.range-cards-wrapper'),
    rangeCardOpen = 'range-cards-wrapper_open',
    $buttonsRange = $rangeCards.find($button);

  function toggle(e) {
    if ($rangeCards.hasClass(rangeCardOpen)) {
      $('html, body').scrollTop($rangeCards.offset().top - 30);
    }
    $rangeCards.toggleClass(rangeCardOpen);
    $buttonsRange.toggle();
    Wick.GalleryRange.refresh($('.gallery.gallery_range').slice(2));
  }

  $buttonsRange.on('click', toggle);
})();
