document.addEventListener("DOMContentLoaded", () => {
    var cells = document.getElementsByTagName("img");
    for (var i = 0; i < cells.length; i++) {
        cells[i].classList = "shown";
        //cells[i].children[0].style = "background-color: black;";
        cells[i].addEventListener("click", function clicker() {
            var ells = Array.from(document.getElementsByTagName("img"));
            var selfindex = ells.indexOf(this);
            //console.log(selfindex);
            var replaceclass = (a) => {
                if (a.classList == "shown") {
                    a.classList = "hidden";
                    a.title = "Lámpa lekapcsolva"
                }
                else {
                    a.classList = "shown";
                    a.title = "Lámpa felkapcsolva"
                }
            };
            if (selfindex - 5 > 0)
                replaceclass(ells[selfindex - 5]);
            if (selfindex - 1 > 0 && (selfindex) % 5 != 0)
                replaceclass(ells[selfindex - 1]);
            if (selfindex + 1 < ells.length && (selfindex + 1) % 5 != 0)
                replaceclass(ells[selfindex + 1]);
            if (selfindex + 5 < ells.length)
                replaceclass(ells[selfindex + 5]);
            replaceclass(this);

            var end = true
            for (var i = 0; i < ells.length; i++) {
                if (ells[i].classList == "shown") {
                    end = false;
                    break;
                }
            }
            if (end) {
                for (var i = 0; i < ells.length; i++) {
                    ells[i].removeEventListener("click", clicker);
                }
            }
        });
    }
});