var _____WB$wombat$assign$function_____=function(name){return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name))||self[name];};if(!self.__WB_pmw){self.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}{
let window = _____WB$wombat$assign$function_____("window");
let self = _____WB$wombat$assign$function_____("self");
let document = _____WB$wombat$assign$function_____("document");
let location = _____WB$wombat$assign$function_____("location");
let top = _____WB$wombat$assign$function_____("top");
let parent = _____WB$wombat$assign$function_____("parent");
let frames = _____WB$wombat$assign$function_____("frames");
let opens = _____WB$wombat$assign$function_____("opens");


function nitroThumb(e) {
    return (
      '<img src="' + document.getElementById(e).getAttribute("data-thumb") + '" alt="' + document.getElementById(e).getAttribute("data-thumbalt") + '">'
      ).replace("ID", e) + '<a href="#" class="et_pb_video_play"></a>'
  }
  
  function machineYoutubeFrame(event) {
    event.preventDefault();
    var iframe = document.createElement("iframe");
    iframe.setAttribute(
      "src",
      "https://www.youtube.com/embed/" + this.dataset.id + "?autoplay=1&mute=1"
    );
    iframe.setAttribute("frameborder", "0");
    iframe.setAttribute("allowfullscreen", "1");
    iframe.setAttribute("allow", "autoplay; fullscreen");
  
    // Create wrapper just like fitVids
    var wrapper = document.createElement("div");
    wrapper.className = "fluid-width-video-wrapper";
    wrapper.style.paddingTop = "56.25%";
  
    // Style iframe like fitVids does
    iframe.style.position = "absolute";
    iframe.style.top = "0";
  
    wrapper.appendChild(iframe);
  
    // Replace the thumbnail container with the wrapped iframe
    this.parentNode.replaceWith(wrapper);
  }
  
  function machineVimeoFrame(event) {
    event.preventDefault();    

    var e = document.createElement("iframe");
    var videoId = this.dataset.id;

    e.setAttribute("src", "https://player.vimeo.com/video/" + videoId + "?autoplay=1&muted=1");
    e.setAttribute("frameborder", "0");
    e.setAttribute("allow", "autoplay; fullscreen");
    e.setAttribute("allowfullscreen", "1");

    this.parentNode.replaceChild(e, this);    
  }
  
  function initializeVideoListeners() {
    var e, t, r = document.getElementsByClassName("de_demach_youtube_listener");
    for (t = 0; t < r.length; t++) {
        e = document.createElement("div");
        e.setAttribute("data-id", r[t].dataset.id);
        e.innerHTML = nitroThumb(r[t].dataset.id);
        e.onclick = machineYoutubeFrame;
        r[t].appendChild(e);
    }
  
    r = document.getElementsByClassName("de_demach_vimeo_listener");
    for (t = 0; t < r.length; t++) {
        e = document.createElement("div");
        e.setAttribute("data-id", r[t].dataset.id);
        e.innerHTML = nitroThumb(r[t].dataset.id);
        e.onclick = machineVimeoFrame;
        r[t].appendChild(e);
    }
  }
  
  document.addEventListener("DOMContentLoaded", function() {
    initializeVideoListeners();
  });
  
  // Reinitialize listeners when the AJAX filter completes
  jQuery(document).on('divi_filter_completed', function() {
    initializeVideoListeners();
  });
    
    jQuery(document).ready(function ($) {
    
      /*$(document.body).on('click', '.et_pb_de_mach_search_posts .et_pb_button', function () {
        $(this).closest(".et_pb_de_mach_search_posts").find("#dmach-search-form").submit();
      });*/
    
    
    
      /*  $(document).on('click', '.show_modal', function(e){
          e.preventDefault();
          e.stopPropagation();
          var srcContent = $($(this).attr('data-mfp-src')).html();
          $.magnificPopup.open({
          items: {
            src: srcContent, // can be a HTML string, jQuery object, or CSS selector
            type: 'inline'
          }
        });
        });*/
    
      if (typeof jQuery.fn.magnificPopup !== 'undefined') {
          $('.et_pb_de_mach_gallery_trigger').magnificPopup({
              type:'inline',
              midClick: true // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href.
          });
      }
    
      $(document.body).on('click', '.dmach-link-whole-grid-card', function () {
        var url = $(this).data("link-url");
        window.location.href = url;
      });
    
    
    
      main_count = Number(0);
    
      $('.dmach-search-items').each(function (i, obj) {
        main_count = Number(0);
        $(this).children('.et_pb_de_mach_search_posts_item').each(function (i, obj) {
          var count = Number($(this).find(".search_filter_cont").attr("data-count"));
          main_count = main_count + count;
          if (main_count >= "100") {
            $(this).addClass("last-item");
            main_count = Number(0);
          }
    
        });
      });
    
    
      $(".search_filter_cont").removeClass("hidden");
      $(".button_container").removeClass("hidden");
    
      $('#select_post_types').on('change', function () {
        var post_type_change = this.value;
        $("#search_post_type").val(post_type_change);
    
      });
    
      // end
    
      var columns = $(".filtered-posts").attr("data-columns");
      $(".filtered-posts").find(".et_pb_column").addClass(columns)
    
      $(window).click(function () {
        $(".et_pb_de_mach_search_posts_item").removeClass("visible");
      });
    
      $('.et_pb_de_mach_search_posts_item').click(function (event) {
        event.stopPropagation();
      });
    
      $(".dmach-filer-toggle .et_pb_contact_field_options_title ").click(function (e) {
    
        if ($(this).closest(".et_pb_de_mach_search_posts_item").hasClass("visible")) {
          $(".et_pb_de_mach_search_posts_item").removeClass("visible");
        } else {
          $(".et_pb_de_mach_search_posts_item").removeClass("visible");
          $(this).closest(".et_pb_de_mach_search_posts_item").addClass("visible");
        }
    
      });
    
      $('.dmach-tag-cloud a').click(function (e) {
    
        var theClass = $(this).attr("class").match(/tag-link-[\w-]*\b/);
    
        $(this).closest(".dmach-tag-cloud").find("select").val(theClass);
        $(this).closest(".dmach-tag-cloud").find("select").trigger("change");
    
      });
    
    
      get_post_popup();
    
    });
    
    jQuery(document).on('click', '.dmach-popup .modal-close', function (e) {
      e.preventDefault();
      jQuery(this).closest('.dmach-popup').removeClass('open');
      jQuery('html').css('overflow', 'auto');
      jQuery('a').css('pointer-events','none');
      setTimeout(
        function() 
        {
          jQuery('a').css('pointer-events','');
        }, 100);
    });
    
    jQuery(document).on('touchstart click', '.dmach-popup', function () {
      jQuery(this).closest('.dmach-popup').removeClass('open');
      jQuery('html').css('overflow', 'auto');
      jQuery('a').css('pointer-events','none');
      setTimeout(
        function() 
        {
          jQuery('a').css('pointer-events','');
        }, 100);
    });
    
    
    jQuery(document).on('touchstart click', '.post-modal-cont', function (event) {
      event.stopPropagation();
    });
    
    jQuery(document).on('touchstart click', '.dmach-next-post', function (event) {
      if (jQuery(this).closest('.dmach-popup').next('.dmach-popup').length) {
        jQuery(this).closest('.dmach-popup').removeClass('open');
        jQuery(this).closest('.dmach-popup').next('.dmach-popup').addClass('open');
      } else {
        jQuery(this).closest('.dmach-popup').removeClass('open');
        jQuery('html').css('overflow', 'auto');
      }
    });
    
    
    jQuery(document).on('touchstart click', '.dmach-prev-post', function (event) {
      if (jQuery(this).closest('.dmach-popup').prev('.dmach-popup').length) {
        jQuery(this).closest('.dmach-popup').removeClass('open');
        jQuery(this).closest('.dmach-popup').prev('.dmach-popup').addClass('open');
      } else {
        jQuery(this).closest('.dmach-popup').removeClass('open');
        jQuery('html').css('overflow', 'auto');
      }
    });
    
    
    function get_post_popup() {
      jQuery('.dmach-popup').remove();
      if (jQuery('.show_modal').length > 0) {
    
        var modal_style = jQuery('.show_modal').eq(0).attr('data-modal-style');
    
        var post_ids = [];
        var modal_layouts = [];
        var modal_posttypes = [];
        var post_type = jQuery('.show_modal').eq(0).closest('.divi-filter-archive-loop').attr('data-posttype');
        jQuery('.show_modal').each(function () {
          var post_id = jQuery(this).attr('data-id');
          var modal_layout = jQuery(this).attr('data-modal-layout');
          var modal_postype = jQuery(this).attr('data-modal-postype');
          var m_index = modal_layouts.indexOf( modal_layout );
          if ( m_index != -1 ) {
            post_ids[m_index].push( post_id );
          } else {
            modal_layouts.push( modal_layout );
            modal_posttypes.push( modal_postype );
            post_ids.push([post_id]);
          }
        });
    
        if (jQuery(".et-l--body").length) {
          jQuery('.et-l--body').append('<div id="dmach-modal-wrapper" class="' + modal_style + ' loading"><div id="loading-modal" modallayout-id="" modaldata-id="" class="dmach-popup"><div class="post-modal-cont"><div class="modal-close"></div><div class="et_pb_section"><div class="et_pb_row"><div class="et_pb_column et_pb_column_4_4"><div class="filtered-posts-loading load-3"><span class="line"></span><span class="line"></span><span class="line"></span></div></div></div></div></div></div></div>');
        } else {
          jQuery('#page-container').append('<div id="dmach-modal-wrapper" class="' + modal_style + ' loading"><div id="loading-modal" modallayout-id="" modaldata-id="" class="dmach-popup"><div class="post-modal-cont"><div class="modal-close"></div><div class="et_pb_section"><div class="et_pb_row"><div class="et_pb_column et_pb_column_4_4"><div class="filtered-posts-loading load-3"><span class="line"></span><span class="line"></span><span class="line"></span></div></div></div></div></div></div></div>');
        }
    
        var data = {
          'action': 'divi_filter_get_post_modal_ajax_handler',
          'security': filter_ajax_object.security,
          'post_ids': JSON.stringify(post_ids),
          'post_type': post_type,
          'modal_layout': JSON.stringify(modal_layouts),
          'modal_postype': JSON.stringify(modal_posttypes)
        };
    
        jQuery("body").addClass("hide_update_content_modal");
    
        jQuery('.show_modal').click(function (event) {
          event.preventDefault();
          event.stopPropagation();
    
          var update_content_show_start = jQuery(this).attr('update_content_show_start');
    
          if (update_content_show_start == "off") {
            jQuery("body").removeClass("hide_update_content_modal");
          }
    
          var data_id = jQuery(this).attr('data-id');
          var loading_animation_color = jQuery(this).attr('loading_animation_color');
          var modal_type = jQuery(this).attr('modal_type');
          var modal_layout = jQuery(this).attr('data-modal-layout');
    
          if (modal_type == "update_content") {
             
              jQuery('.dmach_content_update').each(function() {
                  jQuery(this).hide();
                  jQuery(this).removeClass('open');
              });
    
              if (jQuery('#post-modal-' + modal_layout + '-' + data_id).length) {
                  jQuery('#post-modal-' + modal_layout + '-' + data_id).addClass('open');
              } else {
                  jQuery('#loading-modal').attr('modaldata-id', data_id);
                  jQuery('#loading-modal').attr('modallayout-id', modal_layout);
                  jQuery('#loading-modal').addClass('open');
              }
    
              var $scrolltosection = jQuery('.dmach_content_update_cont'),
              scrollto_fine_tune = '0px',
              scrollto_fine_tune_dis = parseInt(scrollto_fine_tune);
    
              jQuery('html, body').animate({
                scrollTop: $scrolltosection.offset().top - scrollto_fine_tune_dis
              }, 500);
    
          } else {
              if (loading_animation_color !== "") {
                  jQuery('#loading-modal .line').each(function (i, obj) {
                      jQuery(this).css('background-color', loading_animation_color);
                  });
              }
    
              if (jQuery('#post-modal-' + modal_layout + '-' + data_id).length) {
                  jQuery('#post-modal-' + modal_layout + '-' + data_id).addClass('open');
              } else {
                  jQuery('#loading-modal').attr('modaldata-id', data_id);
                  jQuery('#loading-modal').attr('modallayout-id', modal_layout);
                  jQuery('#loading-modal').addClass('open');
              }
              jQuery('html').css('overflow', 'hidden');
          }
        });
    
        jQuery.ajax({
          url: filter_ajax_object.ajax_url, // AJAX handler
          data: data,
          type: 'POST',
          dataType: 'JSON',
          success: function (data) {
    
              jQuery('body').find('#dmach-modal-wrapper:not(.loading)').remove();
              jQuery('#loading-modal').remove();
    
              if (jQuery("#dmach-modal-wrapper.loading").length) {
              } else {
                if (jQuery(".et-l--body").length) {
                    jQuery('.et-l--body').append('<div id="dmach-modal-wrapper" class="' + modal_style + '"></div>');
                } else {
                    jQuery('#page-container').append('<div id="dmach-modal-wrapper" class="' + modal_style + '"></div>');
                }
              }
    
              jQuery('.show_modal').each(function () {
    
                var data_id = jQuery(this).attr('data-id');
                var modal_type = jQuery(this).attr('modal_type');
                var update_content_pos = jQuery(this).attr('update_content_pos');
                var cur_modal_layout = jQuery(this).attr('data-modal-layout');
  
                // console.log("Data id: " + data_id);
                // console.log("Modal type: " + modal_type);
                // console.log("Update content pos: " + update_content_pos);
                // console.log("Current modal layout: " + cur_modal_layout);
    
                if (modal_type == "update_content") {
                    if (update_content_pos == "above") {
                        jQuery('.update_content_loop .dmach-before-posts').addClass('dmach_content_update_cont');
                        jQuery('.update_content_loop .dmach-before-posts').append('<div id="post-modal-' + cur_modal_layout + '-' + data_id + '" class="dmach_content_update"><div class="post-modal-cont">' + data['content']['show_modal_' + cur_modal_layout + '_' + data_id] + '</div></div>');
                    } else {
                        jQuery('.update_content_loop .dmach-after-posts').addClass('dmach_content_update_cont');
                        jQuery('.update_content_loop .dmach-after-posts').append('<div id="post-modal-' + cur_modal_layout + '-' + data_id + '" class="dmach_content_update"><div class="post-modal-cont">' + data['content']['show_modal_' + cur_modal_layout + '_' + data_id] + '</div></div>');
      
                    }
                } else {
                    jQuery('#dmach-modal-wrapper').append('<div id="post-modal-' + cur_modal_layout + '-' + data_id + '" class="dmach-popup"><div class="post-modal-cont"><div class="modal-close"></div>' + data['content']['show_modal_' + cur_modal_layout + '_' + data_id] + '<div class="dmach-nextprev-post"><div class="dmach-prev-post"></div><div class="dmach-next-post"></div></div></div></div>');
                }
    
          if (jQuery('#post-modal-' + cur_modal_layout + '-' + data_id).find('.et_pb_map_container').length > 0) {
            var st = {};
            var modal_obj = {};
            jQuery('#post-modal-' + cur_modal_layout + '-' + data_id).find('.et_pb_map_container').each(function () {
              modal_obj[cur_modal_layout][data_id] = jQuery(this);
              if (typeof et_pb_map_init !== "function") {
                st[cur_modal_layout][data_id] = setInterval(function () {
                  if (typeof et_pb_map_init === "function") {
                    et_pb_map_init(modal_obj[cur_modal_layout][data_id]);
                    clearInterval(st[cur_modal_layout][data_id]);
                  }
                }, 1000);
              } else {
                et_pb_map_init(jQuery(this));
              }
            });
          }
              });
    
        if (jQuery("#dmach-modal-wrapper.loading").length) {
          var modal_data_id = jQuery('#loading-modal').attr('modaldata-id');
          var modal_layout_id = jQuery('#loading-modal').attr('modallayout-id');
          jQuery('#dmach-modal-wrapper').removeClass('loading');
          jQuery('#loading-modal').removeClass('open');
          jQuery('#post-modal-' + modal_layout_id + '-' + modal_data_id).addClass('open');
        }
    
            // console.log("peter");
            // console.log(data.css_output);
    
            jQuery('#dmach-modal-wrapper').append(data.css_output);
    
            jQuery(".dmach-popup").each(function () {
              var $popup = jQuery(this);
              
              $popup.find(".et_pb_de_mach_acf_slider_containter").each(function () {
                var $sliderContainer = jQuery(this);
                var sliderID = $sliderContainer.attr("id"); // Get the ID of the container
                
                if (sliderID) {
                  // Find gallery vars associated with this popup
                  var $galleryVarsElement = $popup.find(".gallery_vars");
                  
                  if ($galleryVarsElement.length > 0) {
                    var galleryVars = $galleryVarsElement.attr("data-gallery_vars");
                    var galleryType = $galleryVarsElement.attr("data-gallery_type");
            
                    if (galleryVars) {
                      // Clean and parse gallery_vars
                      galleryVars = galleryVars.replace(/,\s*$/, "");
                      galleryVars = galleryVars.replace(/,/g, ", ");
                      galleryVars = galleryVars.replace(/'/g, '"');
                      galleryVars = "{" + galleryVars + "}";
                      galleryVars = JSON.parse(galleryVars);
            
                      // Apply Slick to the container
                      if ($sliderContainer.hasClass("slick-initialized")) {
                        $sliderContainer.slick("unslick");
                      }
                      $sliderContainer.slick(galleryVars);
                    }
            
                    // If gallery_type is 'gallery', handle the navigation slider
                    if (galleryType === "gallery") {
                      var galleryNavVars = $galleryVarsElement.attr("data-gallery_nav");
            
                      if (galleryNavVars) {
                        // Clean and parse gallery_nav_vars
                        galleryNavVars = galleryNavVars.replace(/,\s*$/, "");
                        galleryNavVars = galleryNavVars.replace(/,/g, ", ");
                        galleryNavVars = galleryNavVars.replace(/'/g, '"');
                        galleryNavVars = "{" + galleryNavVars + "}";
                        galleryNavVars = JSON.parse(galleryNavVars);
            
                        // Set navigation-specific properties
                        galleryNavVars.asNavFor = "#" + sliderID;
                        galleryNavVars.focusOnSelect = true;
            
                        // Find the navigation container and apply Slick
                        var $navContainer = $popup.find(".et_pb_de_mach_acf_slider_containter_nav");
            
                        if ($navContainer.length > 0) {
                          if ($navContainer.hasClass("slick-initialized")) {
                            $navContainer.slick("unslick");
                          }
                          $navContainer.slick(galleryNavVars);
                        }
                      }
                    }
                  }
                }
              });
            });
    
            jQuery('#dmach-modal-wrapper .dmach-popup').each(function (i, obj) {
              if (jQuery(this).find('.wpcf7-form').length > 0) {
                wpcf7.init(jQuery(this).find('.wpcf7-form'));
              }
            });
    
            if ( "undefined" != typeof wc_add_to_cart_variation_params ) {
              jQuery(".variations_form").each(function() {
                  jQuery(this).wc_variation_form();
              });
            } 
  
            if (typeof jQuery.fn.magnificPopup !== 'undefined') {
              if (jQuery('.et_pb_de_mach_gallery_item').length > 0) {
                // reinitalize magnific popup
                jQuery('.et_pb_gallery_image a').magnificPopup({ 
                  type: 'image'
                });
              }
            } else {
            }
    
            jQuery.event.trigger({
              type: "divi_machine_modal_loaded",
            });
    
          }
        })
      }
    }
    
    function same_height_cards() {
      jQuery('.same-height-cards .filtered-posts').each(function () {
    
        // Cache the highest
        var highestBox = 0;
    
        // Select and loop the elements you want to equalise
        jQuery('.grid-col', this).each(function () {
          // If this box is higher than the cached highest then store it
          if (jQuery(this).height() > highestBox) {
            highestBox = jQuery(this).height();
          }
        });
    
        var margin_bottom = jQuery(this).find(".et_pb_section").css("marginBottom");
    
        // Set the height of all those children to whichever was highest
        jQuery('.grid-col', this).height(highestBox);
        jQuery('.grid-col', this).css("margin-bottom", margin_bottom);
      });
    }
    
    jQuery(document).ready(function($){
      $('span.hidethis').each(function(){
        var hide_option = $(this).attr('data-hide_option');
        if ( typeof hide_option !== "undefined" ) {
          if ( hide_option == "hide_parent_row" ) {
              if ($(this).parents('.et_section_specialty').length) {
                  $(this).closest('.et_pb_row_inner').hide();
                  $(this).closest('.et_pb_row_inner').addClass('hidethis');
              } else {
                  $(this).closest('.et_pb_row').hide();
                  $(this).closest('.et_pb_row').addClass('hidethis');
              }
          } else if ( hide_option == "hide_parent_section") {
              $(this).closest(".et_pb_section").hide();
              $(this).closest(".et_pb_section").addClass('hidethis');
          } else if ( hide_option == "hide_element" ) {
              var target_selector = $(this).attr('data-hide_target');
              var target_in_section = $(this).attr('data-hide_target_in_section');
      
              if ( typeof target_in_section != 'undefined' && target_in_section == "on" ) {
                  $(this).closest('.et_pb_section').find(target_selector).hide();
                  $(this).closest('.et_pb_section').find(target_selector).addClass('hidethis');
      
                  // Check if target_selector includes 'grid-item' or 'grid-col'
                  if ( target_selector.indexOf('grid-item') > -1 || target_selector.indexOf('grid-col') > -1 || target_selector.indexOf('dmach-grid-item') > -1 ) {
                      $(this).closest('.grid-item, .grid-col, .dmach-grid-item').hide();
                      $(this).closest('.grid-item, .grid-col, .dmach-grid-item').addClass('hidethis');
                  }
      
              } else {
                  $(target_selector).hide();
                  $(target_selector).addClass('hidethis');
              }
          }
        }
      
      });
      jQuery(document).on('divi_filter_completed', function(){
        jQuery('span.hidethis').each(function(){
          var hide_option = jQuery(this).attr('data-hide_option');
          if ( typeof hide_option !== "undefined" ) {
            if ( hide_option == "hide_parent_row" ) {
                if ($(this).parents('.et_section_specialty').length) {
                    $(this).closest('.et_pb_row_inner').hide();
                    $(this).closest('.et_pb_row_inner').addClass('hidethis');
                } else {
                    $(this).closest('.et_pb_row').hide();
                    $(this).closest('.et_pb_row').addClass('hidethis');
                }
            } else if ( hide_option == "hide_parent_section") {
                $(this).closest(".et_pb_section").hide();
                $(this).closest(".et_pb_section").addClass('hidethis');
            } else if ( hide_option == "hide_element" ) {
                var target_selector = $(this).attr('data-hide_target');
                var target_in_section = $(this).attr('data-hide_target_in_section');
        
                if ( typeof target_in_section != 'undefined' && target_in_section == "on" ) {
                    $(this).closest('.et_pb_section').find(target_selector).hide();
                    $(this).closest('.et_pb_section').find(target_selector).addClass('hidethis');
        
                    // Check if target_selector includes 'grid-item' or 'grid-col'
                    if ( target_selector.indexOf('grid-item') > -1 || target_selector.indexOf('grid-col') > -1 || target_selector.indexOf('dmach-grid-item') > -1 ) {
                        $(this).closest('.grid-item, .grid-col, .dmach-grid-item').hide();
                        $(this).closest('.grid-item, .grid-col, .dmach-grid-item').addClass('hidethis');
                    }
        
                } else {
                    $(target_selector).hide();
                    $(target_selector).addClass('hidethis');
                }
            }
          }
        });
      });
    });
    
    
    
    
    
    
    jQuery(document).ready(function ($) {
    var $et_pb_countdown_timer = $( '.et_pb_countdown_timer' );   
        window.et_countdown_timer = function( timer ) {
                    var end_date = parseInt( timer.attr( 'data-end-timestamp') ),
                        current_date = new Date().getTime() / 1000,
                        seconds_left = ( end_date - current_date );
    
                    days = parseInt(seconds_left / 86400);
                    days = days > 0 ? days : 0;
                    seconds_left = seconds_left % 86400;
    
                    hours = parseInt(seconds_left / 3600);
                    hours = hours > 0 ? hours : 0;
    
                    seconds_left = seconds_left % 3600;
    
                    minutes = parseInt(seconds_left / 60);
                    minutes = minutes > 0 ? minutes : 0;
    
                    seconds = parseInt(seconds_left % 60);
                    seconds = seconds > 0 ? seconds : 0;
    
                    var $days_section = timer.find('.days > .value').parent('.section'),
                        $hours_section = timer.find('.hours > .value').parent('.section'),
                        $minutes_section = timer.find('.minutes > .value').parent('.section'),
                        $seconds_section = timer.find('.seconds > .value').parent('.section');
    
    
                    if ( days == 0 ) {
                        if ( ! $days_section.hasClass('zero') ) {
                            timer.find('.days > .value').html( '000' ).parent('.section').addClass('zero').next().addClass('zero');
                        }
                    } else {
                        days_slice = days.toString().length >= 3 ? days.toString().length : 3;
                        timer.find('.days > .value').html( ('000' + days).slice(-days_slice) );
    
                        if ( $days_section.hasClass('zero') ) {
                            $days_section.removeClass('zero').next().removeClass('zero');
                        }
                    }
    
                    if ( days == 0 && hours == 0 ) {
                        if ( ! $hours_section.hasClass('zero') ) {
                            timer.find('.hours > .value').html('00').parent('.section').addClass('zero').next().addClass('zero');
                        }
                    } else {
                        timer.find('.hours > .value').html( ( '0' + hours ).slice(-2) );
    
                        if ( $hours_section.hasClass('zero') ) {
                            $hours_section.removeClass('zero').next().removeClass('zero');
                        }
                    }
    
                    if ( days == 0 && hours == 0 && minutes == 0 ) {
                        if ( ! $minutes_section.hasClass('zero') ) {
                            timer.find('.minutes > .value').html('00').parent('.section').addClass('zero').next().addClass('zero');
                        }
                    } else {
                        timer.find('.minutes > .value').html( ( '0' + minutes ).slice(-2) );
    
                        if ( $minutes_section.hasClass('zero') ) {
                            $minutes_section.removeClass('zero').next().removeClass('zero');
                        }
                    }
    
                    if ( days == 0 && hours == 0 && minutes == 0 && seconds == 0 ) {
                        if ( ! $seconds_section.hasClass('zero') ) {
                            timer.find('.seconds > .value').html('00').parent('.section').addClass('zero');
                        }
                    } else {
                        timer.find('.seconds > .value').html( ( '0' + seconds ).slice(-2) );
    
                        if ( $seconds_section.hasClass('zero') ) {
                            $seconds_section.removeClass('zero').next().removeClass('zero');
                        }
                    }
                }
    
                window.et_countdown_timer_labels = function( timer ) {
                    if ( timer.closest( '.et_pb_column_3_8' ).length || timer.closest( '.et_pb_column_1_4' ).length || timer.children('.et_pb_countdown_timer_container').width() <= 400 ) {
                        timer.find('.days .label').html( timer.find('.days').data('short') );
                        timer.find('.hours .label').html( timer.find('.hours').data('short') );
                        timer.find('.minutes .label').html( timer.find('.minutes').data('short') );
                        timer.find('.seconds .label').html( timer.find('.seconds').data('short') );
                    } else {
                        timer.find('.days .label').html( timer.find('.days').data('full') );
                        timer.find('.hours .label').html( timer.find('.hours').data('full') );
                        timer.find('.minutes .label').html( timer.find('.minutes').data('full') );
                        timer.find('.seconds .label').html( timer.find('.seconds').data('full') );
                    }
                }
    
                if ( $et_pb_countdown_timer.length ) {
                    window.et_pb_countdown_timer_init = function( $et_pb_countdown_timer ) {
                        $et_pb_countdown_timer.each(function(){
                            var timer = $(this);
                            et_countdown_timer_labels( timer );
                            et_countdown_timer( timer );
                            setInterval(function(){
                                et_countdown_timer( timer );
                            }, 1000);
                        });
                    }
                    et_pb_countdown_timer_init( $et_pb_countdown_timer );
                }
    });
    
    
    /* Refresh countdown after ajax return */
    jQuery(document).ready(function ($) {
      jQuery(document).on('divi_filter_completed', function(){
    
    
        var $et_pb_countdown_timer = $( '.et_pb_countdown_timer' );
        if ( $et_pb_countdown_timer.length ) {
          window.et_pb_countdown_timer_init = function( $et_pb_countdown_timer ) {
            $et_pb_countdown_timer.each(function(){
              var timer = $(this);
              et_countdown_timer_labels( timer );
              et_countdown_timer( timer );
              setInterval(function(){
                et_countdown_timer( timer );
              }, 1000);
            });
          }
          et_pb_countdown_timer_init( $et_pb_countdown_timer );
        }
    
    
        var $et_pb_tabs = $( '.et_pb_tabs' ),
        is_frontend_builder = $('body').hasClass('et-fb');
    
        if ( $et_pb_tabs.length || is_frontend_builder ) {
          window.et_pb_tabs_init = function( $et_pb_tabs ) {
            var $et_pb_tabs_li = $et_pb_tabs.find( '.et_pb_tabs_controls li' );
    
            $et_pb_tabs.et_pb_simple_slider( {
              use_controls   : false,
              use_arrows     : false,
              slide          : '.et_pb_all_tabs > div',
              tabs_animation : true
            } ).on('et_hashchange', function( event ){
              var params = event.params;
              var $the_tabs = $( '#' + event.target.id );
              var active_tab = params[0];
              if ( !$the_tabs.find( '.et_pb_tabs_controls li' ).eq( active_tab ).hasClass('et_pb_tab_active') ) {
                $the_tabs.find( '.et_pb_tabs_controls li' ).eq( active_tab ).click();
              }
            });
    
            $et_pb_tabs_li.click( function() {
              var $this_el        = $(this),
                $tabs_container = $this_el.closest( '.et_pb_tabs' ).data('et_pb_simple_slider');
    
              if ( $tabs_container.et_animation_running ) return false;
    
              $this_el.addClass( 'et_pb_tab_active' ).siblings().removeClass( 'et_pb_tab_active' );
    
              $tabs_container.data('et_pb_simple_slider').et_slider_move_to( $this_el.index() );
    
              if ( $this_el.closest( '.et_pb_tabs' ).attr('id') ) {
                var tab_state = [];
                tab_state.push( $this_el.closest( '.et_pb_tabs' ).attr('id') );
                tab_state.push( $this_el.index() );
                tab_state = tab_state.join( et_hash_module_param_seperator );
                et_set_hash( tab_state );
              }
    
              return false;
            } );
          }
          window.et_pb_tabs_init( $et_pb_tabs );
        }
    
    
      });
    });
    
    // load more gallery 
    jQuery(document).ready(function ($) {
    
      function ajax_load_more_gallery($this, is_popup) {
    
          
          // if has the class loading, then stop
          if ($this.hasClass('loading')) {
              return false;
          }
    
          var $et_pb_gallery_grid = $this.closest('.et_pb_de_mach_acf_slider ');
          var data_grid_image_ids = $et_pb_gallery_grid.find('.grid-item').attr('data-grid-image-ids');
          var data_load_more_num = $et_pb_gallery_grid.find('.grid-item').attr('data-load-more-num');
          var enable_lightbox = $et_pb_gallery_grid.find('.grid-item').attr('data-enable_lightbox');
          var show_title_and_caption = $et_pb_gallery_grid.find('.grid-item').attr('data-show_title_and_caption');
    
          var loading_text = $this.attr('data-loading_text');
          var original_text = $this.text();
    
          var data = {
              'action': 'divi_filter_load_more_gallery_ajax_handler',
              'data_grid_image_ids': data_grid_image_ids,
              'data_load_more_num': data_load_more_num,
              'enable_lightbox': enable_lightbox,
              'show_title_and_caption': show_title_and_caption
          };
    
          jQuery.ajax({
              url: filter_ajax_object.ajax_url, // AJAX handler
              data: data,
              type: 'POST',
              dataType: 'JSON',
              beforeSend: function () {
                  $this.addClass('loading');
                  $this.attr('disabled', 'disabled');
                  $this.text(loading_text);
              },
              success: function (data) {

                    $this.removeClass('loading');
                    $et_pb_gallery_grid.find('.grid-item').attr('data-grid-image-ids', data['ids']);
                    // $et_pb_gallery_grid.find('.grid-item').attr('data-load-more-num', data['data_load_more_num']);
                    $et_pb_gallery_grid.find('.grid-posts').append(data['content']);
                    $this.text(original_text);
                    
                    if (data['data_load_more_num'] == 0) {
                        $this.hide();
                    }
                    
                    if (typeof jQuery.fn.magnificPopup !== 'undefined' && data['gallery_image_urls'] != '' && is_popup == true) {
                        // get instance (after popup was opened)
                        var mfp = jQuery.magnificPopup.instance;
                        jQuery.each(data['gallery_image_urls'], function( index, value ) {
                        mfp.items.push({
                            src: value
                        });
                        });
        
                        // call update method to refresh counters (if required)
                        mfp.updateItemHTML();
        
                    } else {
                    }

                  

                    // if et_pb_gallery_grid find grid-item has the class "masonry", console log "masonry"
                    if ($et_pb_gallery_grid.find('.grid-item').hasClass('masonry')) {
                        let classes = $et_pb_gallery_grid.find('.grid-item').attr('class');

                        // Match col-desk-4, col-tab-2, col-mob-1 and extract the colNumbers
                        let matches = classes.match(/col-(?:desk|tab|mob)-(\d+)/g);

                        // Extract only the digits
                        let colNumbers = matches.map(m => m.match(/\d+/)[0]);

                        var macyInstance = Macy({
                            container: '.masonry.et_pb_gallery_grid .grid-posts',
                            trueOrder: false,
                            waitForImages: true,
                            margin: {
                                x: 25,
                                y: 25  
                            },
                            columns:  colNumbers[0],
                            breakAt: {
                                1200: colNumbers[0],
                                980: colNumbers[1],
                                767: colNumbers[2]
                            }
                            }); 

                            macyInstance.recalculate();
                            $('.masonry.et_pb_gallery_grid').addClass('loaded');
                    }

              }
          });
          
      }
    
    
      $(document.body).on('click', '.et_pb_de_mach_load_more_button_link', function (e) {
          e.preventDefault();
    
          var $this = $(this);
          var is_popup = false;
          ajax_load_more_gallery($this, is_popup);
    
      });
    
      // on .mfp-arrow click
      $(document.body).on('click', '.mfp-arrow', function (e) {
          // get the current image src
          var current_src = $('.mfp-img').attr('src');
          // get the 2nd to last gallery item image src - .et_pb_gallery_items .grid-item:nth-last-child(2) img
          var second_last_src = $('.et_pb_gallery_items .grid-item:nth-last-child(2) img').attr('src');
          
          // if the current image src is the same as the 2nd to last gallery item image src, ajax load more
          if (current_src == second_last_src) {
              var $this = $('.et_pb_de_mach_load_more_button_link');
              var is_popup = true;
              ajax_load_more_gallery($this, is_popup);
          }
      });
    
      // on keyboard arrow press
      $(document).keydown(function(e) {
          switch(e.which) {
      
              case 39: // right
                  // get the current image src
                  var current_src = $('.mfp-img').attr('src');
                  // get the 2nd to last gallery item image src - .et_pb_gallery_items .grid-item:nth-last-child(2) img
                  var second_last_src = $('.et_pb_gallery_items .grid-item:nth-last-child(2) img').attr('src');
                  
                  // if the current image src is the same as the 2nd to last gallery item image src, ajax load more
                  if (current_src == second_last_src) {
                      var $this = $('.et_pb_de_mach_load_more_button_link');
                      var is_popup = true;
                      ajax_load_more_gallery($this, is_popup);
                  }
              break;
          }
        });
    
    
    
    });
}