$(document).ready(function() {
    $(document).foundation();
    var headerHeight;
    $('.search span.search-top').on('click', function() {
        event.stopPropagation();
        $('#search-block').animate({
            width: "toggle"
        });
    });

    $('#search-block').submit(function() {
        if ($.trim($("#search-block #search").val()) === "") {
            $(this).animate({
                width: "toggle"
            });
            return false;
        }
    });

    function navHeight(hdHeight) {
        $('nav ul.vertical.menu').css({
            'height': 'calc(100% - ' + hdHeight + 'px)'
        });
    };
    headerHeight = $('header').outerHeight();
    navHeight(headerHeight);
    $('body').css({
        'paddingTop': headerHeight
    });

    $('.to-next i.icon-Banner-mouse').on('click', function() {
        var nextDiv = $(this).parents('.carousel').next();
        $('html,body').animate({
            scrollTop: $(nextDiv).offset().top - $('header').outerHeight()
        }, 500)
    });

    $('.navigation ').css({
        marginTop: headerHeight,
        transition: 'all 0.5s ease'
    });
    window.addEventListener("orientationchange", function(e) {
        window.setTimeout(function() {
            headerHeight = $('header').outerHeight();
            $('body').css({
                'paddingTop': headerHeight
            });
            $('.navigation ').css({
                marginTop: headerHeight
            });
            navHeight(headerHeight);
        }, 600);
    });

    $('.overview-column ').hoverdir({
        speed: 500,
    });
    $('header .login>a.button').click(function(e) {
        e.preventDefault();
        $(this).toggleClass('active');
        $('header .form-wrap').slideToggle();
    });

    function mobileMenuAdj() {
        $(window).scroll(function() {
            var scroll = $(window).scrollTop();
            if (scroll >= 300) {
                $("header").addClass("small");
                $('.navigation ').css({
                    marginTop: $('header').outerHeight()
                });

            } else {
                $("header").removeClass("small");
                $('.navigation ').css({
                    marginTop: headerHeight
                });

            }
        });
    }

    $(window).on('changed.zf.mediaquery', function(event, newSize, oldSize) {
        if (Foundation.MediaQuery.atLeast('medium')) {
            mobileMenuAdj();
            navHeight(headerHeight);
        }
    });

    if (Foundation.MediaQuery.atLeast('medium')) {
        mobileMenuAdj();
        navHeight(headerHeight);
    }
    $('.count').countUp({
        delay: 10,
        time: 2000
    });

    function scrollTo() {
        var child = $('.smooth-scroll');
        child.on('click', function(e) {
            e.preventDefault();
            var secId = $(this).attr('href');
            $('html,body').animate({
                scrollTop: $(secId).offset().top - $('header').outerHeight()
            }, 1500);
        });
    };

    scrollTo();

    $('.client-list').owlCarousel({
        loop: true,
        margin: 60,
        nav: false,
        responsive: {
            0: {
                items: 1,
                margin: 0
            },
            420: {
                items: 2,
                margin: 10
            },
            600: {
                items: 3,
                margin: 20
            },
            1000: {
                items: 4,
                margin: 40
            },
            1200: {
                items: 5
            }
        }
    });

});