// videojs.log.level('error');
// dashjs.logLevel = dashjs.LOG_LEVEL_ERROR;
var stickySidebar = undefined;

$( document ).ready(function() {
    $('body.no-js').removeClass('no-js');

    /**
     * Handling Scroll 
     */
    var scrollOffset;

    function setScrollOffset(){
        scrollOffset = 0;

        if( ! $('#header').is(":hidden") && $('#header').css('position') == 'sticky'){
            scrollOffset = $('#header').height();
        }
        if ($(window).width() <= 425) {
            if($('#header nav.fixed-top').height() &&  ! $('#header nav.fixed-top').is(":hidden") && $('#header nav.fixed-top').css('position') == 'sticky'){
                scrollOffset = $('#header nav.fixed-top').height();
            }
        }

        $('.sticky-top').each(function(){
            $(this).css({'position': 'sticky'});
            var dataRef = $(this).data('sticky-ref');
            if(dataRef){
                var stickyParents = dataRef.split(' ');
                var stickyOffsetEle;
                var zIndex = 1000;
                for (var i = 0; i < stickyParents.length; i++) {
                    var stickyParent = $(stickyParents[i]);
                    if( ! stickyParent.is(":hidden") && stickyParent.css('position') == 'sticky'){
                        if( ! stickyOffsetEle || stickyOffsetEle.height() < stickyParent.height()){
                            stickyOffsetEle = stickyParent;
                            var zIndexParent = stickyParent.css('z-index');
                            if(zIndex >= zIndexParent){
                                zIndex = zIndexParent - 1;
                            }
                        }
                    }
                }
                $(this).css({'top': (parseInt(stickyOffsetEle.css('top'), 10) + stickyOffsetEle.height()) + 'px'});
                $(this).css('z-index', zIndex);
            }else{
                $(this).css({'top': scrollOffset + 'px'});
            }
        });

        //$('.sticky-scroll').css('max-height',  'calc(100vh - ' + scrollOffset + 'px)');
        // https://github.com/abouolia/sticky-sidebar
        if($('.sticky-scroll').length && $('.sticky-scroll-inner').length){
            if(stickySidebar && stickySidebar != undefined){
                stickySidebar.destroy();
            }
            stickySidebar = new StickySidebar('.sticky-scroll', {
                topSpacing: scrollOffset,
                innerWrapperSelector: '.sticky-scroll-inner'
            });
        }
    };
    setScrollOffset();
    $(window).on('resize', setScrollOffset);


    function scrollToAnchor(anchor, event){
        var target = $(anchor);
        target = target.length ? target : $('[name=' + anchor.slice(1) + ']');
        if (target.length) {
            if(event){
                event.preventDefault();
            }
            $('html, body').animate({
                scrollTop: target.offset().top - scrollOffset
            }, 1000, function(){});
        }
    }


    var breakPointSelector = '#scroll-breakpoint-dyn-title';
    if($(breakPointSelector).length > 0){
        var breakpoint = $(breakPointSelector);
        $(document).on('scroll', function () {
            var offset = 80;
            var scrollTopPosition = $(document).scrollTop();
            // var impressionSliderScrollHeight = $(impressionSlider).position().top + $(impressionSlider).height();
            var impressionSliderScrollHeight = $(breakpoint).offset().top + $(breakpoint).outerHeight();
            if(scrollTopPosition > impressionSliderScrollHeight + offset){
                $("#headlineSiteScrollInfo").show();
                $("#scroll-dyn-logo").addClass('small-logo');
            }else{
                $("#headlineSiteScrollInfo").hide();
                $("#scroll-dyn-logo").removeClass('small-logo');
            }
        });
    }

    $('#jumpToTop').on('click', function(){
        window.scrollTo(0, 0);
    });
    $(document).scroll(function() {
        var y = $(this).scrollTop();
        if (y > 800) {
            $('#jumpToTop').fadeIn();
        } else {
            $('#jumpToTop').fadeOut();
        }
    });
    $('#livezilla_wm').on('change', function(){
        // if($('#lz_overlay_chat').css('display') == 'block'){
        //     $(this).css('top', '110px');
        // }else{
        //     $(this).css('top', '110px');
        // }
    });


    /**
     * Swiper Configuration
     * @see https://swiperjs.com/demos
     *
     * Selector:
     * .swiper-container
     * .large-swiper-container
     *
     * .nav-swiper-container = For the detailpage navigation element sliding
     */
    new Swiper('.media-swiper', {
        pagination: {
            el: '.swiper-pagination',
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        loop: true,
        dynamicBullets: false,
        cssMode: false,
    });

    // Deprecated: - Uses Responsive-Swiper
    new Swiper('#testimonials-swiper', {
        pagination: {
            el: '.swiper-pagination',
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        loop: true,
        //dynamicBullets: true,
        //cssMode: true,
        slidesPerView: 3,
        spaceBetween: 20,
    });

    new Swiper('.large-swiper-container', {
        slidesPerView: 'auto',
        spaceBetween: 20,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        loop: true,
    });

    var navigationSwiper = new Swiper('.nav-swiper-container', {
        slidesPerView: 'auto',
        spaceBetween: 20,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });
    initNavigationSwiper(navigationSwiper);
    initMobileNavigation(navigationSwiper);

    // E.g. Testimonials
    new Swiper('.responsive-swiper', {
        autoHeight: true, //enable auto height
        centerInsufficientSlides: true,
        // pagination: {
        //     el: '.swiper-pagination',
        //     clickable: true,
        //     type: 'fraction',
        // },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        spaceBetween: 20,
        // responsive
        breakpoints: { // config till width X
            575: { // xs / default/col
                slidesPerView: 1,
            },
            768: { // 768px max window width for sm
                slidesPerView: 2,
            },
            991: { // md
                slidesPerView: 3,
            },
            1349: { // lg
                slidesPerView: 3,
            }
        },
        // default = xl
        slidesPerView: 4
    });

    $('.gallery-swiper').each(function(){
        var swiperParams = {
            autoHeight: false, //enable auto height
            watchOverflow: true,
            // pagination: {
            //     el: '.swiper-pagination',
            //     clickable: true,
            //     type: 'fraction',
            // },
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
            spaceBetween: 20,
            // responsive
            breakpoints: { // config till width X
                575: { // 0 - 575 = xs / default/col
                    slidesPerView: 1,
                },
                768: { // sm
                    slidesPerView: 2,
                },
                991: { // md
                    slidesPerView: 3,
                },
                1349: { // for gallery the lg to xl breaks early at 1200
                    slidesPerView: 3,
                }
            },
            // default = xl
            slidesPerView: 4
        };

        if($(this).data('slides') > 0){
            var countSlides = $(this).data('slides');
            if(countSlides < 4){
                // xl
                swiperParams.slidesPerView = countSlides;
            }
            if(countSlides < 3){
                // lg
                swiperParams.breakpoints[1349].slidesPerView = countSlides;
            }
            if(countSlides < 2){
                // lg
                swiperParams.breakpoints[991].slidesPerView = countSlides;
            }
            // 1 image only fallsback to an image component instead this gallery swiper
        }

        if($(this).data('max') > 0){
            var slidesMax = $(this).data('max');
            if(slidesMax < swiperParams.slidesPerView){
                // xl
                swiperParams.slidesPerView = slidesMax;
            }
            if(slidesMax < swiperParams.breakpoints[1349].slidesPerView){
                // lg
                swiperParams.breakpoints[1349].slidesPerView = slidesMax;
            }
            if(slidesMax < swiperParams.breakpoints[991].slidesPerView){
                // lg
                swiperParams.breakpoints[991].slidesPerView = slidesMax;
            }
            // 1 image only fallsback to an image component instead this gallery swiper
        }

        var gallerySwiper = new Swiper($(this), swiperParams);
    });

    $('.lightbox-gallery').each(function() { // the containers for all your galleries
        var videoObj;
        $(this).magnificPopup({
            delegate: 'a.lightbox-popup', // the selector for gallery item
            type: 'inline',
            preloader: true,
            gallery: {
                enabled: true,
                preload: 0,
                tCounter: '%curr% von %total%'
            },
            showCloseBtn: true,
            closeBtnInside: true,
            closeOnBgClick: true,
            fixedContentPos: false,
            callbacks: {
              open: function() {
                jQuery('body').addClass('noscroll');
                var firstPopup = $(this.content).find('video')[0];
                $('video').each(function(){
                    if(!$(this)[0].paused && firstPopup !== $(this)[0]){
                        $(this)[0].pause();
                    }
                });
              },
              close: function() {
                jQuery('body').removeClass('noscroll');
                $('video').each(function(){
                    $(this)[0].pause();
                    if($(this).hasClass('mfp-video')){
                        $(this)[0].currentTime = 0; // stop videos in gallery popups
                    }
                });
              },
              change: function() {
                if(videoObj && videoObj != undefined){
                    // pause prev video
                    videoObj.pause();
                    videoObj = undefined;
                }
                if($(this.content).find('video').length > 0){

                    if($(this.content).find('video.notLoaded').length > 0){
                        var video = $(this.content).find('video.notLoaded');
                        var source = $(video).find('source');
                        var src = $(source).data('init-src');
                        $(source).attr('src', src);
                        $(video).removeClass('notLoaded');
                        $(video)[0].load();
                    }
                    // play current video
                    videoObj = $(this.content).find('video')[0];
                    videoObj.play();
                }else if($(this.content).find('iframe.notLoaded').length > 0){
                    var iframe = $(this.content).find('iframe.notLoaded');
                    var src = $(iframe).data('init-src');
                    $(iframe).attr('src', src);
                    $(iframe).removeClass('notLoaded');
                }
              }
            }
        });
    });

    /**
     * Anchor navigation
     */
    $('a[href*="#subsection-"]').addClass('nav-link-smooth');

    $('a[href*="#"]')
    .not('[href="#"]')
    .not('[href="#0"]')
    .not('[target="_blank"]')
    .click(function(event) {
        // On-page links
        if($(this).hasClass('nav-link-smooth')){
            if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
                scrollToAnchor(this.hash, event);
            }
        }
    });
});

$( document ).ready(function() {

    /**
     * Content accordions arrow or plus/minus icon switch
     */
    $('.accordion').on('show.bs.collapse', function(e) {
        var target = $( "." + e.target.id );
        if($(target).hasClass( "fa-chevron-down" )){
            $(target).addClass('fa-chevron-up').removeClass('fa-chevron-down');
        }else if($(target).hasClass( "plus-icon" )){
            $(target).addClass('minus-icon').removeClass('plus-icon');
        }
    }).on('hidden.bs.collapse', function(e) {
        var target = $( "." + e.target.id );
        if($(target).hasClass( "fa-chevron-up" )){
            $(target).addClass('fa-chevron-down').removeClass('fa-chevron-up');
        }else if($(target).hasClass( "minus-icon" )){
            $("." + e.target.id).addClass('plus-icon').removeClass('minus-icon');
        }
    });

    $('#filterbutton').click(function(){
        if ($(".kategoriebaumaccordion").hasClass("opened")) {
            $(".kategoriebaumaccordion").removeClass('opened');
            $("#filterbuttonshowtext").show();
            $("#filterbuttonhidetext").hide();
        }
        else{
            $(".kategoriebaumaccordion").addClass('opened');
            $("#filterbuttonshowtext").hide();
            $("#filterbuttonhidetext").show();
        }
    });
});

$(document).ready(function() {

    /* ============================================ */
    // Fix navbar-anchor-offset for "Open anchor link in new window"
    if (location.hash){        
        var space = $('#header').height();
        if ($(window).width() <= 425) {
            space = $('#header nav.fixed-top').height();
        }
        scrollBy(0, -space);
    } 

    /* ============================================ */


    if($('.kategoriebaumaccordion').length <= 0){
        return;
    }

    var showCounter = 0;
    var filterState = {};
    var filterDefaultStates = {};
    $('.GetInputCheckbox.defaultChecked').each(function(){
        var selectionValue = $(this).data('value');
        var selectionGroupId = $(this).data('id');
        filterDefaultStates[selectionGroupId] = [];
        if(!filterDefaultStates[selectionGroupId].includes(selectionValue)) filterDefaultStates[selectionGroupId].push(selectionValue);
    });
    loadFromUri();
    setFilterStates();
    ShowHideElements();
    window.dispatchEvent(new Event('resize')); // Fixes reload on mid scroll position

    var delay = 500; // Will do the ajax stuff after 1000 ms, or 1 s
    var delayTimer;
    $('#searchinput').on('input',function(e){
        clearTimeout(delayTimer);
        var searchText = $(this).val();
        delayTimer = setTimeout(function() {
            $('#searchinputmobile').val(searchText);
            ShowHideElements();
        }, delay);
    });
    $('#searchinputmobile').on('input',function(e){
        clearTimeout(delayTimer);
        var searchText = $(this).val();
        delayTimer = setTimeout(function() {
            $('#searchinput').val(searchText);
            ShowHideElements();
        }, delay); 
    });

    $('.kategoriebaumaccordion .GetInputCheckbox').on('input',function(e){
        var selectionValue = $(this).data('value');
        var selectionGroupId = $(this).data('id');

        if($(this).attr('id').startsWith('sidebar-filter-')){
            var mainFilter = $('.kategoriebaumaccordion .GetInputCheckbox#'+ $.escapeSelector('filter-' + selectionGroupId + '-' + selectionValue));
            $(mainFilter).prop('checked', $(this).prop('checked'));
            $(mainFilter).trigger('input');
        }else{
            var sidebarFilter = $('.kategoriebaumaccordion .GetInputCheckbox#'+$.escapeSelector('sidebar-filter-' + selectionGroupId + '-' + selectionValue));
            $(sidebarFilter).prop('checked', $(this).prop('checked'));
            setFilterStates(selectionGroupId);
            ShowHideElements();
        }
    });

    $('.resetfilter').click(function(){
        $('.GetInputCheckbox').each(function(){
            $(this).prop('checked', false);
        });
        $('.GetInputCheckbox.defaultChecked').each(function(){
            $(this).prop('checked', true);
        });
        $('#searchinput').val("");
        $('#searchinputmobile').val("");
        setFilterStates();
        ShowHideElements();
    });

    function setFilterStates(selectionGroupId){
        if (selectionGroupId === undefined) {
            filterState = {};
            $('.GetInputCheckbox:checked').each(function(i, that) {
                var selectionValue = $(that).data('value');
                var selectionGroupId = $(that).data('id');
                if(!(selectionGroupId in filterState)) filterState[selectionGroupId] = [];
                if(!filterState[selectionGroupId].includes(selectionValue)) filterState[selectionGroupId].push(selectionValue);
            });
        }else{
            filterState[selectionGroupId] = [];
            $('.GetInputCheckbox[data-id=' + selectionGroupId +']:checked').each(function(i, that) {
                var selectionValue = $(that).data('value');
                var selectionGroupId = $(that).data('id');
                if(!filterState[selectionGroupId].includes(selectionValue)) filterState[selectionGroupId].push(selectionValue);
            });
        }
        if(! filterState || isEqual(filterState, filterDefaultStates)) {
            $('.filter-notification').removeClass('active');
        }else{
            $('.filter-notification').addClass('active');
        }
    }

    function filter2Str(filterState){
        var str = '';
        for(var selectionGroupId in filterState){
            if((selectionGroupId == 'pedagogy_studies' && filterState[selectionGroupId] == 'none') || ! filterState[selectionGroupId] || ! filterState[selectionGroupId].length){
                //default value
                continue;
            }

            if(str){
                str += '&';
            }
            str += 'filter['+selectionGroupId+']='+encodeURIComponent(filterState[selectionGroupId]);
        }
        return str;
    }

    function storeInUri(searchTerms){ // + global filterState
        var hash = '';

        if(searchTerms && searchTerms.length > 0 && searchTerms[0] != ''){
            searchTerms = searchTerms.map( x => x.toLowerCase());
            //URIHash.set('search', searchTerms.join(","));
            hash = 'search=' + encodeURIComponent(searchTerms);
        }
        
        if(filterState && !isEqual(filterState, filterDefaultStates)) {
            var filterHash = filter2Str(filterState);
            if(filterHash){
                if(hash){
                    hash += '&';
                }
                hash = hash + filterHash;
            }
        }

        $(location).prop('hash', hash? hash : '!');
        //history.pushState({hash: hash}, document.title, location.pathname + '?' + hash);
        // history.replaceState(location.pathname + '?' + hash, document.title, location.pathname + '?' + hash);
        // window.onpopstate = function (event) {
        //     if (event.state != null){
        //         document.url = event.state.url;
        //         loadFromUri();
        //     }
        // };
        
        // delayTimer = setTimeout(function() {
        //     var stateObj = { hash: hash };
        //     history.pushState(stateObj, "seite 2", "bar.html");
        // }, 1000);

        if(window.sessionStorage){
            if(hash){
                window.sessionStorage.setItem('hash',hash);
            }else{
                window.sessionStorage.removeItem('hash');
            }
        }
    }

    function loadFromUri(){
        var hash = $(location).prop('hash').substr(1);

        if(!hash){
            if(window.sessionStorage){
                hash = window.sessionStorage.getItem('hash');
            }
        }

        var hash = decodeURIComponent(hash);
        hash = hash.split('&');
        for(var i=0; i < hash.length; i++){
            if(!hash[i]){
                continue;
            }

            keyValue = hash[i].split('=');
            key = keyValue[0];
            value = keyValue[1];

            if(!value){
                continue;
            }

            if(key == 'search'){
                $('#searchinput').val(value);
                $('#searchinputmobile').val(value);
            }else{
                var matches;
                if(matches = key.match(/^filter\[(.*)\]$/)){
                    var selectionGroupId = matches[1];
                    var filterValues = value.split(',');
                    if(!(selectionGroupId in filterState) || selectionGroupId == 'pedagogy_studies') filterState[selectionGroupId] = [];
                    for(var j=0; j < filterValues.length; j++){
                        filterState[selectionGroupId].push(filterValues[j]);
                        $('.GetInputCheckbox[data-value="'+$.escapeSelector(filterValues[j])+'"][data-id="'+selectionGroupId+'"]').each(function(){
                            $(this).prop('checked', true);
                        });
                        $('#filter-collapse-'+$.escapeSelector(selectionGroupId)).collapse("show");
                    }
                }
            }
        }
    }

    function ShowHideElements(){
        var inputVal = $('#searchinput').val().toUpperCase().trim();
        var searchTerms = inputVal.split(/[ ,]+/);

        var listElements = $('.listelement');
        $(listElements).show();
        showCounter = $(listElements).length;

        $(listElements).each(function() {
            if(inputVal != ""){
                var hide = true;
                for(var termId in searchTerms){
                    if($(this).find('.search-data:first').text().toUpperCase().indexOf(searchTerms[termId]) >= 0){
                        hide = false;
                        break;
                    }
                }
                if(hide){
                    $(this).hide();
                    showCounter--;
                    return;
                }
            }

            for(var selectionGroupId in filterState){
                var filteredByGroup = true;
                var listItemData = $(this).data(selectionGroupId);
                if(filterState[selectionGroupId].length){
                    for(var i in filterState[selectionGroupId]){
                        var selectionValue = filterState[selectionGroupId][i];
                        if($.isArray(listItemData) && (
                                $.inArray(selectionValue, listItemData) !== -1 ||
                                $.inArray(parseInt(selectionValue, 10), listItemData) !== -1 ||
                                $.inArray(String(selectionValue), listItemData) !== -1
                            ) || listItemData == selectionValue){
                            filteredByGroup = false;
                            break;
                        }
                    }
                }else{
                    // Empty group filter = Nothing to filter out
                    filteredByGroup = false;
                }

                if(filteredByGroup){
                    $(this).hide();
                    showCounter--;
                    return;
                }
            }
        });

        $('#filterCounter').text(showCounter / 2);
        if(showCounter > 0){
            $('#emptySearch').hide();
        }else{
            $('#emptySearch').show();
        }

        if(stickySidebar){
            stickySidebar.updateSticky();

            // Bugfix for auto adjusting sticky bar - Needs scroll events
            // Dispatching is not enough
            var scrollBefore = $(document).scrollTop();
            $(document).scrollTop($(document).scrollTop() + 1);
            setTimeout(function(){
                $(document).scrollTop($(document).scrollTop() - 1);
                var scrollAfter = $(document).scrollTop();
                if(scrollBefore != scrollAfter){
                    //Was end of scroll, rollback -1
                    setTimeout(function(){
                        $(document).scrollTop($(document).scrollTop() + 1);
                    }, 2);
                }
            }, 2);
        }

        storeInUri(searchTerms);
    }


    //sidebar / filter
    $('#dismiss, .overlay').on('click', function () {
        // hide sidebar
        $('#sidebar').removeClass('active');
        // hide overlay
        $('.overlay').removeClass('active');
        //$("body").css({'overflow': 'initial'});
        $("body").removeClass('scroll-blocked');
    });

    $('#sidebarCollapse').on('click', function () {
        var space = $('#header').height();
        if ($(window).width() <= 425) {
            if($('#header nav.fixed-top').height()){
                space = $('#header nav.fixed-top').height();
            }
        }
        //$("#sidebar").css({'top': space + 'px'});
        //$("body").css({'overflow': 'hidden'});
        $("body").addClass('scroll-blocked');

        // open sidebar
        $('#sidebar').addClass('active');
        // fade in the overlay
        $('.overlay').addClass('active');
        $('.collapse.in').toggleClass('in');
        $('a[aria-expanded=true]').attr('aria-expanded', 'false');
    });




    // var containerDiff = ($('div.tab-pane#details').height() - $('div.tab-pane#liste').height()) / 2; //($('.listelement').length / 2);

    // /* Jump scroll on details / list switch to stay on the same list items */
    // $('a[data-toggle="tab"][href="#details"]').on('click', function () {
    //     console.log("Scroll "+containerDiff);
    //     console.log($('html, body').scrollTop());
    //     // window.scrollBy(containerDiff, 0);
    //     $('html, body').animate({
    //         scrollTop: $('html, body').scrollTop() + containerDiff
    //     }, 1000, function(){});
    // });
    // $('a[data-toggle="tab"][href="#liste"]').on('click', function () {
    //     // window.scrollBy(containerDiff, 0);
    //     $('html, body').animate({
    //         scrollTop: $('html, body').scrollTop() - containerDiff
    //     }, 1000, function(){});
    // });
});

function initNavigationSwiper(navigationSwiper){
    if($('nav#Navbar ul li a.nav-link-smooth').length <= 0){
        return;
    }

    var offset = $('#header').height() + 80;
    var navigationMainLinks = $("nav#Navbar ul li a.nav-link-smooth[class*='scroll-navigation-']");
    var sectionIds = [];

    $(navigationMainLinks).each(function () {
        var jumpId = $(this).attr('href');
        if($.inArray(jumpId, sectionIds) === -1){
            sectionIds.push($(this).attr('href'));
        }
    });

    setTimeout(selectCurrentNav, 1000);
    $(document).on('scroll', function () {
        selectCurrentNav();
    });

    function selectCurrentNav(){
        var allNavigationLinks = $("nav#Navbar a.nav-link-smooth[class*='scroll-navigation-']");
        $(allNavigationLinks).removeClass('currentArea');

        var scrollTopPosition = $(this).scrollTop();
        // Iterate backwards to get the first lowest section on scroll-position greater
        for (var i = sectionIds.length - 1; i >= 0; i--){
            var sectionId = sectionIds[i];
            if(scrollTopPosition >= $(sectionId).position().top - offset){
                navigationSwiper.slideTo(i);
                $('a.nav-link-smooth[class*=\'scroll-navigation-\'][href=\''+sectionId+'\']').addClass('currentArea');
                return sectionId;
            }
        }
    }
}

function initMobileNavigation(navigationSwiper){
    // var $navbar = $("#Navbar");

    // if($navbar.find('.nav-swiper-container').length){
    //     var stickTrigger = $navbar.position().top; //$('#header').height() -50;
    //     if ($(window).width() <= 425) {
    //         stickyNavbar();
    //     }
    //     $(window).scroll(function() {
    //         if ($(window).width() <= 425) {
    //             stickyNavbar();
    //         }
    //     });
    //     $(window).resize(function() {
    //         navigationSwiper.update();
    //         if ($(window).width() <= 425) {
    //             stickyNavbar();
    //         }else{
    //             $navbar.removeClass("fixed-top");
    //         }
    //     });
    // }

    // function stickyNavbar(){
    //     if ($(window).scrollTop() > stickTrigger) {
    //         if (!$navbar.hasClass("fixed-top")) {
    //             $navbar.addClass("fixed-top");
    //         }
    //     } else {
    //         $navbar.removeClass("fixed-top");
    //     }
    // }

    $('[data-toggle="tooltip"]').tooltip({
        //trigger: 'focus manual',
        delay: { "show": 100, "hide": 500 }
    });

    $('.nav-tabs a:first').tab('show');
}

/**
 * play / pause toggle audio elements
 * @param e Id-Selector
 */
function play(e) {
    var de = document.getElementById(e);
    if (de.paused) {
        de.play();
        de.onended = function() {
            if (document.getElementById(e+1)) {
                play(e+1);
            } else {
                play(1);
            }
        }
    } else {
        de.pause();
    }
}


/**
 * Check equalize of two arrays with same key values
 */
function isEqual (value, other) {

	// Get the value type
	var type = Object.prototype.toString.call(value);

	// If the two objects are not the same type, return false
	if (type !== Object.prototype.toString.call(other)) return false;

	// If items are not an object or array, return false
	if (['[object Array]', '[object Object]'].indexOf(type) < 0) return false;

	// Compare the length of the length of the two items
	var valueLen = type === '[object Array]' ? value.length : Object.keys(value).length;
	var otherLen = type === '[object Array]' ? other.length : Object.keys(other).length;
	if (valueLen !== otherLen) return false;

	// Compare two items
	var compare = function (item1, item2) {

		// Get the object type
		var itemType = Object.prototype.toString.call(item1);

		// If an object or array, compare recursively
		if (['[object Array]', '[object Object]'].indexOf(itemType) >= 0) {
			if (!isEqual(item1, item2)) return false;
		}

		// Otherwise, do a simple comparison
		else {

			// If the two items are not the same type, return false
			if (itemType !== Object.prototype.toString.call(item2)) return false;

			// Else if it's a function, convert to a string and compare
			// Otherwise, just compare
			if (itemType === '[object Function]') {
				if (item1.toString() !== item2.toString()) return false;
			} else {
				if (item1 !== item2) return false;
			}

		}
	};

	// Compare properties
	if (type === '[object Array]') {
		for (var i = 0; i < valueLen; i++) {
			if (compare(value[i], other[i]) === false) return false;
		}
	} else {
		for (var key in value) {
			if (value.hasOwnProperty(key)) {
				if (compare(value[key], other[key]) === false) return false;
			}
		}
	}

	// If nothing failed, return true
	return true;
};