/* Lighter Blue Background for Sub-Menu */
nav ul.sub-menu {
    background-color: #8BB8E8 !important; /* Lighter Blue */
}

/* White Text for Sub-Menu Links */
nav ul.sub-menu li a {
    color: #FFFFFF !important; /* White font color */
    font-weight: bold;
    opacity: 1 !important;
}

/* White Text on Hover for Sub-Menu Links */
nav ul.sub-menu li a:hover {
    color: #FFFFFF !important; /* White text on hover */
}

document.addEventListener("DOMContentLoaded", function () {
    function smoothScroll(targetId) {
        let target = document.querySelector(targetId);
        if (target) {
            setTimeout(() => {
                window.scrollTo({
                    top: target.offsetTop - 100, // Adjust offset if needed
                    behavior: "smooth"
                });
            }, 500);
        }
    }

    // Redirect to homepage when clicking a section link from another page
    function handleMenuClick(event, hash) {
        event.preventDefault();

        // If on homepage, just scroll
        if (window.location.pathname === "/" || window.location.pathname === "/index.html") {
            smoothScroll("#" + hash);
        } else {
            // Redirect to homepage with the correct section
            window.location.href = "https://breaultco.com/#" + hash;
        }
    }

    // Check if page loads with a hash and redirect if not on homepage
    if (window.location.hash) {
        const hash = window.location.hash.substring(1);

        // If not on homepage, redirect to homepage with the hash
        if (window.location.pathname !== "/" && window.location.pathname !== "/index.html") {
            window.location.href = "https://breaultco.com/#" + hash;
        } else {
            smoothScroll("#" + hash);
        }
    }

    // Attach click event to all menu links (except About Us)
    document.querySelectorAll('nav a').forEach(link => {
        const href = link.getAttribute("href");

        if (href.includes("#") && !href.includes("about")) {
            link.addEventListener("click", function (event) {
                const hash = href.split("#")[1];
                handleMenuClick(event, hash);
            });
        }
    });
});