jQuery( document ).ready(function() {
    let owl = jQuery("#allaowl")

    jQuery( ".collection-year" ).click(function() {
        let collectionId = jQuery(this).data('id');

        // update info
        jQuery('#collection_title').html(jQuery(this).data('title'));

        let syear = jQuery(this).data('year');
        if(syear.toString().length > 0) {
            jQuery('#collection_year_wrap').removeClass('hidethis');
        } else  {
            jQuery('#collection_year_wrap').addClass('hidethis');
        }
        jQuery('#collection_year').html(syear);

        let smedium = jQuery(this).data('medium');
        if(smedium.toString().length > 0) {
            jQuery('#collection_medium_wrap').removeClass('hidethis');
        } else  {
            jQuery('#collection_medium_wrap').addClass('hidethis');
        }
        jQuery('#collection_medium').html(smedium);

        let sprice = jQuery(this).data('prix');
        if(sprice.toString().length > 0) {
            jQuery('#collection_prix_wrap').removeClass('hidethis');
            jQuery('#infocollection_one').addClass('right-vertical-line');
        } else  {
            jQuery('#collection_prix_wrap').addClass('hidethis');
            jQuery('#infocollection_one').removeClass('right-vertical-line');
        }
        jQuery('#collection_prix').html(sprice);
        jQuery('#collection_content').html(jQuery(this).data('content'));

        jQuery( ".collection-carousel" ).each(function() {
            jQuery( this ).addClass( "hidethis" );
        });
        jQuery('#mobil_collection_carousel_'+collectionId).removeClass('hidethis');
        jQuery('#collection_carousel_'+collectionId).removeClass('hidethis');

        jQuery( ".collection-year" ).each(function() {
            jQuery( this ).removeClass( "activ" );
        });
        jQuery(this).addClass('activ');
    });

    jQuery( ".laa .onea" ).hover(function() {
        jQuery( ".laa .onea" ).each(function() {
            jQuery( this ).removeClass( "activ" );
        });
        jQuery(this).addClass('activ');

        let legende = jQuery(this).data('legende');
        jQuery('#legende').html(legende);

        let description = jQuery(this).data('description');
        jQuery('#description').html(description);

        let imgSrc = jQuery(this).data('img');
        jQuery('#aimg').attr('href', jQuery(this).data('link'));
        jQuery('#aimg img').fadeOut(200).queue(function() {
            let img = jQuery(this);
            img.attr('src', imgSrc);
            img.fadeIn(200);
            img.dequeue();
        });

        if(jQuery('.mobimgs').is(':visible')) {
            if(owl) {
                owl.trigger('to.owl.carousel', jQuery(this).data('slidi'));
                owl.trigger('stop.owl.autoplay');

                let aid = jQuery('.owl-item.active .item').data('aid');

                jQuery( ".laa .onea" ).each(function() {
                    jQuery( this ).removeClass( "activ" );
                });
                jQuery("#aid"+aid).addClass('activ');
            }
        }
    });

    if(owl) {
        owl.on('changed.owl.carousel', function (e) {
            setTimeout(function(){
                let aid = jQuery('.owl-item.active .item').data('aid');

                jQuery( ".laa .onea" ).each(function() {
                    jQuery( this ).removeClass( "activ" );
                });
                jQuery("#aid"+aid).addClass('activ');
            }, 205);
        })
    }
});

jQuery('.owl-carousel').owlCarousel({
    loop:true,
    nav:true,
    navText: ['<div class="owlnav owll"><svg viewBox="0 0 35 31" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 15H34.5"/><path d="M16 1L1 15L16 30"/></svg></div>','<div class="owlnav owlr"><svg viewBox="0 0 35 31" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 15H34.5"/><path d="M16 1L1 15L16 30"/></svg></div>'],
    dots: false,
    lazyLoad: true,
    autoHeight: true,
    autoplay: false,
    autoplayTimeout: 5000,
    autoplayHoverPause: true,
    responsive:{
        0:{
            items:1
        },
        600:{
            items:1
        },
        1000:{
            items:1
        }
    }
})

jQuery( ".play-btn" ).click(function(e) {
    e.preventDefault();
    let vid = jQuery(this).data('vid')

    jQuery("#videowrapper-"+vid+" .vplayer")[0].src += "?autoplay=1";
    jQuery("#videowrapper-"+vid+" .vplayer").show();
    jQuery("#videowrapper-"+vid+">div").show();
    jQuery("#videowrapper-"+vid+" .video-cover").hide();
    jQuery("#videowrapper-"+vid+" .play-btn").hide();
})

jQuery(document).ready(function() {

    (function ($) {
        $('.tab ul.tabs').addClass('active').find('> li:eq(0)').addClass('current');

        $('.tab ul.tabs li a').click(function (g) {
            var tab = $(this).closest('.tab'),
                index = $(this).closest('li').index();

            tab.find('ul.tabs > li').removeClass('current');
            $(this).closest('li').addClass('current');

            tab.find('.tab_content').find('div.tabs_item').not('div.tabs_item:eq(' + index + ')').slideUp();
            tab.find('.tab_content').find('div.tabs_item:eq(' + index + ')').slideDown();

            g.preventDefault();
        } );
    })(jQuery);

    jQuery(document).ready(function() {
        jQuery(".scroll-bot").click(function(event){
            jQuery('html, body').animate({scrollTop: '+=450px'}, 200);
        });
    });
});
