/* Template Name: AdventureGene 
   Description: This is a - Travel Adventure & Tours HTML5 Template;
   Version: 1.0 
   Authot: 
   Website:
    ersion: 1.0  
	NOTE:  This is js file contents all jQuery plugins.
*/
/*================================================
[  Table of contents  ]
================================================*/


(function ($) {
 "use strict";
    jQuery(document).ready(function($){


      // === 1. Hero Slider ===
    if ($('#welcome-slide').length) {
      $('#welcome-slide').owlCarousel({
        autoplay:false,
        items:1,
        loop:true,
        mouseDrag:false,
        lazyLoad:true,
        autoplayHoverPause: false,
        smartSpeed: 2000,
        margin:0,
        nav:false,
        navText:['<i class="fal fa-arrow-left"></i>','<i class="fal fa-arrow-right"></i>'],
        dots:false,
        singleItem: true,
        animateIn: 'fadeIn',
        animateOut: 'fadeOut',
      }) 
    }
    
     $(document).ready(function () {
        const maxLength = 900;
        const detailsInfo = $('.details-info');
        const originalContent = detailsInfo.html().trim();
        const truncatedContent = originalContent.substring(0, maxLength) + '...';

        // Check if content length is greater than maxLength
        if (originalContent.length > maxLength) {
            detailsInfo.html(truncatedContent);
            $('.readmore').show();
        } else {
            $('.readmore').hide();
        }

        // Toggle between Read More and Read Less
        $('.readmore').on('click', function (e) {
            e.preventDefault();
            if ($(this).text() === 'Read More') {
                detailsInfo.html(originalContent);
                $(this).text('Read Less');
            } else {
                detailsInfo.html(truncatedContent);
                $(this).text('Read More');
            }
        });
    });

	/* ==== 02. jQuery MeanMenu Active ==== */
	if ($('.gene-nav').length) {
		jQuery('.gene-nav').meanmenu();	
	}
    /* ==== 03. CounterUp Active ==== */
      if ($('.counter').length) {
        $('.counter').counterUp({
          delay: 10,
          time: 2000
        });
      }
    
    
      // Similar Tips
      if ($('.top-selling-sl').length) {
        $('.top-selling-sl').owlCarousel({
            autoplay:5000,
            loop:true,
            autoplayHoverPause: false,
            smartSpeed: 500,
            nav:false,
            navText:['<i class="fal fa-arrow-left"></i>','<i class="fal fa-arrow-right"></i>'],
            dots:false,
            items:6,
            margin:30,
            responsiveClass:true,
            responsive:{
                0:{
                    items:1,
                },
                600:{
                    items:1,
                },
                768:{
                    items:2,
                },
                991:{
                    items:3,
                },
                1200:{
                    items:3,
                }
            }
        }) 
      }
    
        // Similar Tips
      if ($('.featured-package-sl').length) {
        $('.featured-package-sl').owlCarousel({
            autoplay:5000,
            loop:true,
            autoplayHoverPause: false,
            smartSpeed: 500,
            nav:false,
            navText:['<i class="fal fa-arrow-left"></i>','<i class="fal fa-arrow-right"></i>'],
            dots:false,
            items:6,
            margin:30,
            responsiveClass:true,
            responsive:{
                0:{
                    items:1,
                },
                600:{
                    items:2,
                },
                768:{
                    items:2,
                },
                991:{
                    items:3,
                },
                1200:{
                    items:3,
                }
            }
        }) 
      }
        
    if ($('.testimonial-sl').length) {
        $('.testimonial-sl').owlCarousel({
            autoplay:5000,
            loop:true,
            autoplayHoverPause: false,
            smartSpeed: 500,
            nav:false,
            navText:['<i class="fal fa-arrow-left"></i>','<i class="fal fa-arrow-right"></i>'],
            dots:false,
            items:6,
            margin:30,
            responsiveClass:true,
            responsive:{
                0:{
                    items:1,
                },
                600:{
                    items:1,
                },
                768:{
                    items:1,
                },
                991:{
                    items:1,
                },
                1200:{
                    items:1,
                }
            }
        }) 
      }    
        
        
      if ($('.blog-carousel').length) {
        $('.blog-carousel').owlCarousel({
            autoplay:5000,
            loop:true,
            autoplayHoverPause: false,
            smartSpeed: 500,
            nav:false,
            navText:['<i class="fal fa-arrow-left"></i>','<i class="fal fa-arrow-right"></i>'],
            dots:false,
            items:6,
            margin:30,
            responsiveClass:true,
            responsive:{
                0:{
                    items:1,
                },
                600:{
                    items:2,
                },
                768:{
                    items:2,
                },
                991:{
                    items:3,
                },
                1200:{
                    items:4,
                }
            }
        }) 
      }
      
      if ($('.gallery-main').length) {

        var main = $('.gallery-main');
        var thumbs = $('.gallery-thumbs');
    
        main.owlCarousel({
            items: 1,
            loop: true,
            nav: true,
            dots: false,
            smartSpeed: 600,
            navText: [
                '<span class="slider-arrow"><i class="fal fa-angle-left"></i></span>',
                '<span class="slider-arrow"><i class="fal fa-angle-right"></i></span>'
            ]
        }).on('changed.owl.carousel', function (event) {
    
            var index = event.item.index - event.relatedTarget._clones.length / 2;
            index = index < 0 ? event.item.count - 1 : index;
    
            thumbs.find('.owl-item').removeClass('current');
            thumbs.find('.owl-item').eq(index).addClass('current');
            thumbs.trigger('to.owl.carousel', [index, 300, true]);
        });
    
        thumbs.owlCarousel({
            items: 5,
            margin: 10,
            nav: false,
            dots: false,
            responsive: {
                0: { items: 3 },
                768: { items: 4 },
                1200: { items: 5 }
            }
        });
    
        thumbs.on('click', '.owl-item', function () {
            var index = $(this).index();
            main.trigger('to.owl.carousel', [index, 500, true]);
        });
    
        thumbs.find('.owl-item').eq(0).addClass('current');
    }
    
    if ($('#lightgallery').length) {
        lightGallery(document.getElementById('lightgallery'), {
            selector: 'a',
            thumbnail: true,
            zoom: true,
            download: false,
            actualSize: false
        });
    }
    
    $('.view-gallery-btn').on('click', function () {
        $('#lightgallery a').first().trigger('click');
    });


    $('#share-blog').click(function(){
        $('.share-social').toggleClass('show-share-social');
    });

        
        $(document).ready(function() {
            // Function to toggle visibility of child ul and remove href attribute
            function toggleChildUl() {
                if ($(window).width() < 992) {
                    // Remove href attribute from dropdown-toggle anchors
                    $(' .dropdown-toggle').removeAttr('href');
                    // Toggle visibility of all child ul elements
                    $('.main-menunav .navbar-nav li > ul .dropdown-toggle').find('> ul').toggle();
                    // Bind click event to toggle visibility on click
                    $(' .dropdown-toggle').click(function(e) {
                        e.preventDefault();
                        $(this).next('ul').slideToggle();
                    });
                } else {
                    // Restore original behavior on larger screens
                    $('.main-menunav .navbar-nav li > ul .dropdown-toggle').attr('href', '#');
                    $('.nav-item > .main-menunav .navbar-nav li > ul').show();
                }
            }

            // Initial setup
            toggleChildUl();

            // Update on window resize
            $(window).resize(function() {
                toggleChildUl();
            });
        });
        
        $('#collaspe-itinerary').click(function () {
            $('.itinerary-thumb-contents').toggleClass('show');
        
            // Toggle button text
            if ($(this).text().trim() === 'Expand All') {
                $(this).text('Collapse All');
            } else {
                $(this).text('Expand All');
            }
        });

        
        $('#share-toggle').click(function(){
           $('.share-social').toggleClass('show-share-social');
        });

        $('.main-menunav .dropdown-menu li a').click(function() {
            $(this).next('ul').addClass("show-drop");
        }, (e) => {
            $(this).prev('ul').removeClass("show-drop");
        });

        $(document).ready(function() {
            $('.navbar-nav .nav-item').click(
                function() {
                    // Mouse enter: add the class to the first child's ul
                    $(this).find('> ul').addClass("show-drop");
                },
                function() {
                    // Mouse leave: remove the class from the first child's ul
                    $(this).find('> ul').removeClass("show-drop");
                }
            );
        });
      $('.header-area .search-icon').click(function(){
         $('.header-area .search-box').addClass('showbox'); 
      });
      
      $('.header-area .search-box .fa-times').click(function(){
         $('.header-area .search-box').removeClass('showbox'); 
      });
      
      
      
      /* ==== 08. Cart Plus Minus ==== */
        var CartPlusMinus = $('.cart-plus-minus');
        CartPlusMinus.prepend('<div class="dec qtybutton">-</div>');
        CartPlusMinus.append('<div class="inc qtybutton">+</div>');
        $(".qtybutton").on("click", function() {
            var $button = $(this);
            var oldValue = $button.parent().find("input").val();
            if ($button.text() === "+") {
                var newVal = parseFloat(oldValue) + 1;
            } else {
                // Don't allow decrementing below zero
                if (oldValue > 0) {
                    var newVal = parseFloat(oldValue) - 1;
                } else {
                    newVal = 1;
                }
            }
            $button.parent().find("input").val(newVal);
        });

        /* ==== 06. Range Slider ==== */
         if($('.slider-product-sorting').length){
             $( function() {
                 $( ".slider-product-sorting" ).slider({
                 range: true,
                 min: 0,
                 max: 1000,
                 values: [ 200, 600 ],
                 slide: function( event, ui ) {
                 $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
                 }
                 });
                 $( "#amount" ).val( "$" + $( ".slider-product-sorting" ).slider( "values", 0 ) +
                 " - $" + $( ".slider-product-sorting" ).slider( "values", 1 ) );
             } );
         }
        // ========== isotope

         $('.isotope_wrap').imagesLoaded(function() {
            var $grid = $('.isotope_wrap').isotope({
                itemSelector: '.isotope_item',
                percentPosition: true,
                masonry: {
                    columnWidth: '.isotope_item',
                }
            });
        });

		/* ==== 05. ScrollUp ==== */
		$.scrollUp({
			scrollText: '<i class="fal fa-arrow-alt-up"></i>',
			easingType: 'linear',
			scrollSpeed: 900,
			animation: 'fade'
		}); 
	
    });

    var current_page_URL = location.href;
       $( ".gene-nav ul li a" ).each(function() {
           if ($(this).attr("href") !== "#") {
            var target_URL = $(this).prop("href");
            if (target_URL == current_page_URL) {
              $('.gene-nav a').parents('li, ul').removeClass('active');
              $(this).parent('li').addClass('active');
               return false;
            }
           }
       });

// // ==== 11. Sticky Header ====
//     $(function() {
//         var header = $("#header"),
//             yOffset = 0,
//             triggerPoint = 200;
//         $(window).on( 'scroll', function() {
//             yOffset = $(window).scrollTop();
//             if (yOffset >= triggerPoint) {
//             	header.removeClass("animated cssanimation");
//                 header.addClass("navbar-fixed-top sticky  cssanimation animated fadeInTop");
//             } else {
//                 header.removeClass("navbar-fixed-top sticky cssanimation  animated fadeInTop");
//                 header.addClass("animated cssanimation");
//             }

//         });
//     });


	/* ==== 21. Preloader ==== */
	$(window).on('load',function(){
		jQuery(".preloader-wrap").fadeOut(500);
	});

	
})(jQuery); 



