// Menu
function home_shifting_services_openNav() {
  jQuery(".sidenav").addClass('show');
}
function home_shifting_services_closeNav() {
  jQuery(".sidenav").removeClass('show');
}

( function( window, document ) {
  function home_shifting_services_keepFocusInMenu() {
    document.addEventListener( 'keydown', function( e ) {
      const home_shifting_services_nav = document.querySelector( '.sidenav' );

      if ( ! home_shifting_services_nav || ! home_shifting_services_nav.classList.contains( 'show' ) ) {
        return;
      }
      const elements = [...home_shifting_services_nav.querySelectorAll( 'input, a, button' )],
        home_shifting_services_lastEl = elements[ elements.length - 1 ],
        home_shifting_services_firstEl = elements[0],
        home_shifting_services_activeEl = document.activeElement,
        tabKey = e.keyCode === 9,
        shiftKey = e.shiftKey;

      if ( ! shiftKey && tabKey && home_shifting_services_lastEl === home_shifting_services_activeEl ) {
        e.preventDefault();
        home_shifting_services_firstEl.focus();
      }

      if ( shiftKey && tabKey && home_shifting_services_firstEl === home_shifting_services_activeEl ) {
        e.preventDefault();
        home_shifting_services_lastEl.focus();
      }
    } );
  }
  home_shifting_services_keepFocusInMenu();
} )( window, document );

(function ($) {

    $(window).load(function () {
        $("#pre-loader").delay(500).fadeOut();
        $(".loader-wrapper").delay(1000).fadeOut("slow");

    });

    $(document).ready(function () {

       // $(".toggle-button").click(function () {
       //      $(this).parent().toggleClass("menu-collapsed");
       //  });

        /*--- adding dropdown class to menu -----*/
        $("ul.sub-menu,ul.children").parent().addClass("dropdown");
        $("ul.sub-menu,ul.children").addClass("dropdown-menu");
        $("ul#menuid li.dropdown a,ul.children li.dropdown a").addClass("dropdown-toggle");
        $("ul.sub-menu li a,ul.children li a").removeClass("dropdown-toggle");
        $('nav li.dropdown > a, .page_item_has_children a').append('<span class="caret"></span>');
        $('a.dropdown-toggle').attr('data-toggle', 'dropdown');

        /*-- Mobile menu --*/
        if ($('#site-navigation').length) {
            $('#site-navigation .menu li.dropdown,li.page_item_has_children').append(function () {
                return '<i class="bi bi-caret-down-fill" aria-hd="true"></i>';
            });
            $('#site-navigation .menu li.dropdown .bi,li.page_item_has_children .bi').on('click', function () {
                $(this).parent('li').children('ul').slideToggle();
            });
        }

        /*-- tooltip --*/
        $('[data-toggle="tooltip"]').tooltip();

        /*-- Button Up --*/
        var btnUp = $('<div/>', { 'class': 'btntoTop' });
        btnUp.appendTo('body');
        $(document).on('click', '.btntoTop', function (e) {
            e.preventDefault();
            $('html, body').animate({
                scrollTop: 0
            }, 700);
        });

        $(window).on('scroll', function () {
            if ($(this).scrollTop() > 200)
                $('.btntoTop').addClass('active');
            else
                $('.btntoTop').removeClass('active');
        });


        /*-- Reload page when width is between 320 and 768px and only from desktop */
        var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;
        $(window).on('resize', function () {
            var win = $(this); //this = window
            if (win.width() > 320 && win.width() < 991 && isMobile == false && !$("body").hasClass("elementor-editor-active")) {
                location.reload();
            }
        });
    });

})(this.jQuery);

// font
document.addEventListener('DOMContentLoaded', function () {
    function home_shifting_services_applyColorToLastWords() {
        // Select all heading elements inside the carousel
        document.querySelectorAll('.owl-item.active #banner-heading').forEach(function (headingElement) {
            // Get the full text of the heading (without HTML tags)
            var fullText = headingElement.textContent.trim(); 

            // Split the text into words
            var words = fullText.split(' ');

            // Ensure there are at least 3 words
            if (words.length >= 3) {
                // Extract the last three words
                var lastWords = words.splice(-3).join(' ');

                // Join the remaining words
                var mainText = words.join(' ');

                // Prevent duplicate styling by checking if the span is already applied
                if (!headingElement.innerHTML.includes('<span style="color: #f70643;">')) {
                    headingElement.innerHTML = mainText + ' <span style="color: #f70643;">' + lastWords + '</span>';
                }
            }
        });
    }

    // Wait for the Owl Carousel to initialize
    jQuery('.owl-carousel').on('initialized.owl.carousel', function () {
        home_shifting_services_applyColorToLastWords();
    });

    // Apply styling on every slide change in Owl Carousel
    jQuery('.owl-carousel').on('translated.owl.carousel', function () {
        home_shifting_services_applyColorToLastWords();
    });

    // Run the function manually after a short delay to ensure the first slide is styled
    setTimeout(home_shifting_services_applyColorToLastWords, 500);
});

 
// slider section
jQuery('document').ready(function(){
  var owl = jQuery('.slider-sec .owl-carousel');
    owl.owlCarousel({
    margin:0,
    nav: false,
    autoplay :true,
    lazyLoad: true,
    autoplayTimeout: 9000,
    loop: true,
    dots:true,
    navText : ['<i class="bi bi-chevron-left"></i>', '<i class="bi bi-chevron-right"></i>'],
    responsive: {
      0: {
        items: 1
      },
      576: {
        items: 1
      },
      768: {
        items: 1
      },
      1000: {
        items: 1
      }
    },
    autoplayHoverPause : true,
    mouseDrag: true
  });
});

// solution sec
    jQuery('document').ready(function(){
  var owl = jQuery('#solution-wrap .owl-carousel');
    owl.owlCarousel({
    stagePadding: 200,
    margin:15,
    autoplay : true,
    lazyLoad: true,
    autoplayTimeout: 9000,
    loop: true,
    dots:false,
    navText : ['<i class="bi bi-chevron-left"></i>', '<i class="bi bi-chevron-right"></i>'],
    nav:false,
    items:1,
    center:true,
  responsive:{
        0:{
            items:1,
            stagePadding: 50
        },
        600:{
            items:1,
            stagePadding: 200
        },
        1000:{
            items:1,
            stagePadding: 320
        },
        1200:{
            items:1,
            stagePadding: 410
        },
        1300:{
            items:1,
            stagePadding: 500
        },
        1400:{
            items:1,
            stagePadding: 520
        },
        1500:{
            items:1,
            stagePadding: 500
        },
        1600:{
            items:1,
            stagePadding: 560
        },
        1700:{
            items:1,
            stagePadding: 600
        },
        1800:{
            items:1,
            stagePadding: 650
        },
        1835:{
            items:1,
            stagePadding: 720
        },
         1900:{
            items:1,
            stagePadding: 750
        },
        2000:{
            items:1,
            stagePadding: 750
        },
        2100:{
            items:1,
            stagePadding: 800
        },
         2200:{
            items:1,
            stagePadding: 850
        },
         2300:{
            items:1,
            stagePadding: 900
        },
        2400:{
            items:1,
            stagePadding: 960
        },
        2500:{
            items:1,
            stagePadding: 1000
        }
    }
});
});

// custom-header-text
(function( $ ) {
    // Update site title and description color in real-time
    wp.customize( 'header_textcolor', function( value ) {
        value.bind( function( newval ) {
            if ( 'blank' === newval ) {
                $( '.site-title a, .site-description' ).css({
                    'clip': 'rect(1px, 1px, 1px, 1px)',
                    'position': 'absolute'
                });
            } else {
                $( '.site-title a, .site-description' ).css({
                    'clip': 'auto',
                    'position': 'relative',
                    'color': newval
                });
            }
        });
    });
})( jQuery );

// search form

    document.addEventListener("DOMContentLoaded", function () {
    const searchIcon = document.getElementById("search-icon");
    const searchForm = document.getElementById("search-form");

    if (searchIcon && searchForm) {
        searchIcon.addEventListener("click", function () {
            searchForm.style.display = searchForm.style.display === "block" ? "none" : "block";
        });
    }
    });

    // custom-logo
( function( $ ) {
    wp.customize( 'home_shifting_services_logo_width', function( value ) {
        value.bind( function( newVal ) {
            $( '.logo .custom-logo' ).css( 'max-width', newVal + 'px' );
        } );
    } );
} )( jQuery );