var serviceUrl = "//api.reciteme.com/asset/js?key=";
var serviceKey = "c29b45fcd390863caf1fbe0129a7614af2ef468b";
var options = {
  Controls: {
    Core: {
      zoomThreshold: 295,
      maxFontSizePercentage: 150,
    },
  },
};
var autoLoad = false;
var enableFragment = "#reciteEnable";
var loaded = [],
  frag = !1;
window.location.hash === enableFragment && (frag = !0);

function loadScript(c, b) {
  var a = document.createElement("script");
  a.type = "text/javascript";
  a.readyState
    ? (a.onreadystatechange = function () {
        if ("loaded" == a.readyState || "complete" == a.readyState)
          (a.onreadystatechange = null), void 0 != b && b();
      })
    : void 0 != b &&
      (a.onload = function () {
        b();
      });
  a.src = c;
  document.getElementsByTagName("head")[0].appendChild(a);
}

function _rc(c) {
  c += "=";
  for (var b = document.cookie.split(";"), a = 0; a < b.length; a++) {
    for (var d = b[a]; " " == d.charAt(0); ) d = d.substring(1, d.length);
    if (0 == d.indexOf(c)) return d.substring(c.length, d.length);
  }
  return null;
}

function loadService(c) {
  for (var b = serviceUrl + serviceKey, a = 0; a < loaded.length; a++) if (loaded[a] == b) return;
  loaded.push(b);
  loadScript(serviceUrl + serviceKey, function () {
    "function" === typeof _reciteLoaded && _reciteLoaded();
    "function" == typeof c && c();
    Recite.load(options);
    Recite.Event.subscribe("Recite:load", function () {
      Recite.enable();
    });
  });
}
"true" == _rc("Recite.Persist") && loadService();
if ((autoLoad && "false" != _rc("Recite.Persist")) || frag)
  document.addEventListener
    ? document.addEventListener("DOMContentLoaded", function (c) {
        loadService();
      })
    : loadService();
var correct_translation = [
  {
    from: "example Text",
    to: "This text below",
  },
  {
    from: "Our customers",
    to: "Status",
  },
  {
    from: "Taakbron",
    to: "Reden",
  },
];

function _reciteLoaded() {
  Recite.Event.subscribe("Recite.Parser:parsed", function () {
    _setDictionary();
  });
  Recite.Event.subscribe("Controls:loaded", function () {
    document.querySelectorAll('span[style="color:#ffffff;"]').forEach(function (e) {
      e.style.display = "none";
    });
    Recite.Event.subscribe("Recite:ModuleEvent", function (a, b) {
      if (b.name === "Recite.Style") {
        document
          .querySelectorAll(".uk-input,#A-GO, #B-GO,#C-GO, #D-GO, #E-GO")
          .forEach(function (e) {
            e.style.setProperty("background", "#C0C0C0", "important");
          });
      }
    });
    document.querySelector(".uk-width-small").style.setProperty("left", "40px", "");
    window.onscroll = function (e) {
      document.querySelectorAll("[uk-sticky-x]").forEach(function (e) {
        e.style.setProperty("display", "none", "important");
      });
    };
    window.onscrollend = function (e) {
      document.querySelectorAll("[uk-sticky-x]").forEach(function (e) {
        e.style.setProperty("display", "none", "important");
      });
    };
    document.querySelector(".uk-width-small").style.setProperty("left", "40px", "");
  });
  Recite.Event.subscribe("Controls:loaded", addNavbarOffset);
  Recite.Event.subscribe("Controls:loaded", function () {
    document.querySelectorAll(".link-up").forEach((menu) => {
      Recite.PlayerControls.Tooltip.invoke(menu);
    });
    document
      .querySelectorAll(
        " #A-GO > recite, #B-GO > recite,#C-GO > recite, #D-GO > recite, #E-GO > recite, .category ,.uk-drop > ul > li > a ,.recite-ignore-styles-background *:not(.recite-apply-styles-background), .recite-ignore-styles-background, .video_slider *:not(.recite-apply-styles-background), .video_slider"
      )
      .forEach(function (node) {
        node.classList.add("recite-ignore-styles-background");
      });
    document.querySelectorAll(".tier-one > a").forEach((menu) => {
      Recite.PlayerControls.Tooltip.invoke(menu);
    });
  });
  Recite.Event.subscribe("Preferences:set", _updateBackground);
  Recite.Event.subscribe("Controls:loaded", _updateBackground);
  Recite.Event.subscribe("Translate:begin", _translateManualElements);
  Recite.Event.subscribe("Translate:restore_begin", _translateManualElements);
  Recite.Event.subscribe("Preferences:load", _translateManualElements);
  Recite.Event.subscribe("Preferences:set", _translateManualElements);
  Recite.Event.subscribe("Controls:loaded", _updateFontSize);
  Recite.Event.subscribe("Controls:loaded", _resetTheme);
  Recite.Event.subscribe("Preferences:set", _updateFontSize);
  Recite.Event.subscribe("Preferences:reset", _updateFontSize);
  Recite.Event.subscribe("Preferences:reset", function () {
    document.querySelectorAll(".uk-input, #A-GO, #B-GO,#C-GO, #D-GO, #E-GO").forEach(function (e) {
      e.style.setProperty("background", "", "important");
    });
  });
  var bodyNode = document.body;

 function textNodesUnder(el) {
    if (!(el instanceof Node)) {
        console.error("Invalid Node passed to textNodesUnder:", el);
        return [];
    }
    var n,
        a = [],
        walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
    while ((n = walk.nextNode())) a.push(n);
    return a;
}

  Recite.Event.subscribe("Translate:complete", function () {
    var elements = textNodesUnder(bodyNode);
    for (var i = 0; i < elements.length; i++) {
      for (var j = 0; j < correct_translation.length; j++) {
        elements[i].textContent = elements[i].textContent.replace(
          correct_translation[j].from,
          correct_translation[j].to
        );
      }
    }
  });
  Recite.Event.subscribe("Recite.Dictionary.enabled", function () {
    _setDictionary();
  });
  Recite.Event.subscribe("Controls:loaded", function () {
    _setDictionary();
    document
      .querySelectorAll(".coloured_icon_circles--single, .content-circles--inner")
      .forEach(function (node) {
        node.style.mixBlendMode = "unset";
      });
    document.querySelectorAll(".archway>button").forEach(function (node) {
      node.style = "background: transparent !important";
    });
    document.querySelector(".uk-width-small").style.setProperty("left", "40px", "");
    document.querySelectorAll(".tier-one > a").forEach(function (node) {
      node.style.setProperty("position", "relative", "important");
      if (node.href.endsWith("contact")) {
        node.style.setProperty("left", "475px", "important");
      } else {
        node.style.setProperty("left", "450px", "important");
      }
      node.style.setProperty("top", "45px", "important");
    });
    var inputElements = document.querySelectorAll(
        ".uk-background-center, .uk-background-cover,.archway,.value,.content-column-block, .tier-one > a ,.link-up , .modals,.aspect-ratio * ,.uk-grid-collapse.uk-grid-match.uk-grid.uk-grid-stack,.uk-grid-collapse.uk-grid-match.uk-grid.uk-grid-stack *,.investors.content-column-block.uk-margin-small-top.uk-flex.uk-flex-middle.background"
      );
      function hasBackgroundColorClassInTree(element) {
        if (Array.from(element.classList).some(className => 
          className.startsWith('background-colour-') || 
          className.startsWith('background-color-')
        )) {
          return true;
        }
        for (let child of element.children) {
          if (hasBackgroundColorClassInTree(child)) {
            return true;
          }
        }
        return false;
      }
      for (var i = 0; i < inputElements.length; i++) {
        var inputElement = inputElements[i];
        if (!hasBackgroundColorClassInTree(inputElement)) {
            inputElement.classList.add('recite-ignore-styles-background');
        }
      }
    var elements = textNodesUnder(bodyNode);
    for (var i = 0; i < elements.length; i++) {
      for (var j = 0; j < correct_translation.length; j++) {
        elements[i].textContent = elements[i].textContent.replace(
          correct_translation[j].from,
          correct_translation[j].to
        );
      }
    }
    document.querySelectorAll("video").forEach(function (video) {
      if (video.muted) {
        video.volume = 0;
      }
    });
    document.querySelectorAll("iframe").forEach(function (iframe) {
      if (iframe.src.includes("youtube.com")) {
        iframe.contentWindow.postMessage('{"event":"command","func":"setVolume","args":[0]}', '*');
      }
      if (iframe.src.includes("vimeo.com")) {
        var vimeoMessage = {
          method: 'setVolume',
          value: 0
        };
        iframe.contentWindow.postMessage(JSON.stringify(vimeoMessage), '*');
      }
    });
  });  
  Recite.Event.subscribe("TextMode:enabled", function () {
    document.querySelectorAll("[uk-sticky]").forEach((e) => {
      e.setAttribute("uk-sticky-x", e.getAttribute("uk-sticky"));
      e.removeAttribute("uk-sticky");
    });
    document.querySelector(
      ".tier-two, .u.k-sticky-placeholder, .uk-flex.page-tabs, .uk-container"
    ).style.display = "none";
  });
  Recite.Event.subscribe("TextMode:disabled", function () {
    document.querySelectorAll("[uk-sticky-x]").forEach((e) => {
      e.setAttribute("uk-sticky", e.getAttribute("uk-sticky-x"));
      e.removeAttribute("uk-sticky-x");
    });
    document.querySelector(
      ".tier-two, .u.k-sticky-placeholder,.uk-flex.page-tabs, .uk-container "
    ).style.display = "block";
    setTimeout(() => {
      document.querySelector("#recite-wrapper > div >header").style =
        "position: fixed !important; top: 60px !important; width: 100% !important;";
    }, 1000);
  });
  window.onscroll = function () {
    document.querySelector("#recite-wrapper > div >header").style =
      "position: fixed; top: 60px; width: 100%;";
  };
  Recite.Event.subscribe("Controls:loaded", function () {
    var css =
      "#recite-wrapper > div > header { position: fixed !important; top: 60px !important; width: 100% !important;}";
    var style = document.createElement("style");
    if (style.styleSheet) {
      style.styleSheet.cssText = css;
    } else {
      style.appendChild(document.createTextNode(css));
    }
    document.getElementsByTagName("head")[0].appendChild(style);
  });
}

function _setDictionary() {
  document
    .querySelectorAll(
      "#recite-dictionary *,.square-content > div > p > recite > strong, .square-content > div > p > recite > recite, #div-content *"
    )
    .forEach(function (e) {
      e.style.setProperty("font-size", "18px", "important");
    });
}

function addNavbarOffset() {
  document.querySelector("header.boundary-align").setAttribute("uk-sticky", "offset: 60;");
}
document.addEventListener("DOMContentLoaded", () => {
  document.querySelectorAll(".js-open-recite-me").forEach((button) => {
    button.addEventListener("click", loadService);
  });
});
window.addEventListener("load", (event) => {
  document.querySelectorAll(".link-up,.tier-one > a,#Urenco_USA, #map").forEach((menu) => {
    menu.setAttribute("data-recite-skip", "true");
  });
  document.querySelectorAll(".link-up,.tier-one > a").forEach((menu) => {
    menu.setAttribute("data-recite-manual", "true");
  });
});
var reciteManualElementsLang = null;
var originalBaseLang = document.querySelector("html").getAttribute("lang");

function _translateManualElements() {
  var lang = Recite.Preferences.get("language");
  if (lang == reciteManualElementsLang) {
    return;
  }
  reciteManualElementsLang = lang;
  var reciteManualElements = document.querySelectorAll("[data-recite-manual]");
  for (var i = 0; i < reciteManualElements.length; i++) {
    reciteManualElements[i].setAttribute("lang", originalBaseLang);
    Recite.Language.Translate.translate(reciteManualElements[i], lang);
  }
}

function _updateFontSize() {
  var c =
    '.link-up, [href="/swu-calculator"] > recite,[href="/contact"] > recite, .js-open-recite-me, .js-open-recite-me > recite ';
  Recite.Util.each(Recite.Sizzle(c), function (a, b, f) {
    (a = b.getAttribute("data-basesize")) ||
      (a = window.getComputedStyle(b).getPropertyValue("font-size"));
    b.setAttribute("data-basesize", a);
    f = Recite.Preferences.get("style.font.size") / 100;
    if (f === 0) {
      f = 1;
    } else if (f >= 1) {
      f = 1;
    }
    var fontSize = parseInt(a) * f + "px";
    b.style.setProperty("font-size", fontSize, "important");
  });
}

function _setDictionary() {
  document
    .querySelectorAll(
      "#recite-dictionary *,.square-content > div > p > recite > strong, .square-content > div > p > recite > recite, #div-content *"
    )
    .forEach(function (e) {
      e.style.setProperty("font-size", "18px", "important");
    });
}

function _updateBackground() {
  var inputElements = document.querySelectorAll(
    ".uk-container.uk-position-relative, .uk-card-media-top"
  );
  for (var i = 0; i < inputElements.length; i++) {
    var inputElement = inputElements[i];
    inputElement.classList += " recite-ignore-styles-background recite-ignore-styles-color";
  }
}

function _resetTheme() {
  const el = document.querySelector("#recite-swatch-reset-default");
  el.addEventListener("click", function () {
    var _resetBackground = {
      style: {
        backgroundColor: null,
        font: {
          color: null,
          face: null,
          size: null,
        },
      },
    };
    setTimeout(() => {
      Recite.Util.each(_resetBackground, function (key, value) {
        Recite.Preferences.reset(key);
      });
    }, "1000");
  });
}

// fix for extra margin being added to accessibility button after a page refresh
document.addEventListener("DOMContentLoaded", function () {
  document.querySelectorAll(".uk-grid .tier-two .nav a.link-up").forEach((a) => {
    a.classList.add("data-recite-skip");
  });
});