// intialization plugins
$(document).ready(function () {

    // navbar-fixed-top
    $(function () {
        $(document).scroll(function () {
            var $nav = $(".navbar-fixed-top");
            $nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
        });
    });

    //animation icon toggler of navbar
    $(`.navbar-toggler`).click(function() {
        $(`.navbar-toggler`).toggleClass(`active`);
    });

    //Wow intit
    wow = new WOW({
        boxClass: 'wow',
        animateClass: 'animated',
        offset: 200,
        mobile: true,
        live: false
    });
    wow.init();

    //fancybox
    $("[data-fancybox]").fancybox({
        selector: '[data-fancybox="images"]',
        // loop: true
    });

    //  loader 
    // $(window).on("load", function() {
    //     $("#preloader").addClass("isdone");
    // });

});

// Swiper
$(document).ready(function () {

    //////////////////// header_swiper  ////////////////////
    var swiper = new Swiper('.header .header_swiper', {
        // loop: true,
        speed: 900,
        slidesPerView: 1,
        spaceBetween: 0,
        effect:'fade',
        // autoplay: {
        //     delay: 2500,
        // },
        navigation: {
            nextEl: '.header .swiper-button-next',
            prevEl: '.header .swiper-button-prev',
        },
        pagination: {
            el: '.header .swiper-pagination',
            clickable: true
        },

    });

    //////////////////// proj_swiper  ////////////////////
    var swiper = new Swiper('.projects_sec .proj_swiper', {
        // loop: true,
        speed: 900,
        slidesPerView: 1,
        spaceBetween: 10,
        // autoplay: {
        //     delay: 2500,
        // },
        navigation: {
            nextEl: '.projects_sec .swiper-button-next',
            prevEl: '.projects_sec .swiper-button-prev',
        },
        pagination: {
            el: '.projects_sec .swiper-pagination',
            clickable: true
        },

    });
    

    //////////////////// values_swiper  ////////////////////
    var swiper = new Swiper('.values_sec .values_swiper', {
        // loop: true,
        speed: 900,
        slidesPerView: 1,
        spaceBetween: 0,
        // effect:'fade',
        // autoplay: {
        //     delay: 2500,
        // },
        navigation: {
            nextEl: '.values_sec .swiper-button-next',
            prevEl: '.values_sec .swiper-button-prev',
        },
        pagination: {
            el: '.values_sec .swiper-pagination',
            clickable: true
        },

    });


    //////////////////// mediaCards_swiper  ////////////////////
    // var mediaCards_swiper = new Swiper(".media_pg .mediaCards_swiper", {
    //     slidesPerView: 3,
    //     spaceBetween: 5,
    //     freeMode: true,
    //     watchSlidesProgress: true,
    //     direction: "vertical",
    //     allowTouchMove: false,
    //     preventClicks: false,
    //     speed: 1000,
    // });
    // var swiper2 = new Swiper(".media_pg .mediaDet_swiper", {
    //     // loop: true,
    //     // effect: 'fade',
    //     spaceBetween: 10,
    //     speed: 1000,
    //     autoplay: {
    //         delay: 3000,
    //     },
    //     thumbs: {
    //         swiper: mediaCards_swiper,
    //     },
    // });

    //////////////////// Swiper  ////////////////////
    // var swiper = new Swiper(' .swiper-container', {
    //     // loop: true,
    //     speed: 900,
    //     slidesPerView: 1,
    //     spaceBetween: 15,
    //     // autoplay: {
    //     //     delay: 2500,
    //     // },
    //     //In Tabs
    //     // observer: true,
    //     // observeParents: true,
    //     navigation: {
    //         nextEl: '.swiper-button-next',
    //         prevEl: '.swiper-button-prev',
    //     },
    //     pagination: {
    //         el: '.swiper-pagination',
    //         clickable: true
    //     },
    //     breakpoints: {
    //         640: {
    //             slidesPerView: 2,
    //             spaceBetween: 20,
    //         },
    //         768: {
    //             slidesPerView: 3,
    //             spaceBetween: 20,
    //         },
    //         1024: {
    //             slidesPerView: 5,
    //             spaceBetween: 20,
    //             // Prevent swiper in lg screens
    //             // allowTouchMove: false,
    //             // preventClicks: false
    //         },
    //     }
    // });

});

//Cursor
$( function() {
    function mousecursor() {
        if ($("body")) {
            const e = document.querySelector(".cursor-inner"),
                t = document.querySelector(".cursor-outer");
            let n, i = 0,
                o = !1;
            window.onmousemove = function (s) {
                o || (t.style.transform = "translate(" + s.clientX + "px, " + s.clientY + "px)"), e.style.transform = "translate(" + s.clientX + "px, " + s.clientY + "px)", n = s.clientY, i = s.clientX
            },
            $("body").on("mouseenter", ".hover_circle, .cursor-pointer", function () {
                e.classList.add("cursor-hover"), t.classList.add("cursor-hover")
            })
            , $("body").on("mouseleave", ".hover_circle, .cursor-pointer", function () {
                $(this).is("a") && $(this).closest(".cursor-pointer").length || (e.classList.remove("cursor-hover"), t.classList.remove("cursor-hover"))
            }),

                // $("body").on("mouseenter", ".swiper-wrapper.curs-scroll", function () {
                //     e.classList.add("cursor-scroll"), t.classList.add("cursor-scroll")
                // }), $("body").on("mouseleave", ".swiper-wrapper.curs-scroll", function () {
                //     $(this).is("a") && $(this).closest(".cursor-pointer").length || (e.classList.remove("cursor-scroll"), t.classList.remove("cursor-scroll"))
                // }),

                e.style.visibility = "visible", t.style.visibility = "visible"
        }
    };

    $(function () {
        mousecursor();
    });

    $("body").mousedown(function(){
        $(".cursor-outer").css({
            width: "15px",
            height: "15px"
        });
    })

    $("body").mouseup(function(){
        $(".cursor-outer").css({
            width: "25px",
            height: "25px"
        });
    })

    $("a").mouseenter(function(){
        $(".cursor-outer").css({
            width: "60px",
            height: "60px"
        });
    })

    $("a").mouseleave(function(){
        $(".cursor-outer").css({
            width: "25px",
            height: "25px"
        });
    })

});

//Dropdown in navbar
$(document).ready(function(){
    // Show dropdown when mouseenter link of has_dropdown
    $('.navs-container .navbar .has_dropdown').on('mouseenter',function () {
        var data_dropdown = $(this).attr('data-dropdown');
        $("#" + data_dropdown).addClass('active');
    });
    $('.navs-container .navbar .has_dropdown').on('mouseleave',function () {
        var data_dropdown = $(this).attr('data-dropdown');
        $("#" + data_dropdown).removeClass('active');
    });

    // Show dropdown when hover div of drop_down
    $(".navs-container .navbar .drop_down").hover(function(){
        $(this).addClass("active");
    } ,
        function(){
            $(this).removeClass("active");
    });
});

//GSAP
$(function () {

    ScrollSmoother.create({ 
        content: "#scrollsmoother-container", 
        smooth: 1.5, 
        normalizeScroll: !0, 
        ignoreMobileResize: !0, 
        effects: !0 
    }),
    
    gsap.timeline({ scrollTrigger: { 
        trigger: ".about_sec1",  start: "-600 top",  scrub: !0 
    } }).to(".about_sec1 .img_box img", {
            x: 0, y: 0, scale: 1.5, duration: 20, ease: "linear", delay: 1 
        }
    ),

    gsap.timeline({ scrollTrigger: { 
        trigger: ".impact_sec",  start: "-600 top",  scrub: !0 
    } }).to(".impact_sec .img_box img", {
            x: 0, y: 0, scale: 1.5, duration: 20, ease: "linear", delay: 1 
        }
    ) ,

    gsap.timeline({ scrollTrigger: { 
        trigger: ".projects_sec",  start: "-600 top",  
    } }).to(".projects_sec .img_box svg rect", {
        opacity: 0,
        duration: 0.1,
        stagger: { amount: 1, from: "random" }
        }
    ),
    gsap.timeline({ scrollTrigger: { 
        trigger: ".turnkey_proj_pg",  start: "-600 top",  scrub: !0 , scale: .5
    } }).to(".turnkey_proj_pg .logo ", {
            x: -50, y: 0, scale: 1, duration: 20, ease: "linear", delay: 1 
        }
    ),
    
    gsap.timeline({ scrollTrigger: { 
        trigger: ".story_pg",  start: "-600 top",  scrub: !0 
    } }).to(".story_pg .img_box img", {
            x: 0, y: 0, scale: 1.5, duration: 20, ease: "linear", delay: 1 
        }
    ),
    
    gsap.timeline({ scrollTrigger: { 
        trigger: ".about_pg",  start: "-600 top",  scrub: !0 
    } }).to(".about_pg .img_box img", {
            x: 0, y: 0, scale: 1.5, duration: 20, ease: "linear", delay: 1 
        }
    ),
    
    gsap.timeline({ scrollTrigger: { 
        trigger: ".csr_pg",  start: "-600 top",  scrub: !0 
    } }).to(".csr_pg .img_box img", {
            x: 0, y: 0, scale: 1.5, duration: 20, ease: "linear", delay: 1 
        }
    );



    // let t = document.querySelectorAll(".pg_header .anim_txt");
    // function r() {
    //     t.forEach(e => {
    //         e.anim && (e.anim.progress(1).kill(), e.split.revert()), e.split = new SplitText(e, {
    //             type: "lines,words,chars",
    //             linesClass: "split-line"
    //         }), e.anim = gsap.from(e.split.chars, {
    //             scrollTrigger: {
    //                 trigger: e,
    //                 toggleActions: "play none none none",
    //                 start: "-200 50% "
    //             },
    //             duration: .3,
    //             ease: "circ.out",
    //             y: 150,
    //             rotation: 90,
    //             stagger: .02,
    //             delay: 0 ,
    //             opacity: 0
    //         })
    //     })
    // }
    // ScrollTrigger.addEventListener("refresh", r), r();

    
});