$(document).ready(function() {
    // Page Scroll Adjust menu
    $(window).scroll(function(){
        if ($(this).scrollTop() > 50) {
           $('.header_wrap__yM3x0').addClass('header_compact__aKYNF');
           $('.header_sticky__2Bx4l').addClass('header_shadow__lM6e3');
           $('.header_logo__ZEQm1').addClass('header_compact__aKYNF');

        } else {
            $('.header_wrap__yM3x0').removeClass('header_compact__aKYNF');
            $('.header_sticky__2Bx4l').removeClass('header_shadow__lM6e3');
            $('.header_logo__ZEQm1').removeClass('header_compact__aKYNF');
        }
    });


    $('.header_burger__5WW4f').on('click', function () {
            if($(".header_navs__ryH9S").hasClass('header_open__Mydxw')) {
                $('.header_navs__ryH9S').removeClass('header_open__Mydxw');
                $(".overlay_overlay__K50F9").addClass('d-none');
            } else {
                $('.header_navs__ryH9S').addClass('header_open__Mydxw');
                $(".overlay_overlay__K50F9").removeClass('d-none');
            }   
    });

    $(window).resize(function(){   
        var $theWindowSize = $(this).width();
        if($theWindowSize > 1200) {
                $('.header_navs__ryH9S').removeClass('header_open__Mydxw');
            }
    });
    
    // Show dropdown menu
    $('.header_link-wrap__pM5rP').on('click', function () {
        // reset all arrows before rotate
        // $(".header_arrow__jchUA").removeClass('header_arrow-active__FfTK9');
        // end reset all arrows before rotate
        if (!$(this).hasClass('header_link-no-child')) {
            if($(this).hasClass('header_link-arrow__tuSTy')) {
                
                $(this).removeClass('header_link-arrow__tuSTy');
                $(".header_arrow__jchUA", this).removeClass('header_arrow-active__FfTK9');
                $(this).next('.header_sub__7Df_y').addClass('d-none');
                $('.header_link-wrap__pM5rP').next('.header_sub__7Df_y').addClass('sub-closed');
                $(this).next('.header_sub__7Df_y').removeClass('sub-opened');
                $(".button_button__Yaq9u", this).removeClass('header_link-active__BEgYx');
                   
                // Make sure the hamburger is not active
                if(!$(".header_navs__ryH9S").hasClass('header_open__Mydxw')) {
                    $(".overlay_overlay__K50F9").addClass('d-none');
                }
                console.log('first 1');
    
             } else {
                
                 // remove current active menu
                 $('.header_link-wrap__pM5rP').removeClass('header_link-arrow__tuSTy');
                 $('.header_link-wrap__pM5rP').next('.header_sub__7Df_y').addClass('d-none');
                 $('.header_link-wrap__pM5rP').next('.header_sub__7Df_y').removeClass('sub-opened');
                  $(".button_button__Yaq9u").removeClass('header_link-active__BEgYx');
                 $(".header_arrow__jchUA").removeClass('header_arrow-active__FfTK9');
                 $(".overlay_overlay__K50F9").removeClass('d-none');

                // set new active menu
                $(this).addClass('header_link-arrow__tuSTy');
                $(".header_arrow__jchUA", this).addClass('header_arrow-active__FfTK9');
                $(this).next('.header_sub__7Df_y').removeClass('d-none');
                $(this).next('.header_sub__7Df_y').removeClass('sub-closed');
                $(this).next('.header_sub__7Df_y').addClass('sub-opened');
                $(".button_button__Yaq9u", this).addClass('header_link-active__BEgYx');
    
                // Make sure the hamburger is not active
                if(!$(".header_navs__ryH9S").hasClass('header_open__Mydxw')) {
                    $(".overlay_overlay__K50F9").removeClass('d-none');
                }
                // $(".overlay_overlay__K50F9").removeClass('d-none');
                console.log('Else');
            }
        }
     });

    $('.overlay_overlay__K50F9').mouseup(function (e){
        if(!$(".header_navs__ryH9S").hasClass('header_open__Mydxw')) {
            if($('.header_sub__7Df_y').hasClass('sub-opened')) {
                    var container = $(".header_sub__7Df_y.sub-opened"); // Give you class or ID
                    
                    if (!container.is(e.target) &&            // If the target of the click is not the desired div or section
                        container.has(e.target).length === 0) // ... nor a descendant-child of the container
                    {

                    container.prev(".header_link-wrap__pM5rP").removeClass('header_link-arrow__tuSTy');
                    container.prev(".header_link-wrap__pM5rP").find('.button_button__Yaq9u').removeClass('header_link-active__BEgYx');
                    container.prev(".header_link-wrap__pM5rP").find('.header_arrow__jchUA').removeClass('header_arrow-active__FfTK9');
                    
                    container.removeClass('sub-opened');
                    container.addClass('sub-closed d-none');
                    // console.log(container.prev(".header_link-wrap__pM5rP"));

                    $(".overlay_overlay__K50F9").addClass('d-none');
                    console.log("Is affecting");

                }
            }else{
                $(this).toggleClass('d-none');
            }
        }
        });

    $(".circle-card").on("mouseover mouseout", function() {
        $(this).parent().toggleClass("dimmed");
        $(this).toggleClass("active-circle");
    });

    setTimeout(function() {
        $(".circle-thingy").addClass("lines-in");
        $(".blue-background").addClass("cards-in");
    }, 500);

});


// $(document).foundation();

$(document).ready(function() {

    var mediaQueryMedium = window.matchMedia('(max-width: 1023px)');
    $(window).on('load resize', function () {
        mediaQueryMedium = window.matchMedia('(max-width: 1023px)');
    });

    setTimeout(function(){
        $('.header-logo').addClass('close');
    }, 100);
    setTimeout(function(){
        $('.header-nav').addClass('close');
    }, 100);
    setTimeout(function(){
        $('.header-btns').addClass('close');
        $('.home-intro-section-box .section-subtitle').addClass('close');
        $('.home-intro-section-box .home-intro-title').addClass('close');
    }, 300);

    setTimeout(function(){
        $('.intro-img-anim-1').addClass('close');
    }, 600);
    setTimeout(function(){
        $('.intro-img-anim-2').addClass('close');
    }, 800);

    if( $('.home-large-section-sticky-background-inside').length ) {
        $(window).on('load resize', function() {
            var getScreenWidth = $(window).width();
            var getScreenHeight = $(window).height();
            $('.home-large-section-sticky-background-inside').css("width", getScreenWidth + 'px');
            $('.home-large-section-sticky-background-inside').css("height", getScreenHeight + 'px');
        });
    }
    
    $(".hamburger-open-js").click(function() {
        $(this).toggleClass('is-active');
        $('.mobile-header').toggleClass('close');
        $('.mob-circle').toggleClass('close');
    });
    $(".hamburger-close-js").click(function() {
        $(".hamburger-open-js").removeClass('is-active');
        $('.mobile-header').toggleClass('close');
        $('.mob-circle').toggleClass('close');
    });
    $(".mobile-header-nav > ul > li.menu-item-has-children > a").on('click', function(ee) {
        ee.preventDefault();
        if( $(this).parent().hasClass('is-active') ) {
            $(this).parent().removeClass('is-active');
            $(this).parent().find('ul').slideUp(300);
        } else {
            $(this).parent().addClass('is-active');
            $(this).parent().find('ul').slideDown(300);
        }
    });

    // Entry table scroll wrap
    $( ".entry table" ).wrap( "<div class='table-scroll'></div>" );
    
    // header mobile dropdown add
    $( ".mobile-header-nav ul li.menu-item-has-children a" ).append( "<span></span>" );

    // #ScrollToTop
    // $("a[href='#top']").click(function() {
    //   $("html, body").animate({ scrollTop: 0 }, "slow");
    //   return false;
    // });

    // #href scroll //
    // $('a[href^="#"]').on('click',function (e) {
    //     e.preventDefault();

    //     var target = this.hash;
    //     var $target = $(target);

    //     $('html, body').stop().animate({
    //         'scrollTop': $target.offset().top
    //     }, 700, 'swing', function () {
    //         window.location.hash = target;
    //     });
    // });

    var media_small = window.matchMedia('(max-width: 639px)');
    $(window).on('load resize', function () {
        media_small = window.matchMedia('(max-width: 639px)');
    });

    // homepage animated section
    if( $('.home-large-section-hidden').length ) {
        $(window).on( 'scroll resize', function(){
            $window = $(window);
            var scrollTop = $(window).scrollTop() - $(".home-large-section").offset().top;

            $('.home-large-section-hidden').each(function(){
                var thisDistance = $(this).offset().top - ( $(window).height() / 3);

                if ( $window.scrollTop() >= thisDistance ) {
                    var id = $(this).attr('data-id');

                    $(this).addClass('in-view');
                    $('.home-large-section-sticky-item').removeClass('is-active');
                    $('#' + id).addClass('is-active');
                    $('#' + id).find('.section-title-64').addClass('in-view');
                    $('#' + id).find('.home-large-section-sticky-item-btn').addClass('in-view');
                } else {
                    $(this).removeClass('in-view');
                    $('#' + id).removeClass('is-active');
                    $('.home-large-section-sticky-item').not('.is-active').find('.section-title-64').removeClass('in-view');
                    $('.home-large-section-sticky-item').not('.is-active').find('.home-large-section-sticky-item-btn').removeClass('in-view');
                }
            });

            if( $('.home-large-section-hidden').hasClass('in-view') && scrollTop > 0) {
                var getScreenWidthNew = Math.round ($(window).width() + (scrollTop / 40 ));
                var getScreenHeightNew = Math.round ($(window).height() + (scrollTop / 40 ));

                if( media_small.matches ) {
                    var thisMaxHeight = Math.round (220 + (scrollTop ));
                    var thisMaxWidth = Math.round (220 + (scrollTop ));
                } else {
                    var thisMaxHeight = Math.round (420 + (scrollTop ));
                    var thisMaxWidth = Math.round (420 + (scrollTop ));
                }
               
                $('.home-large-section-sticky-background').css({'max-height': thisMaxHeight+"px"});
                $('.home-large-section-sticky-background').css({'max-width': thisMaxWidth+"px"});

                $('.home-large-section-sticky-background-inside').css("width", getScreenWidthNew + 'px');
                $('.home-large-section-sticky-background-inside').css("height", getScreenHeightNew + 'px');
            } else {
                if( media_small.matches ) {
                    $('.home-large-section-sticky-background').css({'max-height': "220px"});
                $('.home-large-section-sticky-background').css({'max-width': "220px"});
                } else {
                    $('.home-large-section-sticky-background').css({'max-height': "420px"});
                    $('.home-large-section-sticky-background').css({'max-width': "420px"});
                }
            }
        });
    }

    var lastScrollTop = 0;
    if( $('.company-page-values-section-hiddens').length ) {
        var company_page_values_section_hiddens = $('.company-page-values-section-hiddens').offset().top;
    }
    $(window).scroll(function(){

        vh = $(window).height();
        var st = $(this).scrollTop();

        if( $('.intro-img-anim').length ) {
            cofIntro1 = st / 10
            $('.intro-img-anim-2 img').css('transform','translate(0,'+cofIntro1+'px)');
            $('.intro-img-anim-1 img').css('transform','translate(0,-'+cofIntro1+'px)');
        }

        if( $('.company-intro-section-right-box').length ) {
            cofIntro1 = st / 10
            $('.company-intro-section-right-box-img-3 img').css('transform','translate(0,'+cofIntro1+'px)');
            $('.company-intro-section-right-box-img-1 img').css('transform','translate(0,-'+cofIntro1+'px)');
        }

        if( $('.company-page-values-section-hiddens').length ) {
            var company_page_values_section = company_page_values_section_hiddens - st;
            if(  company_page_values_section < 1) {
                $('.company-page-values-section-item:not(.company-page-values-section-item-1)').each(function() {
                    var cpvs_item_positon = ($(this).offset().top - st);
                    if( cpvs_item_positon >= 0 ) {
                        $(this).css('transform','translate(0,'+company_page_values_section+'px)');
                    } 
                });
            }
        }

        if( $('.product-intro-section').length ) {
            cofIntro1 = st / 10
            $('.product-intro-section-img-2 img').css('transform','translate(0,'+cofIntro1+'px)');
            $('.product-intro-section-img-1 img').css('transform','translate(0,-'+cofIntro1+'px)');
        }

        if (st > 14) {
            $('header').addClass('scrolled')
        } else {
            $('header').removeClass('scrolled')
        }
        if (st > vh / 2) {
            $('header').addClass('scrolled-more')
        } else {
            $('header').removeClass('scrolled-more')
        }
        if (st > lastScrollTop){
            $('header').addClass('scrolling-down')
            $('header').removeClass('scrolling-up')
        } else {
            $('header').removeClass('scrolling-down')
            $('header').addClass('scrolling-up')
        }
        lastScrollTop = st;
     });

    // homepage animated section rnadom image rotation
    if( $('.hlssbi-image-box').length ) {
        $('.hlssbi-image-box').each(function(){
            var theRandomNumber = Math.floor(Math.random() * 30) - 15;
            $(this).css({'transform' : 'rotate('+ theRandomNumber +'deg)'});
        });
    }

    Splitting({
        target: "[data-splitting]",
        by: 'lines'
    });
    $('.splitting span').wrap('<span></span>')

    setTimeout(function(){
        $('.home-intro-section-box .section-subtitle span').wrap('<span></span')
        $('.home-intro-section-box .home-intro-title span, .home-intro-section-box .home-intro-title strong').wrap('<span></span')
    }, 100);

    if( $('.front-page-intro-video-image').length ) {
        $(window).on('scroll resize load', function() {
            $('.front-page-intro-video-image').each(function(i) {
                var offsetTop = $(this).offset().top;
                var scrollTop = $(window).scrollTop() + ($(window).height() / 3);
                var trueNumber = (scrollTop - offsetTop) / 130;
                
                if( number < 0) {
                    number = 0;
                } else {
                    var number = 4 - (trueNumber );
                }
                if( number2 < 0) {
                    number2 = 0;
                } else {
                    var number2 = 10 - (trueNumber * 2);
                }
                if( number > 4) {
                    number = 4;
                } else {
                    var number = 4 - (trueNumber );
                }
                if( number2 > 10) {
                    number2 = 10;
                } else {
                    var number2 = 10 - (trueNumber * 2);
                }

                $(this).css('clip-path', "inset(0px "+number+"rem round "+number2+"px)");

                if( scrollTop >= offsetTop ) {
                    if( scrollTop >= offsetTop ) {
                        $(this).css('clip-path', "inset(0px "+number+"rem round "+number2+"px)");
                    } else {
                        $(this).css('clip-path', "inset(0px "+number+"rem round "+number2+"px)");
                    }
                }
            });
        });
    }

    if( $('.animation-list-element').length ) {
        $('.animation-list-element').each(function(){
            $(this).find('ul li').each(function(i){
                $(this).css('animation-delay', i*100 + 'ms');
            });
        });
    }
    if( $('.animation-list-element-transition').length ) {
        $('.animation-list-element-transition').each(function(){
            $(this).find('ul li').each(function(i){
                $(this).css('transition-delay', i*100 + 'ms');
            });
        });
    }
    
    // if( $('.community-grid').length ) {
    //     $('.community-grid').packery({
    //         percentPosition: true,   
    //         horizontalOrder: true,
    //         itemSelector: '.grid-item',
    //     });

    //     $(window).bind('resize', function(e) {
    //         if (window.RT) clearTimeout(window.RT);
    //         window.RT = setTimeout(function() {
    //             this.location.reload(false); /* false to get page from cache */
    //         }, 100);
    //     });

    //     $('.community-grid').each(function(){
    //         $(this).find('.grid-item').each(function(i){
    //             $(this).css('animation-delay', i*100 + 'ms');
    //         });
    //     });
    // }

    if( $('.company-page-values-section-item').length ) {
        $('.company-page-values-section-item').each(function (i){
            $(this).css('top', 100 * i + 'vh');
        });
    }

    if( $('.company-page-leadership-section-list-img-hold').length ) {
        $('.company-page-leadership-section-list-img-hold').each(function(){
            var theRandomNumber = Math.floor(Math.random() * 8) - 4;
            $(this).css({'transform' : 'rotate('+ theRandomNumber +'deg)'});
        });
    }

    if( $('.sticky-content').length ) {
        // top meniu scroll and current
            var lastId,
            topMenu = $(".sticky-nav"),
            topMenuHeight = topMenu.outerHeight()+16,
            menuItems = topMenu.find("a"),
            // menuImg = $('.sticky-image-hold img'),
            scrollItems = menuItems.map(function(){
                var item = $($(this).attr("href"));
                if (item.length) { return item; }
            });

        $(window).scroll(function(){
            wHeight = $(window).height()
            var fromTop = $(this).scrollTop()+topMenuHeight - wHeight / 1.5;

            var cur = scrollItems.map(function(){
            if ($(this).offset().top < fromTop)
            return this;
            });
            cur = cur[cur.length-1];
            var id = cur && cur.length ? cur[0].id : "";

            if (lastId !== id) {
            lastId = id;
            menuItems
                .parent().removeClass("active")
                .end().filter("[href='#"+id+"']").parent().addClass("active");
                $('.sticky-image-hold div').removeClass("active");
                $('.sticky-image-hold .img-'+id).addClass("active");
            }      
        });
    }

    setTimeout(function(){
        $('.product-intro-section-img-1').addClass('close');
    }, 600);
    setTimeout(function(){
        $('.product-intro-section-img-2').addClass('close');
    }, 800);

    setTimeout(function(){
        $('.company-intro-section-right-box-img-1').addClass('close');
    }, 600);
    setTimeout(function(){
        $('.company-intro-section-right-box-img-2').addClass('close');
    }, 800);
    setTimeout(function(){
        $('.company-intro-section-right-box-img-3').addClass('close');
    }, 1000);

    $('.ppage-isri-1').hover(
        function() {
            $('.ppage-isri-2').addClass('hovered');
            $('.ppage-isri-3').addClass('hovered');
            $('.ppage-isri-4').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-2').hover(
        function() {
            $('.ppage-isri-1').addClass('hovered');
            $('.ppage-isri-4').addClass('hovered');
            $('.ppage-isri-5').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-3').hover(
        function() {
            $('.ppage-isri-1').addClass('hovered');
            $('.ppage-isri-4').addClass('hovered');
            $('.ppage-isri-6').addClass('hovered');
            $('.ppage-isri-7').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-4').hover(
        function() {
            $('.ppage-isri-1').addClass('hovered');
            $('.ppage-isri-2').addClass('hovered');
            $('.ppage-isri-3').addClass('hovered');
            $('.ppage-isri-5').addClass('hovered');
            $('.ppage-isri-7').addClass('hovered');
            $('.ppage-isri-8').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-5').hover(
        function() {
            $('.ppage-isri-2').addClass('hovered');
            $('.ppage-isri-4').addClass('hovered');
            $('.ppage-isri-8').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-6').hover(
        function() {
            $('.ppage-isri-3').addClass('hovered');
            $('.ppage-isri-7').addClass('hovered');
            $('.ppage-isri-9').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-7').hover(
        function() {
            $('.ppage-isri-3').addClass('hovered');
            $('.ppage-isri-4').addClass('hovered');
            $('.ppage-isri-6').addClass('hovered');
            $('.ppage-isri-8').addClass('hovered');
            $('.ppage-isri-9').addClass('hovered');
            $('.ppage-isri-10').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-8').hover(
        function() {
            $('.ppage-isri-4').addClass('hovered');
            $('.ppage-isri-5').addClass('hovered');
            $('.ppage-isri-7').addClass('hovered');
            $('.ppage-isri-10').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-9').hover(
        function() {
            $('.ppage-isri-6').addClass('hovered');
            $('.ppage-isri-7').addClass('hovered');
            $('.ppage-isri-10').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );
    $('.ppage-isri-10').hover(
        function() {
            $('.ppage-isri-7').addClass('hovered');
            $('.ppage-isri-8').addClass('hovered');
            $('.ppage-isri-9').addClass('hovered');
        }, function() {
            $('.product-page-integrations-section-right-item a').removeClass('hovered');
        }
    );

    if( $('.products-circle-sticky-hidden').length ) {
        $(window).on( 'scroll resize', function(){
            $window = $(window);
            var scrollTop = $(window).scrollTop() - $(".products-circle-sticky-section").offset().top;

            $('.products-circle-sticky-hidden').each(function(){
                var thisDistance = $(this).offset().top - ( $(window).height() / 3);

                if ( $window.scrollTop() >= thisDistance ) {
                    var id = $(this).attr('data-id');

                    $(this).addClass('in-view');
                    
                    if( id == 'products-circle-sticky-hidden-1') {
                        $('.products-circle-sticky-text-1').addClass('in-view');
                    }

                    if( id == 'products-circle-sticky-hidden-2') {
                        $('.products-circle-sticky-text-2').addClass('in-view');
                    }

                    if( id == 'products-circle-sticky-hidden-3') {
                        $('.products-circle-sticky-text-3').addClass('in-view');
                    }
                } 

                if ( $window.scrollTop() <= $(this).offset().top - 120) {
                    $(this).removeClass('in-view');

                    if( id == 'products-circle-sticky-hidden-1') {
                        $('.products-circle-sticky-text-1').removeClass('in-view');
                    }

                    if( id == 'products-circle-sticky-hidden-2') {
                        $('.products-circle-sticky-text-2').removeClass('in-view');
                    }

                    if( id == 'products-circle-sticky-hidden-3') {
                        $('.products-circle-sticky-text-3').removeClass('in-view');
                    }
                } 
            });

            var wHeight = $(window).height();

            if( wHeight < 1024 && wHeight > 780) {
                var scrollTopZero = scrollTop * 1.4;
            } else if ( wHeight < 780 ) {
                var scrollTopZero = scrollTop * 1.6;
            } else {
                var scrollTopZero = scrollTop;
            }
            if( scrollTop >= 0) {
                
                var item_1_a = 100 - (scrollTopZero / 18);
                var item_1_b = 60 - (scrollTopZero / 29);

                var item_2_a = 0;
                var item_2_b = 60 - (scrollTopZero / 30);

                var item_3_a = 80 - (scrollTopZero / 23);
                var item_3_b = 20 - (scrollTopZero / 70);

                var item_4_a = 30 - (scrollTopZero / 55);
                var item_4_b = 30 - (scrollTopZero / 64);

                var item_5_a = 75 - (scrollTopZero / 24);
                var item_5_b = 35 - (scrollTopZero / 56);
                
                if( item_1_a < 0) { item_1_a = 0; }
                if( item_1_b < 0) { item_1_b = 0; }

                if( item_2_a < 0) { item_2_a = 0; }
                if( item_2_b < 0) { item_2_b = 0; }

                if( item_3_a < 0) { item_3_a = 0; }
                if( item_3_b < 0) { item_3_b = 0; }

                if( item_4_a < 0) { item_4_a = 0; }
                if( item_4_b < 0) { item_4_b = 0; }

                if( item_5_a < 0) { item_5_a = 0; }
                if( item_5_b < 0) { item_5_b = 0; }

                $('.products-circle-sticky-circle-segment-1').css({"transform":"translate(-"+item_1_a+"%,-"+item_1_b+"%)"});
                $('.products-circle-sticky-circle-segment-2').css({"transform":"translate("+item_2_a+"%,-"+item_2_b+"%)"});
                $('.products-circle-sticky-circle-segment-3').css({"transform":"translate("+item_3_a+"%,-"+item_3_b+"%)"});
                $('.products-circle-sticky-circle-segment-4').css({"transform":"translate("+item_4_a+"%,"+item_4_b+"%)"});
                $('.products-circle-sticky-circle-segment-5').css({"transform":"translate(-"+item_5_a+"%,"+item_5_b+"%)"});
            }
        });
    }

    if( $('.testimonial-slider-owl').length ) {
        $('.testimonial-slider-owl').owlCarousel({
            loop:true,
            margin:60,
            nav:true,
            dots: false,
            items: 1,
            mouseDrag: false,
            touchDrag: false,
            pullDrag: false,
            freeDrag: false,
            // animateOut: 'fade-in',
            animateIn: 'fadeIn',
        });
    }

    if( $('.testimonial-slider-owl-prev').length ) {
        $('.testimonial-slider-owl-prev').owlCarousel({
            loop:true,
            margin:60,
            nav:false,
            dots: false,
            items: 1,
            startPosition: -1,
            mouseDrag: false,
            touchDrag: false,
            pullDrag: false,
            freeDrag: false,
            // animateOut: 'fade-in',
            animateIn: 'fadeIn',
        });
    }

    if( $('.testimonial-slider-owl-next').length ) {
        $('.testimonial-slider-owl-next').owlCarousel({
            loop:true,
            margin:60,
            nav:false,
            dots: false,
            items: 1,
            startPosition: 1,
            mouseDrag: false,
            touchDrag: false,
            pullDrag: false,
            freeDrag: false,
            // animateOut: 'fade-in',
            animateIn: 'fadeIn',
        });
    }

    $('.testimonial-slider-owl .owl-prev').on('click', function() {
        $('.testimonial-slider-owl-prev').trigger('prev.owl.carousel');
        $('.testimonial-slider-owl-next').trigger('prev.owl.carousel');
    });
    $('.testimonial-slider-owl .owl-next').on('click', function() {
        $('.testimonial-slider-owl-prev').trigger('next.owl.carousel');
        $('.testimonial-slider-owl-next').trigger('next.owl.carousel');
    });

    if( $('.company-page-leadership-section').length ) {
        var section_offset = $(".company-page-leadership-section").offset();

        var item_centerd_1 = section_offset.left + $(".company-page-leadership-section").outerWidth() / 4;
        var item_centerd_2 = section_offset.left + $(".company-page-leadership-section").outerWidth() / 8;
        var item_centerd_3 = section_offset.left + ($(".company-page-leadership-section").outerWidth() / 10) 
        var item_centerd_4 = section_offset.left + ($(".company-page-leadership-section").outerWidth() / 6) 

        var item_top_1_1 = ($(".company-page-leadership-section").outerHeight() / 1.07) * -1;
        var item_top_2_2 = ($(".company-page-leadership-section").outerHeight() / 1.07) * -1;
        var item_top_3_3 = ($(".company-page-leadership-section").outerHeight() / 1.07) * -1;
        var item_top_4_4 = ($(".company-page-leadership-section").outerHeight() / 1.07) * -1;

        $(window).on( 'scroll resize load', function(){
            $window = $(window);
            var scrollTop = $(window).scrollTop() - ($(".company-page-leadership-section").offset().top - $(window).height() / 3);
            
            $('.company-page-leadership-section-list-img-1').css('left', item_centerd_1);
            $('.company-page-leadership-section-list-img-2').css('left', item_centerd_2);
            $('.company-page-leadership-section-list-img-3').css('left', 'auto');
            $('.company-page-leadership-section-list-img-3').css('right', item_centerd_3);
            $('.company-page-leadership-section-list-img-4').css('left', 'auto');
            $('.company-page-leadership-section-list-img-4').css('right', item_centerd_4);

            $('.company-page-leadership-section-list-img-1').css('top', item_top_1_1);
            $('.company-page-leadership-section-list-img-2').css('top', item_top_2_2);
            $('.company-page-leadership-section-list-img-3').css('top', item_top_3_3);
            $('.company-page-leadership-section-list-img-4').css('top', item_top_4_4);

            if( scrollTop > 0 ) {
                var item_1_a = item_centerd_1 - (scrollTop / 1.);
                var item_1_b = item_top_1_1 + (scrollTop * 1.4);
                if( item_1_a < 0) { item_1_a = 0; }
                if( item_1_b >= -58) { item_1_b = -58; }
                $('.company-page-leadership-section-list-img-1').css('left', item_1_a);
                $('.company-page-leadership-section-list-img-1').css('top', item_1_b);

                var item_2_a = item_centerd_2 - (scrollTop / 1.);
                var item_2_b = item_top_2_2 + (scrollTop * 1.4);
                if( item_2_a < 0) { item_2_a = 0; }
                if( item_2_b >= -58) { item_2_b = -58; }
                $('.company-page-leadership-section-list-img-2').css('left', item_2_a);
                $('.company-page-leadership-section-list-img-2').css('top', item_2_b);

                var item_3_a = item_centerd_3 - (scrollTop / 1.);
                var item_3_b = item_top_3_3 + (scrollTop * 1.4);
                if( item_3_a < 0) { item_3_a = 0; }
                if( item_3_b >= -58) { item_3_b = -58; }
                $('.company-page-leadership-section-list-img-3').css('right', item_3_a);
                $('.company-page-leadership-section-list-img-3').css('top', item_3_b);

                var item_4_a = item_centerd_4 - (scrollTop / 1.);
                var item_4_b = item_top_4_4 + (scrollTop * 1.4);
                if( item_4_a < 0) { item_4_a = 0; }
                if( item_4_b >= -58) { item_4_b = -58; }
                $('.company-page-leadership-section-list-img-4').css('right', item_4_a);
                $('.company-page-leadership-section-list-img-4').css('top', item_4_b);

                if( !mediaQueryMedium.matches ) {
                    if( (item_1_a && item_2_a && item_3_a && item_4_a) == 0 && (item_1_b && item_2_b && item_3_b && item_4_b) == -58 ) {
                        $('.company-page-leadership-section .section-title-64').addClass('in-view');
                    } else {
                        $('.company-page-leadership-section .section-title-64').removeClass('in-view');
                    }
                }
            }
        });
    }

    $('.price-page-pricing-section-nav ul').on('click', function() {
        $(this).toggleClass('is-active')
        var item = $(this).find('li.is-active');
        item.removeClass('is-active');
        if( item.next().length ) {
            item.next().addClass('is-active');
        } else {
            item.parent().children().first().addClass('is-active');
        }

        var item_content = $(this).parent().parent().find('.tabs-panel.is-active');
        item_content.removeClass('is-active');
        if( item_content.next().length ) {
            item_content.next().addClass('is-active');
        } else {
            item_content.parent().children().first().addClass('is-active');
        }
    });

    if( $('.integrations-detail-summary-icon').length ) {
        $(window).on( 'scroll resize load', function(){
            $window = $(window);
            var scrollTop = $(window).scrollTop();

            var top_of_element = $(".integrations-detail-summary-icon").offset().top;
            var bottom_of_element = $(".integrations-detail-summary-icon").offset().top + $(".integrations-detail-summary-icon").outerHeight();
            var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
            var top_of_screen = $(window).scrollTop();

            var max_width = 44 - (scrollTop / 20);

            if ((bottom_of_screen > top_of_element) && (top_of_screen < bottom_of_element)){
                $('.integrations-detail-summary-icon-hold').css('max-width', max_width + '%');
            }
        });
    }

    if( $('.cxat-page').length ) {
        $(window).on( 'load', function(){
            var item = $('.cxat-page-counter-list ul').find('.is-active');
            item.next().addClass('is-next');
            item.next().next().addClass('is-next-next');
        });

        function cxatLoadAnimations() {
            if( $('.cxat-intro-section-next').hasClass('active') ) {
                $('.cxat-intro-section-next.active .section-title-47').addClass('in-view');
                $('.cxat-intro-section-next.active .footer-cta-btns ul li').addClass('in-view');
            }
            if( $('.cxat-intro-section-last').hasClass('active') ) {
                $('.cxat-intro-section-last.active .section-title-47').addClass('in-view')
                $('.cxat-intro-section-last.active .section-text-18').addClass('in-view')
                $('.cxat-intro-section-last.active .cxat-intro-section-last-form').addClass('in-view')
            }
        }

        $('.cxat-start').on('click', function() {
            $(this).removeClass('active');
            $('.cxat-intro-section-next').first().addClass('active');
            $('.cxat-page-counter').addClass('active');

            setTimeout(function() {
                cxatLoadAnimations();
            }, 400);
        });

        $('.cxat-intro-section-next-trigger ul li').on('click', function() {
            var itemCounterNext = $('.cxat-page-counter-list ul').find('.is-active');
            $('.cxat-page-counter-list ul li').removeClass('is-next');
            $('.cxat-page-counter-list ul li').removeClass('is-next-next');
            $('.cxat-page-counter-list ul li').removeClass('is-prev');
            $('.cxat-page-counter-list ul li').removeClass('is-prev-prev');
            $('.cxat-page-counter-list ul li').removeClass('is-active');

            itemCounterNext.next().addClass('is-active');
            itemCounterNext.next().next().addClass('is-next');
            itemCounterNext.next().next().next().addClass('is-next-next');

            var itemCounterPrev = $('.cxat-page-counter-list ul').find('.is-active');
            itemCounterPrev.prev().addClass('is-prev');
            itemCounterPrev.prev().prev().addClass('is-prev-prev');

            var item = $(this).closest('.cxat-intro-section-next');

            if(item.next().length > 0 ) {
                item.removeClass('current');
                item.next().addClass('active current');
            } else {
                $('.cxat-intro-section-last').addClass('active current');
                $('.cxat-page-counter').removeClass('active current');
            }

            if( $('.cxat-intro-section-next.current').hasClass('cxat-intro-section-white') ) {
                $('.cxat-page-counter-list').addClass('cxat-page-counter-list-white');
            } else {
                $('.cxat-page-counter-list').removeClass('cxat-page-counter-list-white');
            }

            setTimeout(function() {
                cxatLoadAnimations();
            }, 400);
        });
    }

    if( $('.testimonials-landing-page-section-list').length ) {
        $('.testimonials-landing-page-section-list ul li').each(function(){
            var theRandomNumber = Math.floor(Math.random() * 4) - 2;
            $(this).find('.testimonials-landing-page-section-list-box').css({'transform' : 'rotate('+ theRandomNumber +'deg)'});
        });
    }

    $('.testimonials-landing-page-section-list ul li:lt(25)').show();
    var testimonials_items = $(".testimonials-landing-page-section-list ul li").length;
    if (testimonials_items <= 25) {
        $('.testimonials-more-trigger').hide();
    } else {
        $('.testimonials-more-trigger').show();
    }
    $('.testimonials-more-trigger').click(function () {
        var shown = $('.testimonials-landing-page-section-list ul li:visible').length + 25;
        if(shown< testimonials_items) {
		$('.testimonials-landing-page-section-list ul li:lt('+shown+')').show();
	} else {
		$('.testimonials-landing-page-section-list ul li:lt('+testimonials_items+')').show();
            $('.testimonials-more-trigger').hide();
        }
    });
    if( $('.animation-list-element.testimonials-landing-page-section-list').length ) {
        $('.animation-list-element.testimonials-landing-page-section-list').each(function(){
            $(this).find('ul li').each(function(i){
                $(this).find('.testimonials-landing-page-section-list-box').css('animation-delay', i*50 + 'ms');
            });
        });
    }

    $('.front-page-intro-video-hold-play').on('click', function(){
        $(this).addClass('active');
        if( $(this).find("video").length ) {
            $(this).find("video")[0].play();
        }
        if( $(this).find("iframe").length ) {
            $(this).find("iframe")[0].src += "?autoplay=1";
        }
    });

    if( $('.js-select-industry').length ) {
        console.log('ss');
        $('.js-select-industry').select2({
            placeholder: "Industry *",
            minimumResultsForSearch: Infinity,
        });
    }

    // animations
    // for in-view
    var $animation_elements = $('.animation-element');
    var $window = $(window);
    $vHeight = $(window).height();
    $vWidth = $(window).width();
    function check_if_in_view() {
        var window_height = $window.height();
        var window_top_position = $window.scrollTop();
        var window_bottom_position = (window_top_position + window_height);
        $.each($animation_elements, function() {
            var $element = $(this);
            var element_height = $element.outerHeight();

            var element_top_position = $element.offset().top + 100;

            var element_bottom_position = (element_top_position + element_height);
            if ((element_bottom_position >= window_top_position) &&
                (element_top_position <= window_bottom_position)) {
                $element.addClass('in-view');
            }
        });
    }
    $window.on('scroll resize', check_if_in_view);
    $window.trigger('scroll');
});