document.addEventListener('DOMContentLoaded', function () {
    var elems = document.querySelectorAll('.parallax');
    var parallaxes = M.Parallax.init(elems, {});

    var elems = document.querySelectorAll('.slider');
    var sliders = M.Slider.init(elems, {
        indicators: true,
        duration: 500,
        interval: 5000
    });

    var mailcypts = document.querySelectorAll(".cryptmail");
    mailcypts.forEach(element => {
        element.onclick = function () {
            window.location.href = 'mailto:' + this.dataset.name + '@' + this.dataset.domain + '.' + this.dataset.tld;

            return false;
        }
    });

    var hashAnchors = document.querySelectorAll("a[href^='#']");
    hashAnchors.forEach(element => {
        element.onclick = function () {
            var target = this.getAttribute("href");
            scrollToElement(target);

            return false;
        }
    });
});

function scrollToElement(name) {
    var elementToScrollTo = document.querySelector(name);
    var top = elementToScrollTo.getBoundingClientRect().top + window.pageYOffset - 48;

    window.scrollTo({
        top: top,
        behavior: "smooth"
    })
}