// source --> https://elanillounico.com/wp-content/plugins/efemerides/public/slider.js?ver=1.0 
jQuery(document).ready(function($) {
    var currentSlide = 0;
    var slides = $('.efemerides-slider .slide');
    var numSlides = slides.length;

    if (numSlides > 1) {
        slides.hide();
        slides.eq(currentSlide).show();

        setInterval(function() {
            slides.eq(currentSlide).fadeOut(600, function() {
                currentSlide = (currentSlide + 1) % numSlides;
                slides.eq(currentSlide).fadeIn(600);
            });
        }, 5000); // Intervalo de 5 segundos
    }
});
// source --> https://elanillounico.com/wp-content/plugins/tolkienpedia/assets/js/single-entry.js?ver=0.9.60 
(function () {
  function loadPanel(panel) {
    var frame = panel.querySelector("iframe[data-src]");
    if (frame && !frame.getAttribute("src")) {
      frame.setAttribute("src", frame.getAttribute("data-src"));
    }
    window.setTimeout(function () {
      window.dispatchEvent(new Event("resize"));
    }, 80);
  }

  document.addEventListener("toggle", function (event) {
    var panel = event.target;
    if (!panel.matches(".tolkienpedia-entry-lazy-panel") || !panel.open) {
      return;
    }
    loadPanel(panel);
  }, true);

  function fallbackCopy(input) {
    input.focus();
    input.select();
    input.setSelectionRange(0, input.value.length);
    return document.execCommand("copy");
  }

  document.addEventListener("click", function (event) {
    var input = event.target.closest("[data-tolkienpedia-shortlink]");
    if (!input) {
      return;
    }

    var status = document.getElementById(input.getAttribute("aria-describedby"));
    var copied = window.navigator.clipboard && window.isSecureContext
      ? window.navigator.clipboard.writeText(input.value)
      : Promise.resolve(fallbackCopy(input));

    copied.then(function () {
      input.select();
      if (status) {
        status.textContent = "COPIADO";
        window.setTimeout(function () {
          status.textContent = "";
        }, 1800);
      }
    }).catch(function () {
      fallbackCopy(input);
      if (status) {
        status.textContent = "COPIADO";
      }
    });
  });

  var floatingTools = document.querySelector("[data-tolkienpedia-floating-tools]");
  if (!floatingTools) {
    return;
  }

  var searchToggle = floatingTools.querySelector("[data-tolkienpedia-floating-search-toggle]");
  var searchPanel = floatingTools.querySelector(".tolkienpedia-entry-floating-search");
  var searchInput = searchPanel ? searchPanel.querySelector('input[type="search"]') : null;
  var shareButton = floatingTools.querySelector("[data-tolkienpedia-share]");
  var floatingStatus = floatingTools.querySelector("[data-tolkienpedia-floating-status]");
  var statusTimer;

  function setFloatingStatus(message) {
    if (!floatingStatus) {
      return;
    }
    window.clearTimeout(statusTimer);
    floatingStatus.textContent = message;
    floatingStatus.hidden = !message;
    if (message) {
      statusTimer = window.setTimeout(function () {
        floatingStatus.textContent = "";
        floatingStatus.hidden = true;
      }, 2200);
    }
  }

  function closeFloatingSearch() {
    if (!searchPanel || !searchToggle) {
      return;
    }
    searchPanel.hidden = true;
    searchToggle.setAttribute("aria-expanded", "false");
    searchToggle.classList.remove("is-active");
  }

  if (searchToggle && searchPanel) {
    searchToggle.addEventListener("click", function () {
      var willOpen = searchPanel.hidden;
      searchPanel.hidden = !willOpen;
      searchToggle.setAttribute("aria-expanded", willOpen ? "true" : "false");
      searchToggle.classList.toggle("is-active", willOpen);
      if (willOpen && searchInput) {
        window.setTimeout(function () {
          searchInput.focus();
        }, 20);
      }
    });
  }

  if (shareButton) {
    shareButton.addEventListener("click", function () {
      var shareData = {
        title: document.title,
        text: document.querySelector(".tolkienpedia-entry-header h1")
          ? document.querySelector(".tolkienpedia-entry-header h1").textContent.trim()
          : document.title,
        url: window.location.href
      };
      shareButton.classList.add("is-active");

      if (window.navigator.share) {
        window.navigator.share(shareData).catch(function (error) {
          if (error && error.name !== "AbortError") {
            setFloatingStatus("No se ha podido compartir");
          }
        }).finally(function () {
          shareButton.classList.remove("is-active");
        });
        return;
      }

      var copied = window.navigator.clipboard && window.isSecureContext
        ? window.navigator.clipboard.writeText(shareData.url)
        : Promise.reject(new Error("Clipboard unavailable"));
      copied.then(function () {
        setFloatingStatus("Enlace copiado");
      }).catch(function () {
        var temporary = document.createElement("input");
        temporary.value = shareData.url;
        temporary.setAttribute("readonly", "readonly");
        temporary.style.position = "fixed";
        temporary.style.opacity = "0";
        document.body.appendChild(temporary);
        fallbackCopy(temporary);
        temporary.remove();
        setFloatingStatus("Enlace copiado");
      }).finally(function () {
        shareButton.classList.remove("is-active");
      });
    });
  }

  document.addEventListener("click", function (event) {
    if (searchPanel && !searchPanel.hidden && !floatingTools.contains(event.target)) {
      closeFloatingSearch();
    }
  });

  document.addEventListener("keydown", function (event) {
    if (event.key === "Escape" && searchPanel && !searchPanel.hidden) {
      closeFloatingSearch();
      searchToggle.focus();
    }
  });
})();
// source --> https://elanillounico.com/wp-content/plugins/eau-imagenes/assets/frontend/lightbox.js?ver=1.2.1 
(function () {
    'use strict';

    var links = [];
    var currentIndex = -1;
    var overlay = null;
    var picture = null;
    var caption = null;
    var closeButton = null;
    var previousButton = null;
    var nextButton = null;
    var lightboxSelector = '[data-eau-lightbox="1"], .entry-content a.ngg-fancybox[href]';
    var imageUrlPattern = /\.(?:avif|webp|jpe?g|png|gif)(?:[?#].*)?$/i;

    function collectLinks() {
        links = Array.prototype.slice.call(document.querySelectorAll(lightboxSelector)).filter(isLightboxLink);
    }

    function isLightboxLink(link) {
        if (!link || link.getAttribute('data-eau-no-lightbox') === '1') {
            return false;
        }

        if (link.getAttribute('data-eau-lightbox') === '1') {
            return true;
        }

        return imageUrlPattern.test(getFullSrc(link));
    }

    function getLightboxLink(target) {
        var link = target.closest(lightboxSelector);
        return isLightboxLink(link) ? link : null;
    }

    function getFullSrc(link) {
        return link.getAttribute('data-full-src') || link.getAttribute('data-src') || link.href || '';
    }

    function getCaption(link) {
        var figure = link.closest('figure');
        var figcaption = figure ? figure.querySelector('figcaption') : null;

        return link.getAttribute('data-caption') ||
            link.getAttribute('data-title') ||
            (figcaption ? figcaption.textContent.trim() : '');
    }

    function getAlt(link) {
        var image = link.querySelector('img');

        return link.getAttribute('data-alt') ||
            (image ? image.getAttribute('alt') || '' : '') ||
            getCaption(link);
    }

    function createOverlay() {
        if (overlay) {
            return;
        }

        overlay = document.createElement('div');
        overlay.className = 'eau-lightbox';
        overlay.setAttribute('role', 'dialog');
        overlay.setAttribute('aria-modal', 'true');
        overlay.setAttribute('aria-hidden', 'true');

        closeButton = document.createElement('button');
        closeButton.type = 'button';
        closeButton.className = 'eau-lightbox__button eau-lightbox__close';
        closeButton.setAttribute('aria-label', 'Cerrar imagen');
        closeButton.textContent = 'x';

        previousButton = document.createElement('button');
        previousButton.type = 'button';
        previousButton.className = 'eau-lightbox__button eau-lightbox__previous';
        previousButton.setAttribute('aria-label', 'Imagen anterior');
        previousButton.textContent = '<';

        nextButton = document.createElement('button');
        nextButton.type = 'button';
        nextButton.className = 'eau-lightbox__button eau-lightbox__next';
        nextButton.setAttribute('aria-label', 'Imagen siguiente');
        nextButton.textContent = '>';

        picture = document.createElement('picture');
        picture.className = 'eau-lightbox__picture';

        caption = document.createElement('div');
        caption.className = 'eau-lightbox__caption';

        overlay.appendChild(closeButton);
        overlay.appendChild(previousButton);
        overlay.appendChild(nextButton);
        overlay.appendChild(picture);
        overlay.appendChild(caption);
        document.body.appendChild(overlay);

        closeButton.addEventListener('click', closeLightbox);
        previousButton.addEventListener('click', function () {
            showImage(currentIndex - 1);
        });
        nextButton.addEventListener('click', function () {
            showImage(currentIndex + 1);
        });
        overlay.addEventListener('click', function (event) {
            if (event.target === overlay) {
                closeLightbox();
            }
        });
    }

    function setPicture(link) {
        var full = getFullSrc(link);
        var avif = link.getAttribute('data-avif-src') || '';
        var webp = link.getAttribute('data-webp-src') || '';
        var alt = getAlt(link);
        var text = getCaption(link);
        var html = '';

        if (avif) {
            html += '<source type="image/avif" srcset="' + escapeAttribute(avif) + '">';
        }
        if (webp) {
            html += '<source type="image/webp" srcset="' + escapeAttribute(webp) + '">';
        }
        html += '<img src="' + escapeAttribute(full) + '" alt="' + escapeAttribute(alt) + '">';

        picture.innerHTML = html;
        caption.textContent = text;
        caption.hidden = !text;
    }

    function showImage(index) {
        if (!links.length) {
            return;
        }

        if (index < 0) {
            index = links.length - 1;
        } else if (index >= links.length) {
            index = 0;
        }

        currentIndex = index;
        setPicture(links[currentIndex]);
        previousButton.hidden = links.length < 2;
        nextButton.hidden = links.length < 2;
    }

    function openLightbox(index) {
        createOverlay();
        showImage(index);
        overlay.classList.add('is-open');
        overlay.setAttribute('aria-hidden', 'false');
        document.documentElement.classList.add('eau-lightbox-open');
        closeButton.focus();
    }

    function closeLightbox() {
        if (!overlay) {
            return;
        }

        overlay.classList.remove('is-open');
        overlay.setAttribute('aria-hidden', 'true');
        document.documentElement.classList.remove('eau-lightbox-open');
    }

    function escapeAttribute(value) {
        return String(value).replace(/[&<>"']/g, function (character) {
            return {
                '&': '&amp;',
                '<': '&lt;',
                '>': '&gt;',
                '"': '&quot;',
                "'": '&#039;'
            }[character];
        });
    }

    document.addEventListener('click', function (event) {
        var link = getLightboxLink(event.target);
        if (!link) {
            return;
        }

        collectLinks();
        var index = links.indexOf(link);
        if (index < 0) {
            return;
        }

        event.preventDefault();
        openLightbox(index);
    });

    document.addEventListener('keydown', function (event) {
        if (!overlay || !overlay.classList.contains('is-open')) {
            return;
        }

        if (event.key === 'Escape') {
            closeLightbox();
        } else if (event.key === 'ArrowLeft') {
            showImage(currentIndex - 1);
        } else if (event.key === 'ArrowRight') {
            showImage(currentIndex + 1);
        }
    });
}());