document.addEventListener("DOMContentLoaded", function () {
	"use strict";

	/* ==========================
	   Infinite Marquee
	========================== */

	const homeElectricianTrack = document.querySelector(".feature-track");

	if (homeElectricianTrack) {
		homeElectricianTrack.innerHTML += homeElectricianTrack.innerHTML;

		let homeElectricianX = 0;
		const homeElectricianSpeed = 1;

		function homeElectricianMarquee() {
			homeElectricianX -= homeElectricianSpeed;

			if (Math.abs(homeElectricianX) >= homeElectricianTrack.scrollWidth / 2) {
				homeElectricianX = 0;
			}

			homeElectricianTrack.style.transform =
				`translateX(${homeElectricianX}px)`;

			requestAnimationFrame(homeElectricianMarquee);
		}

		homeElectricianMarquee();
	}

	/* ==========================
	   Text Reveal Animation
	========================== */

	if (typeof gsap !== "undefined" && typeof ScrollTrigger !== "undefined") {

		gsap.registerPlugin(ScrollTrigger);

		function homeElectricianSplitText() {

			document.querySelectorAll(".reveal-type").forEach(function (homeElectricianElement) {

				const homeElectricianText = homeElectricianElement.textContent.trim();
				const homeElectricianWords = homeElectricianText.split(" ");

				homeElectricianElement.innerHTML = "";

				homeElectricianWords.forEach(function (homeElectricianWord) {

					const homeElectricianWordSpan = document.createElement("span");
					homeElectricianWordSpan.classList.add("word");

					[...homeElectricianWord].forEach(function (homeElectricianChar) {

						const homeElectricianCharSpan = document.createElement("span");
						homeElectricianCharSpan.classList.add("char");
						homeElectricianCharSpan.textContent = homeElectricianChar;

						homeElectricianWordSpan.appendChild(homeElectricianCharSpan);

					});

					homeElectricianElement.appendChild(homeElectricianWordSpan);
					homeElectricianElement.appendChild(document.createTextNode(" "));

				});

			});

		}

		homeElectricianSplitText();

		gsap.utils.toArray(".reveal-type").forEach(function (homeElectricianSection) {

			const homeElectricianChars = homeElectricianSection.querySelectorAll(".char");

			gsap.fromTo(
				homeElectricianChars,
				{
					opacity: 0,
					filter: "blur(8px)"
				},
				{
					opacity: 1,
					filter: "blur(0px)",
					stagger: 0.03,
					ease: "power2.out",
					scrollTrigger: {
						trigger: homeElectricianSection,
						start: "top 85%",
						end: "top 15%",
						scrub: true
					}
				}
			);

		});

	} else {
		console.error("GSAP or ScrollTrigger is not loaded.");
	}

});