/* Minification failed. Returning unminified contents.
(164,45-46): run-time error JS1195: Expected expression: >
(167,10-11): run-time error JS1195: Expected expression: )
(169,10-11): run-time error JS1195: Expected expression: )
(172,41-42): run-time error JS1004: Expected ';': {
 */
$(document).ready(function(){
  var firstBlink = $(".grid-section .sk-blink").first();
  var firstBlinkButton = $(".grid-section .sk-blink .sk-promo-link").first();
  var secondBlink = firstBlink.next();
  secondBlink.addClass("test-blink");
  var secondBlinkButton = $(".test-blink .sk-promo-link");
  var thirdBlink = secondBlink.next();
  var fourthBlink = thirdBlink.next();
  var fifthBlink = fourthBlink.next();

  firstBlink.addClass("blink-show");
  $(".grid-section .sk-blink").not([firstBlink]).addClass("blink-hidden");
  var currentActive = $(".blink-show");


  firstBlinkButton.on("click", function(e){
    var counter = 1;
    var myInterval = setInterval(function () {
      $('.test-blink .sk-grid-richtext h2:last-child').html("<h2>" + counter + "</h2>");
      ++counter;
    }, 1000);

    var nextActive = secondBlink;
    currentActive.removeClass("blink-show").addClass("blink-hidden");
    nextActive.removeClass("blink-hidden").addClass("blink-show");

    var timer = setTimeout(function(){
      nextActive = fifthBlink;
      counter--;
      secondBlink.removeClass("blink-show").addClass("blink-hidden");
      nextActive.removeClass("blink-hidden").addClass("blink-show");
      $(".blink-show .sk-grid-richtext h2:nth-child(2)").html("<h2>" + counter + "</h2>");
      $(".blink-show .sk-promo-row .col-md-6:first-child .sk-promo-slot-link").on("click", function(e){
        nextActive = firstBlink;
        fifthBlink.removeClass("blink-show").addClass("blink-hidden");
        nextActive.removeClass("blink-hidden").addClass("blink-show");
        counter= 0;
        clearInterval(myInterval);
        $('.test-blink .sk-grid-richtext h2:last-child').html("<h2>0</h2>");
        e.preventDefault();
      });
    },15000);


      secondBlinkButton.on("click", function(e){
        counter--;
        if(counter < 5){
          nextActive = thirdBlink;
          secondBlink.removeClass("blink-show").addClass("blink-hidden");
          fourthBlink.removeClass("blink-show").addClass("blink-hidden");
          fifthBlink.removeClass("blink-show").addClass("blink-hidden");
          nextActive.removeClass("blink-hidden").addClass("blink-show");
          $(".blink-show .sk-grid-richtext h2:nth-child(2)").html("<h2>" + counter + "</h2>");
          clearTimeout(timer);
          counter= 0;

          $(".blink-show .sk-promo-row .col-md-6:first-child .sk-promo-slot-link").on("click", function(e){
            nextActive = firstBlink;
            thirdBlink.removeClass("blink-show").addClass("blink-hidden");
            fifthBlink.removeClass("blink-show").addClass("blink-hidden");
            nextActive.removeClass("blink-hidden").addClass("blink-show");
            clearInterval(myInterval);
            $('.test-blink .sk-grid-richtext h2:last-child').html("<h2>0</h2>");
            e.preventDefault();
          });
        }
        else if(counter < 10){
          nextActive = fourthBlink;
          secondBlink.removeClass("blink-show").addClass("blink-hidden");
          thirdBlink.removeClass("blink-show").addClass("blink-hidden");
          fifthBlink.removeClass("blink-show").addClass("blink-hidden");
          nextActive.removeClass("blink-hidden").addClass("blink-show");
          $(".blink-show .sk-grid-richtext h2:nth-child(2)").html("<h2>" + counter + "</h2>");
          clearTimeout(timer);

          $(".blink-show .sk-promo-row .col-md-6:first-child .sk-promo-slot-link").on("click", function(e){
            nextActive = firstBlink;
            fourthBlink.removeClass("blink-show").addClass("blink-hidden");
            nextActive.removeClass("blink-hidden").addClass("blink-show");
            clearInterval(myInterval);
            $('.test-blink .sk-grid-richtext h2:last-child').html("<h2>0</h2>");
            e.preventDefault();
          });
        }
        else if(counter < 15){
          nextActive = fifthBlink;
          secondBlink.removeClass("blink-show").addClass("blink-hidden");
          thirdBlink.removeClass("blink-show").addClass("blink-hidden");
          fourthBlink.removeClass("blink-show").addClass("blink-hidden");
          nextActive.removeClass("blink-hidden").addClass("blink-show");
          $(".blink-show .sk-grid-richtext h2:nth-child(2)").html("<h2>" + counter + "</h2>");
          clearTimeout(timer);

          $(".blink-show .sk-promo-row .col-md-6:first-child .sk-promo-slot-link").on("click", function(e){
            nextActive = firstBlink;
            fifthBlink.removeClass("blink-show").addClass("blink-hidden");
            nextActive.removeClass("blink-hidden").addClass("blink-show");
            counter= 0;
            clearInterval(myInterval);
            $('.test-blink .sk-grid-richtext h2:last-child').html("<h2>0</h2>");
            e.preventDefault();
          });
        }


              clearInterval(myInterval);
              e.preventDefault();
            });
    e.preventDefault();
  });
});
// Open modal after shop image click
$( ".sk-product-page-extended .sk-buy-now-btn" ).click(function() {
    event.preventDefault();
    $( ".sk-buy-online-shops-modal" ).addClass("sk-buy-online-shops-modal--show");
    $( ".sk-buy-online-shops-modal-links" ).find('a').attr('target', 'new');
});

// Close modal after link image button click
$( ".sk-buy-online-shops-modal-links .sk-grid-image-as-link" ).click(function() {
    $( ".sk-buy-online-shops-modal" ).removeClass("sk-buy-online-shops-modal--show")
});

// Close modal after link text button click
$( ".sk-buy-online-shops-modal-links .sk-grid-richtext" ).click(function() {
    $( ".sk-buy-online-shops-modal" ).removeClass("sk-buy-online-shops-modal--show")
});

// Close modal after "x" button click
$( ".sk-buy-online-shops-modal-close-button" ).click(function() {
    event.preventDefault();
    $( ".sk-buy-online-shops-modal" ).removeClass("sk-buy-online-shops-modal--show")
});

// Buy online header navigation MODAL: 
var formPopupClass = '.buy-online-nav-popup';
var formContainerClass = '.sk-buy-online-list';
// button in navigation: Site configuration > starter kit > navigation > POPUP LINKS > custm CSS class: 'buy-online-popup'
// content of modal in home > 'ver-en-farmacia' - 'Buy Online Page' > 3x Buy Online Store Page
// css - modules > sections > page > 'nav-modal.less'
$(document).ready(function() {
    var navModalOpenButton = $('.sk-popup-nav-item--buy-online-popup');
    $(navModalOpenButton.find('a')).on('click', function(e) {
        e.preventDefault();
        e.stopPropagation();
        var agreeBtn = $('.sk-modal--buy-online-popup .sk-modal-btn--agree');
        loadFormInPopup(agreeBtn.attr('href'));
    });
});

function loadFormInPopup(link) {
    var popupBox = $(formPopupClass);
    if (popupBox.length > 0) {
        popupBox.addClass('open');
        return;
    }
    popupBox = $('<div>').addClass(formPopupClass.substring(1)); //need to remove first char (dot)
    popupBox.addClass('open');
    $('body').append(popupBox);

    $.get(link, function(data) {
        var list = $(data).find(formContainerClass);
        popupBox.append(list);
        $(list).find('img').map( (i, item) => { // data-src -> src
            var uncroppedPath = $(item).attr('data-src').split('?')[0];
            $(item).attr('src', uncroppedPath);
        })
        addCloseButton(list, popupBox);
        });
};

function addCloseButton(list, popupBox) {
    var btn = $('<button>')
        .addClass('popup-close-button')
        .text('✖')
        .appendTo(list);
    btn.on('click', function(e) {
        popupBox.removeClass('open');
    });
};
$(document).ready(function() {
    var pageTitle = $('head title').text().trim().replace(/'/g, "");
    if($('body').hasClass('RBStarterKitProductPage')) {
      var productName = $('.sk-product-header h1').text().trim().replace(/'/g, "");
      $('head').prepend("<script> window.dataLayer = window.dataLayer || []; window.dataLayer.push({'pageTitle': '" + pageTitle + "', 'productName': '" + productName + "'}); </script>");
    }
    else if($('body').hasClass('RBStarterKitProductListPage')) {
      var productList = [];
      var query = $('.sk-product-list-item-title');
      query.each(function() {
        var product = $(this).text().trim().replace(/'/g, "");
        product = "'" + product + "'";
      	productList.push(product);
      });
        $('head').prepend("<script> window.dataLayer = window.dataLayer || []; window.dataLayer.push({'pageTitle': '" + pageTitle + "', 'productList': [" + productList + "]}); </script>");
    }
    else {
      $('head').prepend("<script> window.dataLayer = window.dataLayer || []; window.dataLayer.push({'pageTitle': '" + pageTitle + "'}); </script>");
    }
});
$(document).ready(function() {
  var d = $('#cdc-form div.checkbox').add($('div.form-group > div')),
    l = d.children('label'),
    c = $('input:checkbox'),
    a = $('label > a');
  d.find(l).each(function() {
    $(this).children('input').prependTo($(this).parent(d));
  });
  d.find(c).each(function() {
    name = $(this).attr('name');
    $(this).attr('id', name);
    $(this).next('label').attr('for', name);
  });
});
$(document).ready(function(){
  $("#rb-ipredirect-close").on("click", function(e){
    $(".clp-title").css("display", "none");
    e.preventDefault();
  });
});