
var flipContainerInterval = null;

function flipContainerSetCheckInterval() {
    var e = document.querySelectorAll('[class*="frame-type-gallery"]')[0];
    if (e) {
        flipContainerInterval = setInterval("flipContainerCheck()",1000);
    }
}

function flipContainerHide() {
    var e = document.querySelectorAll('[class*="frame-type-gallery"]')[0];
    if (e) {
        e.setAttribute("style","opacity:0");
    }
}

function flipContainerShow() {
    var e = document.querySelectorAll('[class*="frame-type-gallery"]')[0];
    if (e) {
        e.setAttribute("style","opacity:1");
    }
}

function flipContainerUpdate(){
    flipContainerShow();
}

function flipContainerCheck(){
    var c = 0;
    var gI = document.querySelectorAll('[class*="frame-type-gallery"] .gallery-item');
    if (gI) {
        for(var i = 0, l = gI.length; i < l; i++) {
            if (gI[i].querySelectorAll('img')[0].clientWidth > 10) c++;
        }
    }
    if (c == gI.length) {
        flipContainerUpdate();
        clearInterval(flipContainerInterval);
    }
    isotopeContainerUpdate();
}


flipContainerHide();
document.addEventListener('DOMContentLoaded', flipContainerHide, false);
window.addEventListener('load', flipContainerSetCheckInterval, false);
window.addEventListener('resize', flipContainerUpdate, false);

function updateBreakpoints(){
    var b = document.querySelectorAll('body')[0],
        t = document.querySelectorAll('#top')[0],
        w = window.innerWidth;
        xs = window.getComputedStyle(document.documentElement).getPropertyValue('--t3j-breakpoint-xs').replace('px',''),
        sm = window.getComputedStyle(document.documentElement).getPropertyValue('--t3j-breakpoint-sm').replace('px',''),
        md = window.getComputedStyle(document.documentElement).getPropertyValue('--t3j-breakpoint-md').replace('px',''),
        lg = window.getComputedStyle(document.documentElement).getPropertyValue('--t3j-breakpoint-lg').replace('px',''),
        xl = window.getComputedStyle(document.documentElement).getPropertyValue('--t3j-breakpoint-xl').replace('px',''),
        m = 1024;

    if (t) { m = window.getComputedStyle(t).getPropertyValue('max-width').replace('px','')-0.999; }
    //b.classList.remove('xl-down','lg-down','md-down','sm-down','xs-down','xl-up','lg-up','md-up','sm-up','xs-up','desktop','mobil');
    //alert(w+","+xs+","+sm+","+md+","+lg+","+xl);

    if (w < xs)             {   b.classList.add('xl-down','lg-down','md-down','sm-down','xs-down');                                                                     }
    if (w >= xs && w < sm)  {   b.classList.add('xl-down','lg-down','md-down','sm-down');               b.classList.remove('xs-down');                                  }
    if (w >= sm && w < md)  {   b.classList.add('xl-down','lg-down','md-down');                         b.classList.remove('sm-down','xs-down');                        }
    if (w >= md && w < lg)  {   b.classList.add('xl-down','lg-down');                                   b.classList.remove('md-down','sm-down','xs-down');              }
    if (w >= lg && w < xl)  {   b.classList.add('xl-down');                                             b.classList.remove('lg-down','md-down','sm-down','xs-down');    }
    if (w >= xl)            {   b.classList.remove('xl-down','lg-down','md-down','sm-down','xs-down');                                                                  }


    if (w < sm && w >= xs)  {   b.classList.add('xs-up');                                               b.classList.remove('xl-up','lg-up','md-up','sm-up');            }
    if (w < md && w >= sm)  {   b.classList.add('xs-up','sm-up');                                       b.classList.remove('xl-up','lg-up','md-up');                    }
    if (w < lg && w >= md)  {   b.classList.add('xs-up','sm-up','md-up');                               b.classList.remove('xl-up','lg-up');                            }
    if (w < xl && w >= lg)  {   b.classList.add('xs-up','sm-up','md-up','lg-up');                       b.classList.remove('xl-up');                                    }
    if (w >= xl)            {   b.classList.add('xs-up','sm-up','md-up','lg-up','xl-up');                                                                               }

    if (w > m)              {   b.classList.add('desktop'); b.classList.remove('mobile');   } else {    b.classList.add('mobile'); b.classList.remove('desktop');   }
}


function updateLoaded(){
    var b = document.querySelectorAll('body')[0];
    b.classList.add('loaded');
}

function updateDomLoaded(){
    var b = document.querySelectorAll('body')[0];
    b.classList.add('domloaded');
}



document.addEventListener('DOMContentLoaded', updateDomLoaded, false);
window.addEventListener('resize', updateBreakpoints, false);
window.addEventListener('load', updateLoaded, false);
window.addEventListener('load', updateBreakpoints, false);
updateBreakpoints();

console.log("WE LOVE T3JET");


function updateHashes(){
    var a = document.querySelectorAll('a');
    for(var i = 0, l = a.length; i < l; i++) {
      var e = a[i];
      e.innerHTML = e.innerHTML.replace('pixel<!-- hashcode 698794sdf23546 begin --><img scr="../Icons/typo3-clear-gif.gif"><!-- hashcode 698794sdf23546 end -->werk', '<!-- hashcode 698794sdf23546 begin --><img scr="../Icons/typo3-clear-gif.gif">@<!-- hashcode 698794sdf23546 end -->');
      e.href = e.href.replace('[@]', '@');
      e.href = e.href.replace('mail:', 'mailto:');
    }
}

document.addEventListener('DOMContentLoaded', updateHashes, false);

function updateFooter(){
    var b = document.querySelectorAll('body')[0];
    if (document.documentElement.scrollHeight >= window.innerHeight+1) {
        b.classList.remove('fixed-footer');
        b.classList.add('relative-footer');
    } else {
        b.classList.add('fixed-footer');
        b.classList.remove('relative-footer');
    }
}


document.addEventListener('DOMContentLoaded', updateFooter, false);
window.addEventListener('resize', updateFooter, false);

window.onload = function(){ setTimeout(function(){ updateFooter(); }, 500); };

function initInverted(){

    var b = document.querySelectorAll('.layout-99')[0],
        n = document.querySelectorAll('.navbar')[0],
        f = document.querySelectorAll('.navbar-fixed-bottom')[0];

    if (b) {
        b.classList.add('layout-inverse');
        b.classList.remove('layout-99');
    }

    if (n) {
        if (b) {
            n.classList.add('navbar-inverse');
        }
    }

    if (f) {
        if (b) {
            f.classList.remove('navbar-default');
            f.classList.add('navbar-default-transition');
        } else {
            f.classList.remove('navbar-default-transition');
            f.classList.add('navbar-default');
        }
    }
}

document.addEventListener('DOMContentLoaded', initInverted, false);

function iOS() {
    return typeof navigator.standalone === 'boolean';
}

function updateOS(){
    if (iOS()) {
        var b = document.querySelectorAll('body')[0];
        b.classList.add('ios');
    }
}



document.addEventListener('DOMContentLoaded', updateOS, false);

function mixinContentTransitionInit() {
    var h = document.querySelector('#page-header'),
        s = document.querySelectorAll('.section-default')[0],
        c = document.querySelectorAll('.carousel')[0],
        b = document.querySelectorAll('.body-bg')[0],
        t = false;

    if (s) {
        if (c) {
            if (c.parentNode.id == 'page-content') {
                t = true;
            }
        }
    }

    if (t) {
        if (h) {
            h.classList.add('navbar-default-transition');
            h.classList.remove('navbar-default');
        }
        if (b) {
            b.classList.add('body-bg-transition');
        }
    } else {
        if (h) {
            h.classList.remove('navbar-default-transition');
            h.classList.add('navbar-default');
        }
        if (b) {
            b.classList.remove('body-bg-transition');
            b.classList.add('body-bg-top');
        }
    }
}

function mixinContentTransitionUpdate() {
    var s = document.querySelectorAll(".navbar-fixed-top")[0];
    if (s) {
        if (150 < window.scrollY && document.body.classList.contains('desktop')) {
            var d = document.querySelectorAll(".navbar-inverse-transition")[0];
            if (d) {
                d.classList.remove('navbar-inverse-transition');
                d.classList.add('navbar-default-transition');
            }
        } else {
            var d = document.querySelectorAll(".navbar-default-transition")[0];
            if (d) {
                d.classList.remove('navbar-default-transition');
                d.classList.add('navbar-inverse-transition');
            }
        }
    }
}



document.addEventListener('DOMContentLoaded', mixinContentTransitionInit, false);
window.addEventListener("load", mixinContentTransitionInit, false);

document.addEventListener('DOMContentLoaded', mixinContentTransitionUpdate, false);
window.addEventListener('resize', mixinContentTransitionUpdate, false);
window.addEventListener('scroll', mixinContentTransitionUpdate, false);

function isotopeContainerUpdate(){

};

var modalContainerInterval = null;

function modalContainerSetCheckInterval(timeout) {
    modalContainerInterval = setInterval("modalContainerHide()",timeout);
}

function modalContainerInit() {
    if (document.querySelectorAll('.modal-container')[0]) {
        modalContainerShow();
        if (document.querySelectorAll('.modal-container.autoclose-time-03')[0]) { modalContainerSetCheckInterval(3000); }
        if (document.querySelectorAll('.modal-container.autoclose-time-05')[0]) { modalContainerSetCheckInterval(5000); }
        if (document.querySelectorAll('.modal-container.autoclose-time-10')[0]) { modalContainerSetCheckInterval(10000); }
        if (document.querySelectorAll('.modal-container.autoclose-time-15')[0]) { modalContainerSetCheckInterval(15000); }
        if (document.querySelectorAll('.modal-container.autoclose-time-20')[0]) { modalContainerSetCheckInterval(20000); }
        if (document.querySelectorAll('.modal-container.autoclose-time-25')[0]) { modalContainerSetCheckInterval(25000); }
        if (document.querySelectorAll('.modal-container.autoclose-time-30')[0]) { modalContainerSetCheckInterval(30000); }
        if (document.querySelectorAll('.modal-container.autoclose-time-60')[0]) { modalContainerSetCheckInterval(60000); }
        if (document.querySelectorAll('.modal-container.autoclose-time-120')[0]) { modalContainerSetCheckInterval(120000); }
        document.querySelectorAll('.modal-container .btn-close')[0].onclick = function() { modalContainerHide() };
    }
}

function modalContainerHide() {
    if (document.querySelectorAll('.modal-container')[0]) {
        document.querySelectorAll('.modal-container')[0].classList.remove("show");
        modalContainerInterval = setInterval("modalContainerDisable()",1500);
    }
}

function modalContainerShow() {
    if (document.querySelectorAll('.modal-container')[0]) {
        document.querySelectorAll('.modal-container')[0].classList.add("show");
    }
}

function modalContainerDisable() {
    if (document.querySelectorAll('.modal-container')[0]) {
        document.querySelectorAll('.modal-container')[0].setAttribute("style","display:none");
        clearInterval(modalContainerInterval);
    }
}

document.addEventListener('DOMContentLoaded', modalContainerInit, false);

function carouselContainerInit(max) {
    let w = document.querySelectorAll('.carousel-c'+max);
    if (w) {
        w.forEach((cc) => {
            let c = cc.querySelectorAll('.carousel-item');
            if (c) {
                c.forEach((e) => {
                    e.classList.add("show");
                    let next = e.nextElementSibling;
                    for (var i=1; i<max; i++) {
                        if (!next) {
                            next = c[0];
                        }
                        let cloneChild = next.cloneNode(true);
                        e.appendChild(cloneChild.children[0]);
                        next = next.nextElementSibling;
                    }
                })
            }
        })
    }
}



document.addEventListener('DOMContentLoaded', carouselContainerInit(2), false);
document.addEventListener('DOMContentLoaded', carouselContainerInit(3), false);
document.addEventListener('DOMContentLoaded', carouselContainerInit(4), false);
