jQuery(document).ready(function ($) {
    
    // art trail map & grid view toogle
    $('#artgridview').hide();
    $('a[href="#artmapview"]').css({
    'color': 'white',
    'background-color': 'rgb(233 189 94)',
    'font-weight': 'bold',
    'border': '1px solid rgb(233 189 94)'
    });
    $('a[href="#artmapview"]').click(function(){
        $('#artgridview').hide();
        $('#artmapview').show();
        $('a[href="#artmapview"]').css({
    'color': 'white',
    'background-color': 'rgb(233 189 94)',
    'font-weight': 'bold',
    'border': '1px solid rgb(233 189 94)'
    });
    $('a[href="#artgridview"]').css({
        'color': 'black',
        'background-color': 'transparent',
        'font-weight': 'normal',
        'border': '1px solid black'
    });
    });
    $('a[href="#artgridview"]').click(function(){
        $('#artmapview').hide();
        $('#artgridview').show();
        $('a[href="#artgridview"]').css({
        'color': 'white',
        'background-color': 'rgb(233 189 94)',
        'font-weight': 'bold',
        'border': '1px solid rgb(233 189 94)'
    });
        $('a[href="#artmapview"]').css({
        'color': 'black',
        'background-color': 'transparent',
        'font-weight': 'normal',
        'border': '1px solid black'
    });
    });
    // end
    
    $('.match-title').matchHeight();
    var $menuBarIcon = $('.togglemenu');
    $menuBarIcon.on('click', function() {
     $menuBarIcon.hide();
    });
    $(document).on('elementor/popup/hide', function() {
    // Show the menu bar icon
     $menuBarIcon.show();
    });
    
    // home tab section
    $('.match-title').matchHeight();
    
    $('.tab-link-cb li').on('click', function() {
        $('.tab-link-cb li.currenttab').removeClass('currenttab');
        $(this).addClass('currenttab');
    });
    
    /* events navigation */
    
    setTimeout(function() {
    // Handling 'whats-on' swiper
    var prevButton = $('.feature-container .elementor-swiper-button.elementor-swiper-button-prev');
    var nextButton = $('.feature-container .elementor-swiper-button.elementor-swiper-button-next');
    var arrowPoss = $('.elementor-slide-description');

    if (prevButton.length && nextButton.length && arrowPoss.length) {
        arrowPoss.append(prevButton).append(nextButton);

        var swiperWrapper = $('.feature-container .swiper-wrapper');
        var swiperWrapperId = swiperWrapper.attr('id');
        if (!swiperWrapperId) {
            swiperWrapperId = 'swiper-wrapper-' + Math.random().toString(36).substr(2, 9);
            swiperWrapper.attr('id', swiperWrapperId);
        }

        prevButton.attr('aria-label', 'Previous slide').attr('aria-controls', swiperWrapperId);
        nextButton.attr('aria-label', 'Next slide').attr('aria-controls', swiperWrapperId);

        var swiperContainer = $('.feature-container .swiper-wrapper.elementor-slides')[0];
        if (swiperContainer) {
            var swiperInstance = swiperContainer.swiper;
            if (swiperInstance) {
                swiperInstance.params.navigation.prevEl = prevButton[0];
                swiperInstance.params.navigation.nextEl = nextButton[0];
                swiperInstance.navigation.update();
            } else {
                console.log('Swiper instance not found on the .feature-container element.');
            }
        } else {
            console.log('Element with selector .feature-container .elementor-swiper-container not found.');
        }
    } else {
        console.log('Required elements for "feature-container" swiper not found.');
    }

    // Handling 'eat-drink' swiper
    var eatprevButton = $('.eat-drink div.elementor-swiper-button.elementor-swiper-button-prev');
    var eatnextButton = $('.eat-drink .elementor-swiper-button.elementor-swiper-button-next');
    var eatnav = $('.eatnav');

    if (eatprevButton.length && eatnextButton.length && eatnav.length) {
        eatnav.append(eatprevButton).append(eatnextButton);

        var eatswiperWrapper = $('.eat-drink .swiper-wrapper');
        var eatswiperWrapperId = eatswiperWrapper.attr('id');
        if (!eatswiperWrapperId) {
            eatswiperWrapperId = 'swiper-wrapper-' + Math.random().toString(36).substr(2, 9);
            eatswiperWrapper.attr('id', eatswiperWrapperId);
        }

        eatprevButton.attr('aria-label', 'Previous slide').attr('aria-controls', eatswiperWrapperId);
        eatnextButton.attr('aria-label', 'Next slide').attr('aria-controls', eatswiperWrapperId);

        var eatswiperContainer = $('.eat-drink .elementor-swiper-container')[0];
        if (eatswiperContainer) {
            var eatswiperInstance = eatswiperContainer.swiper;
            if (eatswiperInstance) {
                eatswiperInstance.params.navigation.prevEl = eatprevButton[0];
                eatswiperInstance.params.navigation.nextEl = eatnextButton[0];
                eatswiperInstance.navigation.update();
            } else {
                console.log('Swiper instance not found on the .eat-drink element.');
            }
        } else {
            console.log('Element with selector .eat-drink .elementor-swiper-container not found.');
        }
    } else {
        console.log('Required elements for "eat-drink" swiper not found.');
    }

    // Handling 'stay-plays' swiper
    var stayprevButton = $('.stay-plays div.elementor-swiper-button.elementor-swiper-button-prev');
    var staynextButton = $('.stay-plays .elementor-swiper-button.elementor-swiper-button-next');
    var staynav = $('.staynav');

    if (stayprevButton.length && staynextButton.length && staynav.length) {
        staynav.append(stayprevButton).append(staynextButton);

        var staySwiperWrapper = $('.stay-plays .swiper-wrapper');
        var staySwiperWrapperId = staySwiperWrapper.attr('id');
        if (!staySwiperWrapperId) {
            staySwiperWrapperId = 'swiper-wrapper-' + Math.random().toString(36).substr(2, 9);
            staySwiperWrapper.attr('id', staySwiperWrapperId);
        }

        stayprevButton.attr('aria-label', 'Previous slide').attr('aria-controls', staySwiperWrapperId);
        staynextButton.attr('aria-label', 'Next slide').attr('aria-controls', staySwiperWrapperId);

        var stayswiperContainer = $('.stay-plays .elementor-swiper-container')[0];
        if (stayswiperContainer) {
            var stayswiperInstance = stayswiperContainer.swiper;
            if (stayswiperInstance) {
                stayswiperInstance.params.navigation.prevEl = stayprevButton[0];
                stayswiperInstance.params.navigation.nextEl = staynextButton[0];
                stayswiperInstance.navigation.update();
            } else {
                console.log('Swiper instance not found on the .stay-plays element.');
            }
        } else {
            console.log('Element with selector .stay-plays .elementor-swiper-container not found.');
        }
    } else {
        console.log('Required elements for "stay-plays" swiper not found.');
    }

    // Handling 'develop-update' swiper
    var blogprevButton = $('.develop-update div.elementor-swiper-button.elementor-swiper-button-prev');
    var blognextButton = $('.develop-update .elementor-swiper-button.elementor-swiper-button-next');
    var blognav = $('.blog-nav');

    if (blogprevButton.length && blognextButton.length && blognav.length) {
        blognav.append(blogprevButton).append(blognextButton);

        var blogSwiperWrapper = $('.develop-update .swiper-wrapper');
        var blogSwiperWrapperId = blogSwiperWrapper.attr('id');
        if (!blogSwiperWrapperId) {
            blogSwiperWrapperId = 'swiper-wrapper-' + Math.random().toString(36).substr(2, 9);
            blogSwiperWrapper.attr('id', blogSwiperWrapperId);
        }

        blogprevButton.attr('aria-label', 'Previous slide').attr('aria-controls', blogSwiperWrapperId);
        blognextButton.attr('aria-label', 'Next slide').attr('aria-controls', blogSwiperWrapperId);

        var blogswiperContainer = $('.develop-update .elementor-swiper-container')[0];
        if (blogswiperContainer) {
            var blogswiperInstance = blogswiperContainer.swiper;
            if (blogswiperInstance) {
                blogswiperInstance.params.navigation.prevEl = blogprevButton[0];
                blogswiperInstance.params.navigation.nextEl = blognextButton[0];
                blogswiperInstance.navigation.update();
            } else {
                console.log('Swiper instance not found on the .develop-update element.');
            }
        } else {
            console.log('Element with selector .develop-update .elementor-swiper-container not found.');
        }
    } else {
        console.log('Required elements for "develop-update" swiper not found.');
    }
}, 0); // Adjust the timeout as necessary


	$('.main-menu-container .menu > li.menu-item-has-children > a ').click(function(e){
		e.preventDefault();

		// $('.sub-menu-wrap.open').slideUp();
		if ($(this).parent().find('.sub-menu-wrap').hasClass('open')) {
			$(this).parent().find('.sub-menu-wrap').slideUp();
			$(this).parent().find('.sub-menu-wrap').removeClass('open');
		} else {
			//close other open menus
			$('.sub-menu-wrap.open').slideUp();
			$('.sub-menu-wrap.open').removeClass('open');

			$(this).parent().find('.sub-menu-wrap').slideDown();
			$(this).parent().find('.sub-menu-wrap').addClass('open');

		}
	});


	jQuery.fn.scrollToMe = function(speed,callFunc) {
		var that = this;
		setTimeout(function() {
			var targetOffset = that.offset().top-10;
			$('html,body').eq(0).animate({scrollTop: targetOffset}, speed || 500, callFunc);
		},500);
		return this;
	};
	$('.slick-prev').click(function(){
		$('.explore-slider').slick('slickPrev');
	});

	$('.slick-next').click(function(){
		$('.explore-slider').slick('slickNext');
	});


	$('.gotofirstslide').click(function(){
		$(this).parent().parent().find('.ranger-slider').slick("slickGoTo", 0);
		console.log('clicked');
	});

	$('.gotolastslide').click(function(){
		$int = $(this).data('go-to');
		$(this).parent().parent().find('.ranger-slider').slick('slickGoTo', $int);
		console.log('clicked');
	});


	$('.control-prev').click(function(){
		$('.featured-article-slider').slick('slickPrev');
	});

	$('.control-next').click(function(){
		$('.featured-article-slider').slick('slickNext');
	});
	var $featured_article_slider = $('.featured-article-slider');
	$featured_article_slider.slick({
		"dots": false,
		"infinite": true,
		"arrows": false,
		"slidesToShow": 1,
		"slidesToScroll": 1,
		// "adaptiveHeight": true,
		"respondTo": "window",
		"swipeToSlide": true
	});
		// slider
	var $slick_slider = $('.mobile-slider-cards');
	var settings_slider = {
			"dots": false,
			"infinite": false,
			"arrows": false,
			"slidesToShow": 2,
			"slidesToScroll": 2,
			"adaptiveHeight": true,
			"respondTo": "window",
			"swipeToSlide": true,
			"responsive": [				
				{
					"breakpoint": 769,
					"settings": {
						"slidesToShow": 1,
						"slidesToScroll": 1
					}
				},
				{
					"breakpoint": 480,
					"settings": {
						"slidesToShow": 1,
						"slidesToScroll": 1
					}
				}
			]
		// more settings
	}
	slick_on_mobile( $slick_slider, settings_slider);

	// slick on mobile
		function slick_on_mobile(slider, settings){
			$(window).on('load resize', function() {
				if ($(window).width() > 600) {
					//console.log($(window).width());
					 setTimeout(function(){
						if (slider.hasClass('slick-initialized')) {
							slider.slick('unslick');
						}						
					},200);
					return
				} else {
					//console.log($(window).width());
					if (!slider.hasClass('slick-initialized')) {
						return slider.slick(settings);
					}
				}
			});
		}
		var fullscreen = document.getElementById('play-fullscreen'),
				player = document.getElementById('home-qwv');

		if (fullscreen) {
		fullscreen.addEventListener('click', function (e) {
				if (~player.src.indexOf('?')) player.src += '&autoplay=1';
				else player.src += '?autoplay=1';

				var req = player.requestFullscreen
						|| player.webkitRequestFullscreen
						|| player.mozRequestFullScreen
						|| player.msRequestFullscreen;

				req.call(player);
				e.preventDefault();
		});		
	}
});