window.onload = function() {
    let nav = document.getElementById("nav")
    let items = nav.getElementsByClassName("menu-item");
    for (let i = 0; i < items.length; i++) {
        let item = items[i]
        item.onclick = function () {
            for (let j = 0; j < items.length; j++) {
                if (i === j) {
                    continue
                }
                let oldItem = items[j]
                oldItem.getElementsByClassName("submenu")[0].classList.remove('show')
            }

            let submenu = item.getElementsByClassName("submenu")[0];
            if (submenu.classList.contains('show')) {
                submenu.classList.remove('show')
            } else {
                submenu.classList.add('show')
            }
        }
    }
}
