<!-- Start of HubSpot Embed Code -->
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/22027035.js"></script>
<!-- End of HubSpot Embed Code -->

<!-- Hotjar Tracking Code for https://www.fiveseasonswindows.com/ -->
<script>
(function (h, o, t, j, a, r) {
  h.hj = h.hj || function () {
    (h.hj.q = h.hj.q || []).push(arguments);
  };
  h._hjSettings = { hjid: 3720778, hjsv: 6 };
  a = o.getElementsByTagName("head")[0];
  r = o.createElement("script");
  r.async = 1;
  r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
  a.appendChild(r);
})(window, document, "https://static.hotjar.com/c/hotjar-", ".js?sv=");
</script>

<script>
(function () {
  const menuUpdates = [
    {
      selector: 'li[data-menu="0"] .meganav-container__grid-sub-nav-title',
      href: "/windows/styles",
      text: "Window Styles",
    },
    {
      selector: 'li[data-menu="0"] .meganav-container__stack-sub-nav-title',
      href: "/windows/materials",
      text: "Window Materials",
    },
    {
      selector: 'li[data-menu="1"] .meganav-container__grid-sub-nav-title',
      href: "/doors",
      text: "Door Styles",
    },
    {
      selector: 'li[data-menu="2"] .meganav-container__grid-sub-nav-title',
      href: "/brands",
      text: "Brands We Love",
    },
    {
      selector: 'li[data-menu="4"] .meganav-container__stack-sub-nav-title',
      href: "/about-us",
      text: "About Us",
    },
    {
      selector: 'li[data-menu="4"] .meganav-container__grid-sub-nav-title',
      href: "/media",
      text: "News Media",
    },
  ];

  function updateMenuLinks() {
    menuUpdates.forEach((update) => {
      const element = document.querySelector(update.selector);
      if (element) {
        let link = element.querySelector("a");
        if (!link) {
          link = document.createElement("a");
          link.className = "mm-nav-link";
          element.innerHTML = "";
          element.appendChild(link);
        }
        link.href = update.href;
        link.textContent = update.text;
      }
    });
  }

  function runWhenReady() {
    if (document.readyState !== "loading") {
      updateMenuLinks();
    } else {
      document.addEventListener("DOMContentLoaded", updateMenuLinks);
    }
  }

  // Try to run immediately
  runWhenReady();

  // Also run after a short delay to ensure DOM is fully processed
  setTimeout(runWhenReady, 500);

  // Run the script again when the window is fully loaded
  window.addEventListener("load", updateMenuLinks);
})();
</script>

<script>
// Add a style tag to hide the form container initially
var style = document.createElement("style");
style.textContent = "#hbspt-form { visibility: hidden; }";
document.head.appendChild(style);

// Function to load the HubSpot script and create the form
function loadHubSpotForm() {
  if (typeof hbspt === "undefined") {
    var script = document.createElement("script");
    script.async = true;
    script.defer = true;
    script.onload = function () {
      createForm();
    };
    script.src = "//js.hsforms.net/forms/embed/v2.js";
    document.head.appendChild(script);
  } else {
    createForm();
  }
}

// Function to create the form
function createForm() {
  hbspt.forms.create({
    region: "na1",
    portalId: "22027035",
    formId: "9567dc41-6d2b-456c-8926-17fde530fac1",
    target: "#hbspt-form",
    onFormReady: function ($form) {
      // This function runs after the form is fully loaded
      // Remove the hiding style to reveal the form
      style.textContent = "";
    },
  });
}

// Load the form when the page is ready
if (document.readyState === "loading") {
  document.addEventListener("DOMContentLoaded", loadHubSpotForm);
} else {
  loadHubSpotForm();
}
</script>