jQuery(document).ready(function (jQuery) {

    if (document.body.classList.contains('et-fb')) {
        return;
    }

    let siteName = document.querySelector('meta[property="og:site_name"]')?.getAttribute('content');
    if (siteName) {
        const footer = document.querySelector('footer');

        let copyrightFooterText = 'Copyright © ' + new Date().getFullYear() + ' ' + siteName + '. All rights reserved. ';
        if (footer && /(powered by|menusifu)/i.test(footer.textContent)) {
            copyrightFooterText += 'Powered by <b><a aria-label="Menusifu" href="https://www.menusifu.com" target="_blank" tabindex="0">Menusifu</a></b>.';
        }

        copyrightFooterText +=
            '<br/>' +
            '<b><a aria-label="Accessibility Statement" href="/accessibility-statement" id="accessibility-statement-link" tabindex="0">Accessibility Statement</a></b>' +
            '<span aria-hidden="true"> | </span>' +
            '<b><a aria-label="Report a web accessibility issue" href="https://forms.gle/eYyaX1D4W16tMRR16" tabindex="0">Report a web accessibility issue</a></b>';

        const walker = document.createTreeWalker(footer, NodeFilter.SHOW_TEXT, {
            acceptNode: node => /all rights/i.test(node.textContent) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
        });

        copyrightFooterText = '<p>' + copyrightFooterText + '</p>';

        const textNode = walker.nextNode();

        if (textNode?.parentElement) {
            textNode.parentElement.innerHTML = '<div id="copyright-footer-text">' + copyrightFooterText + '</div>';
        }
    }


    let header = document.querySelector('header');
    if (header) {
        let headerImage = header.querySelector('img[src*="Transparent"], img[src*="Divi"]');
        if (headerImage) {
            headerImage.parentElement.remove(); //.removeChild(headerImage);
        }

        // set image logo alt in header
        document.querySelectorAll('header .et_pb_menu__logo img').forEach(img => {
            if (!img.hasAttribute('alt') || img.getAttribute('alt') === '') {
                img.setAttribute('alt', siteName + ' Logo'); // Set your desired alt text
            }
        });
    }

    // Get current page URL parameters
    const currentParams = new URLSearchParams(window.location.search);

    if (currentParams.toString()) {
        // Loop through all anchor tags with href attributes
        document.querySelectorAll('a[href]').forEach(link => {
            try {
                const url = new URL(link.href);

                // Only modify links where the domain includes "abc.com"
                if (url.hostname.includes('mealkeyway.com')) {
                    // Append current URL parameters to the link
                    currentParams.forEach((value, key) => {
                        url.searchParams.set(key, value);
                    });

                    // Update the link's href
                    link.href = url.toString();
                }
            } catch (e) {
                console.warn('Skipped invalid URL:', link.href);
            }
        });
    }

    // set bypass cookie so that page won't be cached
    if (document.querySelectorAll("form").length > 0 && !document.cookie.match(/^(.*;)?\s*cache_bypass\s*=\s*[^;]+(.*)?$/)) {
        document.cookie = "cache_bypass=true";
        location.reload();
    }

    let viewport = document.querySelector("meta[name=viewport]");
    if (viewport) viewport.setAttribute('content', 'width=device-width, initial-scale=1.0');

    // add accessibility statement button
    let accessibilityStatementLink = document.createElement('a');
    accessibilityStatementLink.appendChild(document.createTextNode("Go to accessibility statement"));
    accessibilityStatementLink.title = 'Go to accessibility statement';
    accessibilityStatementLink.href = '/accessibility-statement';
    accessibilityStatementLink.id = 'accessibility-statement-link-id';
    accessibilityStatementLink.className = 'accessibility-statement-link';
    accessibilityStatementLink.setAttribute("tabIndex", "0");
    document.getElementById('page-container')?.querySelector('header')?.prepend(accessibilityStatementLink);

    // add skip tp main content button
    let skipToMainContentLink = document.createElement('a');
    skipToMainContentLink.appendChild(document.createTextNode("Skip to main content"));
    skipToMainContentLink.title = "Skip to main content";
    skipToMainContentLink.href = "#et-main-area";
    skipToMainContentLink.id = 'skip-to-main-content-link-id';
    skipToMainContentLink.className = 'skip-to-main-content-link';
    skipToMainContentLink.setAttribute("tabIndex", "0");
    document.getElementById('page-container')?.querySelector('header')?.prepend(skipToMainContentLink);

    // move footer outside of div 
    let pageContainerFooter = document.querySelector('#et-main-area footer');
    let pageContainer = document.getElementById('page-container');
    let pageContainerHeader = pageContainer.querySelector('header');
    if (pageContainerFooter && !pageContainerHeader.nextElementSibling?.matches('footer')) {
        pageContainer.appendChild(pageContainerFooter);
    }

    // change div to main 
    let pageContainerDiv = document.getElementById('et-main-area');
    if (pageContainerDiv && pageContainerDiv.tagName === 'DIV') {
        let tempMain = document.createElement('main');

        for (let j = 0; j < pageContainerDiv.attributes.length; j++) {
            let tempAttr = pageContainerDiv.attributes[j];
            tempMain.setAttribute(tempAttr.name, tempAttr.value);
        }

        // Move children
        while (pageContainerDiv.firstChild) {
            tempMain.appendChild(pageContainerDiv.firstChild);
        }

        // Set tabidex=-1 for focus purposes
        tempMain.setAttribute('tabindex', '-1');

        // Replace article with div
        pageContainerDiv.parentNode.replaceChild(tempMain, pageContainerDiv);

    }

    // change article to div
    let articles = document.querySelectorAll('article');
    for (let i = 0; i < articles.length; i++) {
        var article = articles[i];
        let tempDiv = document.createElement('div');

        // Copy attributes
        for (let j = 0; j < article.attributes.length; j++) {
            let tempAttr = article.attributes[j];
            tempDiv.setAttribute(tempAttr.name, tempAttr.value);
        }

        // Move children
        while (article.firstChild) {
            tempDiv.appendChild(article.firstChild);
        }
        // Replace article with div
        article.parentNode.replaceChild(tempDiv, article);
    }

    // scroll to top to adhere accessibility issue
    let scrollTop = document.querySelector('.et_pb_scroll_top');
    if (scrollTop) {
        let anchor = document.createElement('a');
        anchor.href = '#page-container';
        anchor.className = scrollTop.className;
        anchor.innerHTML = scrollTop.innerHTML;
        scrollTop.replaceWith(anchor);

        scrollTop = document.querySelector('.et_pb_scroll_top');
        // move scroll to top after footer
        const footer = document.querySelector('footer');
        if (footer) {
            footer.insertAdjacentElement('afterend', scrollTop);
        }
    }
    jQuery(".et_pb_scroll_top").attr({ "aria-label": "Scroll to top", "role": "button", "tabindex": "0" });

    // make sure all the internal links are scrolled smoothly
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            const scrollToTarget = document.querySelector(this.getAttribute('href'));


            if (scrollToTarget) {
                e.preventDefault();
                scrollToTarget.scrollIntoView({ behavior: 'smooth' });

                if (scrollToTarget.id === 'page-container') {
                    setTimeout(() => {
                        document.querySelector('#skip-to-main-content-link-id').focus();
                    }, 500);

                }
            }
        });
    });


    // move et-social-icons
    let socialIconsDiv = document.querySelector('.et-social-icons');
    if (socialIconsDiv) {
        let nextDiv = socialIconsDiv.nextElementSibling;
        if (nextDiv && nextDiv.tagName === 'DIV') {
            nextDiv.parentNode.insertBefore(socialIconsDiv, nextDiv.nextElementSibling);
        }
    }


    // move header/main out of et-boc if exists
    let etBoc = document.getElementById('et-boc');
    if (etBoc) {
        etBoc.parentNode.insertBefore(pageContainerHeader, etBoc);
        pageContainerDiv = document.getElementById('et-main-area');
        etBoc.parentNode.insertBefore(pageContainerDiv, etBoc);
        etBoc.remove();
    }

    // retrieve email and phone info for the assessibility statement
    let pageContent = document.querySelector('body').innerText;

    let emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
    let emails = pageContent.match(emailRegex);
    let filteredEmails = emails ? emails.filter(e => e.length > 5) : [];
    let firstEmail = filteredEmails.length > 0 ? filteredEmails[0] : '';

    let phoneRegex = /(?:\+?\d{1,3}[ -]?)?(?:\(?\d{2,4}\)?[ -]?)?\d{3,4}[ -]?\d{3,4}/g;
    let phones = pageContent.match(phoneRegex);
    let filteredPhones = phones ? phones.filter(p => p.replace(/\D/g, '').length >= 10) : [];
    let firstPhone = filteredPhones.length > 0 ? filteredPhones[0] : '';

    firstPhone = trimPhoneFormat(firstPhone);

    function trimPhoneFormat(original) {
        let digitCount = 0;
        let firstDigit = null;
        let result = '';

        for (let char of original) {
            if (/\d/.test(char)) {
                if (firstDigit === null) {
                    firstDigit = char;
                }
                digitCount++;
                if (
                    (firstDigit === '1' && digitCount > 11) ||
                    (firstDigit !== '1' && digitCount > 10)
                ) {
                    break;
                }
            }
            result += char;
        }
        return result;
    }


    // create accessibility statement
    let originalContent = document.getElementById("et-main-area").innerHTML;
    let newContent = `
        <div class="et_pb_section"><div class="et_pb_row">
        <h1 style="text-align:center;margin-bottom:30px">Accessibility Statement</h1>
            <p> <b>${siteName}</b> is committed to providing an inclusive and accessible experience to everyone, including those with disabilities.</p>
            <p> Our commitment is guided by our accessibility policy to ensure that people with disabilities have full and equal opportunity to access and benefit from its products and information provided on the website using the Web Content Accessibility Guidelines (WCAG) version 2.2 AA.</p>
            <h2 style="margin:20px 0"> Support / Feedback</h2>
            <p> How can we provide support and improve accessibility?</p>
            <p> We welcome your questions and feedback on the accessibility of our website. Please let us know how we can assist you if you encounter any barriers to access:</p>
            <ul>
                ${firstEmail ? `<li>Email: <a style="color: #000000; text-decoration: underline;" href="mailto:${firstEmail}" target="_blank" aria-label="${firstEmail}, This link will open in a new tab">${firstEmail}</a> with subject line: <b>Accessibility Support</b></li>` : ''}
                ${firstPhone ? `<li>Accessibility Support Phone: <a style="color: #000000; text-decoration: underline;" href="tel:${firstPhone}" target="_blank" aria-label="Tel: ${firstPhone}, This link will open in a new tab">Tel: ${firstPhone}</a></li>` : ''}
                <li>Visit this page to <a style="color: #000000; text-decoration: underline;" href="https://forms.gle/eYyaX1D4W16tMRR16" target="_blank" aria-label="Report a web accessibility issue, This link will open in a new tab">Report a web accessibility issue</a>
            </ul>
            <h2 style="margin:20px 0"> Compatibility </h2>
            <p> ${siteName} is designed to be compatible with assistive technologies using current operating systems, and the last two versions of major browsers including Chrome, Safari, FireFox, and Edge. Assistive technologies include NVDA, JAWS, VoiceOver, and mobile screen readers.</p>
            <p> The website may not display optimally in older browsers or older operating systems.</p>
            <h2 style="margin:20px 0"> Expertise </h2>
            <p> Our website platform provider <a style="color: #000000; text-decoration: underline;" href="https://www.menusifu.com/" target="_blank" rel="noopener" aria-label="Menusifu, This link will open in a new tab">Menusifu</a> has retained <a style="color: #000000; text-decoration: underline;" href="http://www.ecomback.com/" target="_blank" rel="noopener" aria-label="EcomBack, This link will open in a new tab">EcomBack</a> as an independent third-party website and digital accessibility specialist to provide consultation and periodic audits for usability and WCAG 2.2 AA conformance. EcomBack prepares a written report based on the evaluation, which helps to identify any barriers and provides remediation and recommendations to enhance the accessibility of the website.</p>
            <h2 style="margin:20px 0"> Testing </h2>
            <p>Automated tools and manual user testing by professionals with disabilities are utilized to continually assess and improve the usability and accessibility of the website.</p>
            <h2 style="margin:20px 0"> Training </h2>
            <p> We further invest in training on accessibility for our digital team to ensure our web content personnel, developers, designers, and other team members are knowledgeable and follow best practices for accessibility. </p>
            <h2 style="margin:20px 0"> Helpful Resources </h2>
            <ul>
                <li><a style="color: #000000; text-decoration: underline;" href="https://www.ada.gov/2010_regs.htm" target="_blank" rel="noopener" aria-label="The Americans with Disabilities Act, This link will open in a new tab">The Americans with Disabilities Act</a></li>
                <li><a style="color: #000000; text-decoration: underline;" href="https://www.w3.org/WAI/" target="_blank" rel="noopener" aria-label="W3C Web Accessibility Initiative, This link will open in a new tab">W3C Web Accessibility Initiative</a></li>  
                <li><a style="color: #000000; text-decoration: underline;" href="https://www.w3.org/TR/WCAG21/" target="_blank" rel="noopener" aria-label="Web Content Accessibility Guidelines, This link will open in a new tab">Web Content Accessibility Guidelines</a></li>
                <li><a style="color: #000000; text-decoration: underline;" href="https://support.apple.com/guide/mac-help/get-started-with-accessibility-features-mh35884/mac" target="_blank" rel="noopener" aria-label="Apple Mac OS Accessibility, This link will open in a new tab">Apple Mac OS Accessibility</a></li>
                <li><a style="color: #000000; text-decoration: underline;" href="https://about.google/belonging/disability-inclusion/product-accessibility/" target="_blank" rel="noopener" aria-label="Google Accessibility, This link will open in a new tab">Google Accessibility</a></li>
                <li><a style="color: #000000; text-decoration: underline;" href="https://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly" target="_blank" rel="noopener" aria-label="Mozilla Firefox Browser Accessibility, This link will open in a new tab">Mozilla Firefox Browser Accessibility</a></li>
                <li><a style="color: #000000; text-decoration: underline;" href="https://support.microsoft.com/en-us/microsoft-edge/accessibility-features-in-microsoft-edge-4c696192-338e-9465-b2cd-bd9b698ad19a#ID0EBBD=Windows" target="_blank" rel="noopener" aria-label="Microsoft Edge Accessibility, This link will open in a new tab">Microsoft Edge Accessibility</a></li>
                <li><a style="color: #000000; text-decoration: underline;" href="https://www.nvaccess.org/download/" target="_blank" rel="noopener" aria-label="NVDA screen reader (free), This link will open in a new tab">NVDA screen reader (free)</a></li>
            </ul>
            <h2 style="margin:20px 0"> Accessibility Shortcuts Guide </h2>
            <p><a style="color: #000000; text-decoration: underline;" href="https://www.ecomback.com/accessibility-shortcuts-guide-for-screen-readers-and-browsers" target="_blank" rel="noopener" aria-label="Read this helpful Accessibility Shortcuts Guide for Screen Readers and Browsers(opens new window), This link will open in a new tab">Read this helpful Accessibility Shortcuts Guide for Screen Readers and Browsers</a></p>
            <br aria-hidden="true"><br aria-hidden="true">
            <p>Last updated: April 24, 2025</p>
        </div></div>
    `;

    // automatically replace content if has accessibility-statement parameter
    if (currentParams.toString().includes('accessibility-statement=true')) {
        let mainArea = document.getElementById("et-main-area");
        mainArea.innerHTML = newContent;
        window.history.replaceState(null, '', window.location.origin + '/accessibility-statement');
    }


    // Event listener for the accessibility statement link
    document.querySelectorAll('a[href*="accessibility-statement"]').forEach(el => {

        el.addEventListener('click', function (event) {
            event.preventDefault(); // Stop the default behavior of the link

            // Update the URL to /accessibility without reloading
            history.pushState({ page: "accessibility-statement" }, "Accessibility Statement", "/accessibility-statement");

            // Modify the webpage title
            const pageTitle = document.title;
            document.title = "Accessibility Statement - " + pageTitle.split(" - ")[1];

            // Replace the content in #et-main-area
            let mainArea = document.getElementById("et-main-area");
            if (mainArea) {
                mainArea.innerHTML = newContent;
            }
            mainArea.scrollIntoView({ behavior: 'smooth' });

            setTimeout(() => {
                mainArea.focus();

                document.querySelectorAll('header li a').forEach(function (e) {
                    const href = e.getAttribute('href');
                    if (href && href.startsWith('#')) {
                        e.setAttribute('href', '/' + href.substring(1));
                    }
                });

            }, 1000);

        });
    });

    // Handle the back button
    window.addEventListener("popstate", function (event) {
        let mainArea = document.getElementById("et-main-area");

        // When navigating back, restore the original content
        if (mainArea) {
            if (event.state && event.state.page === "accessibility-statement") {
                // If we are on the accessibility page, show the accessibility content
                mainArea.innerHTML = newContent;
            } else {
                // Restore the original content of #et-main-area when back is pressed
                mainArea.innerHTML = originalContent;
                location.reload();
            }
        }
    });

    // set alt text to remind it is third party link 
    jQuery('a').each(function () {
        let link = jQuery(this);
        let href = link.attr('href');
        if (!href) return;
        if (link.find('img').length > 0) {
            let img = link.find('img');
            if (isThirdParty(href)) {

                // make sure the link has target="_blank" for all external links
                if (link.attr('target') !== '_blank') {
                    link.attr('target', '_blank');
                }

                let altText = img.attr('alt') || '';
                let altTitle = img.attr('title') || '';
                altText = altText ? altText + ', This link will open in a new tab' : 'This link will open in a new tab';
                altTitle = altTitle ? altTitle + ', This link will open in a new tab' : 'This link will open in a new tab';
                img.attr('alt', altText);
                img.attr('title', altTitle);
            }
            return; // Done with this link
        }

        if (isThirdParty(href)) {

            // make sure the link has target="_blank" for all external links
            if (link.attr('target') !== '_blank') {
                link.attr('target', '_blank');
            }
            let existingText = link.text().trim();
            link.attr('aria-label', existingText + ', This link will open in a new tab');
        }

        if (!link.attr('aria-label')) {
            let existingText = link.text().trim();
            link.attr('aria-label', existingText + (link.attr('target') === '_blank' ? ', This link will open in a new tab' : ''));
        }

    });

    // function to check if a link is from a third-party website
    function isThirdParty(url) {
        if (!url || typeof url !== 'string') return false;
        if (url.startsWith('/') || url.startsWith('#')) return false;
        if (url.includes(window.location.hostname)) return false;
        return true;
    }


    // set standard alt for images 
    let images = document.querySelectorAll("#page-container img");
    for (let i = 0; i < images.length; i++) {
        if (images[i].alt && images[i].alt.length >= 3) continue;

        if (images[i].title && images[i].title.length >= 5) {
            images[i].alt = images[i].title.replaceAll('-', ' ').replaceAll('_', ' ').replaceAll('#', ' ');
        } else {
            images[i].alt = 'Food and Restaurant ' + (i + 1);
        }

    }

    let iframes = document.querySelectorAll("iframe");
    for (let i = 0; i < iframes.length; i++) {
        if (!iframes[i].title)
            iframes[i].title = 'Iframe ' + (i + 1);
    }

    // fix accessibility on mobile webpage
    jQuery('span.mobile_menu_bar.mobile_menu_bar_toggle').attr('aria-label', 'Main Menu');
    jQuery('.mobile_menu_bar_toggle').attr('aria-expanded', 'false');
    jQuery('.mobile_menu_bar_toggle').on('click', function () {
        let isExpanded = jQuery(this).attr('aria-expanded') === 'true';
        jQuery(this).attr('aria-expanded', !isExpanded);
    });

    // Some additional accessibility related updates
    jQuery(".logo_helper, .et_overlay.dsm-overlay").attr("role", "none");
    jQuery("ul.sub-menu").prev("a").attr({ "aria-haspopup": "true", "aria-expanded": "false" });
    jQuery(".mobile_menu_bar").attr({ "role": "button", "tabindex": "0" });

    jQuery('br').attr('aria-hidden', 'true');
    jQuery('form input, form textarea').attr('required', '');
    jQuery('a.et_pb_video_play').attr('aria-label', 'Play the Video');

    jQuery('form input, form textarea').removeAttr('placeholder');
    jQuery('.et-pb-contact-message').insertAfter('.et_pb_contact');
    jQuery('.dsm_faq-item-close_icon, .dsm_faq-item-open_icon').attr('aria-hidden', 'true');


    // run after dom and everything else is finished 
    setTimeout(() => {

        //make sure the social icons has correct aria-label
        let socialFollowLinks = document.querySelectorAll(".et_pb_social_media_follow a");
        if (socialFollowLinks) {
            socialFollowLinks.forEach(link => {
                const aria = link.getAttribute('aria-label');
                if (!aria) return;
                const title = link.getAttribute('title');
                const updatedAria = aria.replace(/^Follow\b/, title);
                link.setAttribute('aria-label', updatedAria);
            });
        }

        jQuery('svg.rough-annotation').attr('aria-hidden', 'true');

        jQuery(".dsm-popup-wrap").attr({ "aria-modal": "true", "role": "dialog" });
        jQuery(".et-pb-slider-arrows a, .et-pb-controllers a").attr("role", "button");

        jQuery('a[href^="tel:"]').each(function () {
            var phoneNumber = jQuery(this).text().trim();
            jQuery(this).attr('aria-label', 'Phone Number: ' + phoneNumber);
            jQuery(this).removeAttr('target');
        });

        jQuery('a[href^="mailto:"]').each(function () {
            var emailAddress = jQuery(this).text().trim();
            jQuery(this).attr('aria-label', 'Email at: ' + emailAddress);
            jQuery(this).removeAttr('target');
        });

    }, 1000);

    // Modify the public pop-up window on the web page
    const array = document.querySelectorAll('.dsm-popup')
    for (let index = 0; index < array.length; index++) {
        const element = array[index]
        const ob = new MutationObserver((mutationsList, observer) => {
            for (const mutation of mutationsList) {
                if (mutation.type === 'childList' && mutation.addedNodes.length) {
                    // Pop-up open
                    let ariaLabel = 'Information Dialog'
                    const popupContent = document.querySelector('.mfp-content')
                    const closeBtn = document.querySelector('.mfp-close')
                    const dsmPopupWrap = document.querySelector('.dsm-popup-wrap')
                    const aria_el = popupContent.querySelector('#custom-accessible-popup-aria-label')
                    if (aria_el) {
                        if (aria_el.childNodes.length) {
                            let childrenList = aria_el.querySelectorAll('*')
                            for (let index = 0; index < childrenList.length; index++) {
                                if (childrenList[index].tagName === 'IMG') {
                                    ariaLabel = childrenList[index].alt
                                    break
                                }
                                if (childrenList[index].tagName === 'P') {
                                    ariaLabel = childrenList[index].textContent
                                    break
                                }
                            }
                        }
                    }
                    popupContent.setAttribute('tabindex', '0')
                    dsmPopupWrap.setAttribute('role', 'dialog')
                    dsmPopupWrap.setAttribute('aria-modal', 'true')
                    dsmPopupWrap.setAttribute('aria-label', ariaLabel)
                    dsmPopupWrap.setAttribute('tabindex', '-1')
                    closeBtn.setAttribute('aria-label', 'Close')
                    closeBtn.replaceChildren()
                    closeBtn.insertAdjacentHTML('beforeend', `
                    <span class="custom-et-pb-icon" aria-hidden="true"></span>
                `);
                } else {
                    // Pop-up close
                    document.querySelector('.skip-to-main-content-link').focus()
                }
            }
        })
        ob.observe(element, { childList: true, attributes: false, subtree: false })
    }
    
    // Decorative pictures are not read
    const customBackgroundImageHidden = document.querySelectorAll('.custom-background-image-hidden')
	for (let index = 0; index < customBackgroundImageHidden.length; index++) {
		const element = customBackgroundImageHidden[index]
		const img = element.querySelector('img')
		img.setAttribute('aria-hidden', 'true')
		img.setAttribute('tabindex', '-1')
	}
	
	// Fixing Screen Reader Issues with Multiple Online Order Links
	let menuElement = []
	if (document.querySelector('#menu-main-menu')) {
		menuElement = document.querySelector('#menu-main-menu').children
	} else {
		menuElement = document.querySelector('#top-menu') ? document.querySelector('#top-menu').children : []
	}
	for (let index = 0; index < menuElement.length; index++) {
		const itemHasChildren = menuElement[index].classList.contains('menu-item-has-children')
		let a_el = menuElement[index].querySelector('a')
		if (itemHasChildren) {
			if (a_el.href.indexOf('#') !== -1) {
				a_el.setAttribute('aria-label', 'Online Order - Expand to select (contains submenu)')
			}
		} else {
			const val = a_el.innerText.toUpperCase()
			if (a_el.href && (val.indexOf('ONLINE ORDER') !== -1 || val.indexOf('PICK UP') !== -1)) {
				a_el.setAttribute('aria-label', 'Access the Online Order page from the navigation bar. This link will open in a new tab.')
			}
		}
	}
	const a_list = document.querySelectorAll('main a')
	let index1 = 0
	const labelList = [
		'Start your online order',
		'Proceed to online ordering page',
		'Begin online order process',
		'Place order online'
	]
	for (let index = 0; index < a_list.length; index++) {
		const element = a_list[index]
		const list = ['ONLINEORDER', 'ORDERNOW', 'ONLINEORDERNOW', 'PICKUPDELIVERY']
		const value = element.innerText.replace(/[\p{P}\s]/gu, '').toUpperCase()
		if (list.findIndex(e => e === value) !== -1 && !element.classList.contains('custom-aria-label')) {
			index1++
			let str = element.href.indexOf(window.location.hostname) !== -1 ? '' : '. This link will open in a new tab.'
			if (index1 === 1) {
				element.setAttribute('aria-label', 'Access the Online Order page from the main content' + str)
			} else {
				element.setAttribute('aria-label', labelList[index1 - 2] ? labelList[index1 - 2] + str : 'Online order (opens in a new tab)')
			}
		}
	}
	
	// Website bottom accessibility image alt attribute settings
	document.querySelectorAll('footer img').forEach(e => {
		if (e.src.toLowerCase().indexOf('accessibility') !== -1 || e.src.toLowerCase().indexOf('ada') !== -1) {
			const text = 'Audited and certified for accessibility and usability by disabled testers.'
			e.title = text
			e.alt = text
		}
	})
	
	// Background video ada fix
	if (jQuery('.mejs-mediaelement video').length) {
      jQuery('span.et_pb_section_video_bg.et_pb_video_play_outside_viewport span.mejs-offscreen').remove();
      jQuery('.mejs-container.mejs-container-keyboard-inactive.mejs-video').removeAttr('tabindex');
      jQuery('.mejs-container.mejs-container-keyboard-inactive.mejs-video').removeAttr('role');
      jQuery('.mejs-container.mejs-container-keyboard-inactive.mejs-video').removeAttr('aria-label');
      jQuery('.mejs-mediaelement video').removeAttr('aria-label');
    }

});
