/*
Theme Name: Enfold Child
Description: A <a href='http://codex.wordpress.org/Child_Themes'>Child Theme</a> for the Enfold Wordpress Theme. If you plan to do a lot of file modifications we recommend to use this Theme instead of the original Theme. Updating wil be much easier then.
Version: 1.0
Author: Kriesi
Author URI: http://www.kriesi.at
Template: enfold
*/



/*Add your own styles here:*/

.bx-marquee{
  overflow:hidden;
  width:100%;
  padding:2.5rem 0;
  background:#f4f4f5;                 /* light strip — matches the mono logos */
  -webkit-mask-image:linear-gradient(90deg,transparent,#000 8%,#000 92%,transparent);
          mask-image:linear-gradient(90deg,transparent,#000 8%,#000 92%,transparent);
}
.bx-track{
  display:flex;
  align-items:center;
  gap:4.5rem;
  width:max-content;
  animation:bx-scroll 28s linear infinite;
}
.bx-track img{
  height:46px;            /* the mono PNGs are pre-trimmed, so one height = tidy */
  width:auto;
  opacity:.7;
  transition:opacity .3s;
}
.bx-track img:hover{opacity:1;}
.bx-marquee:hover .bx-track{animation-play-state:paused;}

@keyframes bx-scroll{
  from{transform:translateX(0);}
  to{transform:translateX(-50%);}
}
@media (prefers-reduced-motion:reduce){
  .bx-track{animation:none;flex-wrap:wrap;justify-content:center;gap:2rem;}
}

<?php
/* ==================================================================
   HOTEZA HOTPAD FEATURE CAROUSEL  -  STEP 3 of 3

   Copy EVERYTHING BELOW the line that says "COPY FROM HERE" and
   paste it at the very BOTTOM of your child theme functions.php:

   WordPress Dashboard > Appearance > Theme File Editor
     > Theme to edit: Enfold Child  > functions.php
     > scroll to the bottom, paste, then "Update File"

   IMPORTANT: do NOT copy the <?php tag on the first line of this
   file. Your functions.php already has one at the top, and a second
   one will break the site. Start copying at "COPY FROM HERE".

   If you pasted an earlier version of bict_hotpad_carousel_js into
   functions.php already, delete that whole old block first.
   ================================================================== */

// ============ COPY FROM HERE ============

function bict_hotpad_carousel_js() {
	if ( is_admin() ) { return; }
	?>
	<script id="bict-hotpad-carousel-js">
	(function () {

	  var REDUCED = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;

	  function initCarousel(root) {
	    if (root.dataset.fcReady === '1') return;
	    root.dataset.fcReady = '1';

	    var track = root.querySelector('[data-fc-track]');
	    var prev  = root.querySelector('[data-fc-prev]');
	    var next  = root.querySelector('[data-fc-next]');
	    var thumb = root.querySelector('[data-fc-thumb]');
	    if (!track) return;

	    /* ---------- geometry ---------- */

	    function step() {
	      var card = track.querySelector('.bict-fc__card');
	      if (!card) return track.clientWidth;
	      var cs = getComputedStyle(track);
	      var gap = parseFloat(cs.columnGap || cs.gap) || 0;
	      return card.getBoundingClientRect().width + gap;
	    }

	    function update() {
	      var max = track.scrollWidth - track.clientWidth;
	      var pos = track.scrollLeft;

	      if (prev) prev.disabled = pos <= 2;
	      if (next) next.disabled = pos >= max - 2;

	      if (thumb) {
	        var width = Math.min(1, track.clientWidth / track.scrollWidth) * 100;
	        var travel = max > 0 ? (pos / max) : 0;
	        thumb.style.width = width + '%';
	        thumb.style.left = (travel * (100 - width)) + '%';
	      }
	    }

	    function scrollByCards(dir) {
	      track.scrollBy({ left: dir * step(), behavior: REDUCED ? 'auto' : 'smooth' });
	    }

	    function atEnd() {
	      return track.scrollLeft >= (track.scrollWidth - track.clientWidth - 2);
	    }

	    /* ---------- autoplay ---------- */

	    var delay = parseInt(root.getAttribute('data-fc-autoplay'), 10);
	    if (isNaN(delay)) delay = 6000;

	    var timer = null;
	    var stopped = REDUCED || delay === 0;

	    root.style.setProperty('--fc-autoplay-ms', delay + 'ms');

	    function play() {
	      if (stopped || timer) return;
	      root.classList.add('is-playing');
	      timer = window.setInterval(function () {
	        if (atEnd()) {
	          track.scrollTo({ left: 0, behavior: REDUCED ? 'auto' : 'smooth' });
	        } else {
	          scrollByCards(1);
	        }
	      }, delay);
	    }

	    function pause() {
	      root.classList.remove('is-playing');
	      if (timer) { window.clearInterval(timer); timer = null; }
	    }

	    /* Hand control to the visitor for good once they touch it */
	    function stopForGood() {
	      stopped = true;
	      pause();
	    }

	    root.addEventListener('mouseenter', pause);
	    root.addEventListener('mouseleave', play);
	    root.addEventListener('focusin', pause);
	    root.addEventListener('focusout', function (e) {
	      if (!root.contains(e.relatedTarget)) play();
	    });
	    document.addEventListener('visibilitychange', function () {
	      if (document.hidden) { pause(); } else { play(); }
	    });

	    if (prev) prev.addEventListener('click', function () { stopForGood(); scrollByCards(-1); });
	    if (next) next.addEventListener('click', function () { stopForGood(); scrollByCards(1); });
	    track.addEventListener('pointerdown', stopForGood);

	    /* ---------- keyboard ---------- */

	    track.addEventListener('keydown', function (e) {
	      if (e.key === 'ArrowRight') { e.preventDefault(); stopForGood(); scrollByCards(1); }
	      if (e.key === 'ArrowLeft')  { e.preventDefault(); stopForGood(); scrollByCards(-1); }
	      if (e.key === 'Home')       { e.preventDefault(); stopForGood(); track.scrollTo({ left: 0, behavior: 'smooth' }); }
	      if (e.key === 'End')        { e.preventDefault(); stopForGood(); track.scrollTo({ left: track.scrollWidth, behavior: 'smooth' }); }
	    });

	    /* ---------- scroll position tracking ---------- */

	    var ticking = false;
	    track.addEventListener('scroll', function () {
	      if (ticking) return;
	      ticking = true;
	      window.requestAnimationFrame(function () { update(); ticking = false; });
	    }, { passive: true });

	    window.addEventListener('resize', update);
	    update();

	    /* ---------- entrance reveal ---------- */

	    function reveal() {
	      root.classList.add('is-in');
	      window.setTimeout(play, 900);
	    }

	    if (REDUCED || !('IntersectionObserver' in window)) {
	      reveal();
	    } else {
	      var io = new IntersectionObserver(function (entries) {
	        entries.forEach(function (entry) {
	          if (entry.isIntersecting) {
	            reveal();
	            io.disconnect();
	          }
	        });
	      }, { threshold: 0.2 });
	      io.observe(root);
	    }

	    /* Safety net: if anything above misfires, never leave cards hidden */
	    window.setTimeout(function () { root.classList.add('is-in'); }, 3000);
	  }

	  function initAll() {
	    document.documentElement.classList.remove('no-js');
	    var nodes = document.querySelectorAll('[data-bict-carousel]');
	    for (var i = 0; i < nodes.length; i++) initCarousel(nodes[i]);
	  }

	  if (document.readyState === 'loading') {
	    document.addEventListener('DOMContentLoaded', initAll);
	  } else {
	    initAll();
	  }
	})();
	</script>
	<?php
}
add_action( 'wp_footer', 'bict_hotpad_carousel_js', 100 );

// ============ STOP COPYING HERE ============