$(document).ready(function(){

    //Sticky Navbar
    $(function () {
        $(window).on('load scroll', function () {
            if ($(window).scrollTop() >= 50) {
                $(".change").css({
                    "background": "white",
                    "boxShadow": "0px 4px 9px #ccc",
                    "min-height": "50px"
                });
                $(".nav-link").css("display", "none");
                $(".change .form-group").css("display", "none");
                $(".change .btn-search").css("display", "none");
                $(".change .btn-toggler").css("display", "none");
            }
            else {
                $(".change").css({
                    "background": "transparent",
                    "boxShadow": "0px 0px 0px"
                });
                $(".nav-link").css("display", "block");
                $(".change .form-group").css("display", "block");
                $(".change .btn-search").css("display", "block");
                $(".change .btn-toggler").css("display", "block");

            }
        });
    });


    // Scroll To Top Button
            $(window).scroll(function() {
                var scroll = $(window).scrollTop();
                if (scroll >= 200) {
                    // Scroll to top button
                    $('#scroll-top').fadeIn(1000);
                } else {
                    // Scroll to top button
                    $('#scroll-top').fadeOut(1000);
                }
            });
        $('#scroll-top').click(function(e) {
            e.preventDefault();
            $('html, body').animate({
                scrollTop: 0
            }, 500)
        });

    // Chat Messenger

        $('.open-button').click(function () {
            $('.chat-popup').slideToggle();
        });

/*
    // Tag Button
    $(window).scroll(function() {
        var scroll = $(window).scrollTop();
        if (scroll >= 200) {
            $('#tag').fadeIn(1000);
        } else {
            $('#tag').fadeOut(1000);
        }
    });
*/


 // Loading Page

        $("body").css("overflow", "auto"),
        $(".loading-screen").fadeOut(3000, function () {

                $(".img").fadeOut(2500, function () {});
        });



    // Adjust Active Class

    $('.navbar-light .navbar-nav .nav-link').filter(function(){return this.href==location.href}).addClass('active').siblings().removeClass('active')
            $('.navbar-nav .nav-link').click(function(){
                $(this).addClass('active').siblings().removeClass('active');
            });





    // Trigger ScrollMagic

    // init controller
var controller = new ScrollMagic.Controller();

$('.fade').each(function(){

    // create a scene
var ourScene = new ScrollMagic.Scene({
    triggerElement: this,
      //triggerHook: 0.9
    })
    .setClassToggle(this, 'fade-in') // add class
    .addTo(controller); // assign the scene to the controller
});


//Counter Section

    $('.count').each(function () {
        var $this = $(this);
        jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
        duration: 10000,
        easing: 'swing',
        step: function () {
            $this.text(Math.ceil(this.Counter));
        }
        });
    });

    function animateNumber(ele,no,stepTime){
        $({someValue: 0}).animate({someValue: no}, {
                duration: stepTime,
                step: function() { // called on every step. Update the element's text with value:
                    ele.text(Math.floor(this.someValue+1));
                },
                complete : function(){
                    ele.text(no);
                }
        });
        }
    animateNumber($('.count'), 100, 1000)





    // Search Icon

    $('#search').focus(function () {
        $(this).parent().removeClass('flaticon-loupe');
    });

    $('#search').blur(function () {
        $(this).parent().addClass('flaticon-loupe');
    });


});
