function createDialogImage(url) {
    createDialogHTML(`<img src="${url}">`, "imageDialog");
}

function createDialogHTML(html, customClasses = "") {
    let dialog = document.createElement("div");
    dialog.classList.add("dialog");

    dialog.innerHTML = `
    <span class="close">&times;</span>
    <div class="dialogContent ${customClasses}">
        ${html}
    </div>`;

    document.body.appendChild(dialog);
    fade(dialog, 0.04);

    dialog.querySelector(".close").onclick = function (){
        fade(dialog, -0.04, true);
    }
}

function fade(element, value = 0.1, deleteAfterwards = false) {
    let opacity = +(element.style.opacity) + value;

    element.style.opacity = String(opacity);

    if ((opacity < 1 && value > 0) || (opacity >= 0 && value < 0)) {
        setTimeout(function () {
            fade(element, value, deleteAfterwards);
        }, 10);
    } else if (deleteAfterwards) {
        setTimeout(function () {
            element.parentNode.removeChild(element);
        }, 10);
    }
}