(function ($) {
    function sticky_header() {
        if ($('body').hasClass('sticky-header')) {
            var start_y = $('.top-header').innerHeight() + 60;
            var window_y = $(window).scrollTop();

            if (window_y > 10) {
                if (!($('#masthead').hasClass('is-sticky'))) {
                    $('#masthead .top-header').hide();
                    $('#masthead').addClass('is-sticky');
                }
            }
            else {
                if ($('#masthead').hasClass('is-sticky')) {
                    $('#masthead .top-header').show();
                    $('#masthead').removeClass('is-sticky');
                }
            }
        }
    }
    $(document).ready(function () {

        var example = $('.main-navigation .nav-menu').superfish();
        $('.main-navigation > div').meanmenu({
            meanScreenWidth: 991
        });

        //Issue for last menu with submenu
        $("ul.nav-menu li.menu-item-has-children").each(function () {
            var elm = $(this).children('ul');
            if (elm.length > 0) {
                var off = elm.offset();
                var l = off.left;
                var container_left = $('.container').offset().left;
                var container_width = $('.container').width();
                var w = elm.width();
                var isEntirelyVisible = (l + w <= container_width + container_left + 60);
                if (!isEntirelyVisible) {
                    $(this).addClass('edge');
                } else {
                    $(this).removeClass('edge');
                }
            }
        });

        $('#portfolio_slider').carouFredSel({
            responsive: true,
            auto: false,
            width: '100%',
            scroll: 1,
            prev: '#prevport-portfolio',
            next: '#nextport-portfolio',
            items: {
//                width: 400,
                visible: {
                    min: 1,
                    max: 3
                }
            }
        });
        $('#testimonial_slider').carouFredSel({
            responsive: true,
            auto: false,
            width: '100%',
            scroll: {fx: "crossfade"},
            pagination: "#paginatecircle",
            items: {
                width: 1100,
                visible: {
                    min: 1,
                    max: 1
                }
            }
        });
        /*----------------Go to top----------------------------*/
        $(".arrow-up").click(function () {
            $("html, body").animate({scrollTop: 0}, 1000);
        });

    });
    $('.our_client_div').slick({
        slidesToShow: 5,
        dots: true,
        slidesToScroll: 1,
        autoplay: true,
        autoplaySpeed: 2000,
        responsive: [
            {
                breakpoint: 1100,
                settings: {
                    slidesToShow: 4,
                    slidesToScroll: 1,
                    infinite: true,
                    dots: true
                }
            },
            {
                breakpoint: 1023,
                settings: {
                    slidesToShow: 3,
                    slidesToScroll: 1
                }
            },
            {
                breakpoint: 480,
                settings: {
                    slidesToShow: 2,
                    slidesToScroll: 1
                }
            },
            {
                breakpoint: 360,
                settings: {
                    slidesToShow: 1,
                    slidesToScroll: 1
                }
            }
        ]
    });
    //Issue for last menu with submenu
    $("ul.nav-menu li.menu-item-has-children").on('mouseenter mouseleave', function (e) {
        var elm = $(this).children('ul');
        var off = elm.offset();
        var l = off.left;
        var container_left = $('.container').offset().left;
        var container_width = $('.container').width();
        var w = elm.width();
        var isEntirelyVisible = (l + w <= container_width + container_left);
        if (!isEntirelyVisible) {
            $(this).addClass('edge');
        } else {
            $(this).removeClass('edge');
        }
    });

    /*---------------------script for GO TO TOP button--------------------*/

    $(window).scroll(function () {
        var scroll = $(window).scrollTop();
        if (scroll > 100) {
            $(".arrow-up").fadeIn();
        } else {
            $(".arrow-up").fadeOut();
        }

        if ($(window).width() > 1024) {
            var top_height = $('.top_header_wrap').height();
            if (scroll > top_height) {
                $("ul.nav-menu li.menu-item-has-children").each(function () {
                    var elm = $(this).children('ul');
                    if (elm.length > 0) {
                        var off = elm.offset();
                        var l = off.left;
                        var container_left = $('.container').offset().left;
                        var container_width = $('.container').width();
                        var w = elm.width();
                        var isEntirelyVisible = (l + w <= container_width + container_left + 60);
                        if (!isEntirelyVisible) {
                            $(this).addClass('edge');
                        }
                    }
                });
            }
        }
        if ($(window).width() > 767)
            sticky_header();
    });
})(jQuery);

/*-------Scrolling Effects-------*/
jQuery(function ($) {
    var $elems = $('.animateblock');
    var winheight = $(window).height();
    var fullheight = $(document).height();
    $elems.each(function () {
        var $elm = $(this);
        var topcoords = $elm.offset().top;
        if (topcoords < winheight) {
            // animate when top of the window is 3/4 above the element
            $elm.addClass('animated');
        }
    });
    $('.progress_inner').each(function () {
        if ($(this).offset().top < winheight)
        {
            var width = $(this).attr('data-width');
            $(this).animate({
                width: width
            }, 1000);
        }
    });
    $('.pie_progress').each(function () {
        if ($(this).offset().top < winheight)
        {
            $(this).asPieProgress('start');
        }
    });

    $(window).scroll(function () {
        animate_elems();
    });

    function animate_elems() {
        var wintop;
        wintop = $(window).scrollTop(); // calculate distance from top of window

        // loop through each item to check when it animates
        $elems.each(function () {
            var $elm = $(this);
            if ($elm.hasClass('animated')) {
                return true;
            } // if already animated skip to the next item
            var topcoords = $elm.offset().top; // element's distance from top of page in pixels
            if (wintop > (topcoords - (winheight * 0.9))) {
                // animate when top of the window is 3/4 above the element
                $elm.addClass('animated');
            }
        });
        $('.progress_inner').each(function () {
            if (wintop > $(this).offset().top - winheight)
            {
                var width = $(this).attr('data-width');
                $(this).animate({
                    width: width
                }, 500);
            }
        });
    }
});
/* --------------- Scrolling Effects end ------------ */
jQuery(window).load(function ($) {
    /* ------------Portfolio isotop effect start------------------ */
    var transitionDuration = 200;
    var columnWidth = 400;
    var $container = jQuery('.isotope').isotope({
        itemSelector: '.portfolio_single',
        containerStyle: {
            position: 'relative',
            overflow: 'visible'
        },
        getSortData: {
            category: '[data-category]'
        }
    });

    jQuery('#category_menu_ul li a').removeClass('category_menu_selected');
    var current_cat_with_hash = window.location.hash;
    if (current_cat_with_hash != '')
    {
        var cat_slug_arr = current_cat_with_hash.split('#');
        var cat_slug = cat_slug_arr[1];
        jQuery('.' + cat_slug + ' a').addClass('category_menu_selected');
        if (cat_slug == 'show_all')
        {
            console.log();
        }
        else
        {
            $container.isotope({filter: '.' + cat_slug});
            jQuery('.page-numbers').each(function () {
                var cur_link = jQuery(this).attr('href');
                if (typeof cur_link !== typeof undefined && cur_link !== false) {
                    var pag_l = jQuery(this).attr('href').split('#');
                    if (pag_l != '')
                    {
                        jQuery(this).attr('href', pag_l[0] + current_cat_with_hash);
                    }
                    else
                    {
                        jQuery(this).attr('href', cur_link + current_cat_with_hash);
                    }
                }
                else
                {
                    jQuery(this).attr('href', current_cat_with_hash);
                }
            });
        }
    }
    else
    {
        jQuery('.show_all a').addClass('category_menu_selected');
    }
    jQuery('#category_menu_ul').on('click', 'li', function () {
        jQuery('#category_menu_ul li a').removeClass('category_menu_selected');
        jQuery(this).children('a').addClass('category_menu_selected');
        var filterValue = jQuery(this).attr('data-filter');
        var curclass = jQuery(this).attr('class');
        window.location.hash = curclass;
        $container.isotope({filter: filterValue});

        var page_q = jQuery(this).children('a').attr('href');
        jQuery('.page-numbers').each(function () {
            var cur_link = jQuery(this).attr('href');
            if (typeof cur_link !== typeof undefined && cur_link !== false) {
                var pag_l = jQuery(this).attr('href').split('#');
                if (pag_l != '')
                {
                    jQuery(this).attr('href', pag_l[0] + page_q);
                }
                else
                {
                    jQuery(this).attr('href', cur_link + page_q);
                }
            }
            else
            {
                jQuery(this).attr('href', page_q);
            }
        });
    });
    function layoutTimer() {
        setTimeout(function () {
            $container.isotope('layout');
        }, transitionDuration);

    }
    layoutTimer();
    jQuery(window).resize(function () {
        layoutTimer();
    });

    /* ------------Portfolio isotop effect end------------------ */
    /*Our team start*/
    var $container1 = jQuery('.isotope1').isotope({
        itemSelector: '.team_single',
        containerStyle: {
            position: 'relative',
            overflow: 'visible'
        },
        getSortData: {
            category: '[data-category]'
        }
    });

    jQuery('#ourteam_category_menu_ul li a').removeClass('category_menu_selected');
    var current_cat_with_hash_team = window.location.hash;
    if (current_cat_with_hash_team != '')
    {
        var cat_slug_arr_1 = current_cat_with_hash_team.split('#');
        var cat_slug_1 = cat_slug_arr_1[1];
        jQuery('.' + cat_slug_1 + ' a').addClass('category_menu_selected');
        if (cat_slug_1 == 'show_all')
        {
            console.log();
        }
        else
        {
            $container1.isotope({filter: '.' + cat_slug_1});
        }
    }
    else
    {
        jQuery('.show_all a').addClass('category_menu_selected');
    }

    jQuery('#ourteam_category_menu_ul').on('click', 'li', function () {
        jQuery('#ourteam_category_menu_ul li a').removeClass('category_menu_selected');
        jQuery(this).children('a').addClass('category_menu_selected');
        var filterValue_1 = jQuery(this).attr('data-filter');
        var curclass_1 = jQuery(this).attr('class');
        window.location.hash = curclass_1;
        $container1.isotope({filter: filterValue_1});
    });
    function layoutTimer1() {
        setTimeout(function () {
            $container1.isotope('layout');
        }, transitionDuration);

    }
    layoutTimer1();
    jQuery(window).resize(function () {
        layoutTimer1();
    });
    /*Our team end*/
});