(function($) {
    'use strict';
    /*meanmenu js for responsive menu*/
    jQuery('.main-navigation').meanmenu({
        meanMenuContainer: '.hgroup-wrap .navbar',
        meanScreenWidth: "992",
        meanRevealPosition: "right",
    });
	
	//keyboard navigation for mean menu
		var myEvents = {
		click: function(e) {
		  if ( jQuery(this).hasClass('menu-item-has-children') ) {
			jQuery(this).find('.mean-expand').addClass('mean-clicked').text('-');
		  }
		  jQuery(this).siblings('li').find('.mean-expand').removeClass('mean-clicked').text('+');
		  jQuery(this).children('.sub-menu').show().end().siblings('li').find('ul').hide();

		},

		keydown: function(e) {
		  e.stopPropagation();

		  if (e.keyCode == 9) {


			if (!e.shiftKey &&
			  ( jQuery('.mean-bar li').index( jQuery(this) ) == ( jQuery('.mean-bar li').length-1 ) ) ){
				jQuery('.meanclose').trigger('click');
			}  else if( jQuery('.mean-bar li').index( jQuery(this) ) == 0 ) {
			  $('.meanclose').removeClass('onfocus');
			}
			else if (e.shiftKey && jQuery('.mean-bar li').index(jQuery(this)) === 0)
			 jQuery('.mean-bar ul:first > li:last').focus().blur();
		  }else if('.meanmenu-reveal.meanclose'){
					 jQuery('.meanclose').trigger('click');
					 }
		},

		keyup: function(e) {
		  e.stopPropagation();
		  if (e.keyCode == 9) {
			if (myEvents.cancelKeyup) myEvents.cancelKeyup = false;
			else myEvents.click.apply(this, arguments);
		  }
		}
	  }
		jQuery(document)
		.on('click', 'li', myEvents.click)
		.on('keydown', 'li', myEvents.keydown)
		.on('keyup', 'li', myEvents.keyup);

	  jQuery('.mean-bar li').each(function(i) { this.tabIndex = i; });
    /* back-to-top button */
    jQuery('.back-to-top').hide();
    jQuery('.back-to-top').on("click", function(e) {
        e.preventDefault();
        jQuery('html, body').animate({
            scrollTop: 0
        }, 'slow');
    });
    jQuery(window).scroll(function() {
        var scrollheight = 400;
        if (jQuery(window).scrollTop() > scrollheight) {
            jQuery('.back-to-top').fadeIn();

        } else {
            jQuery('.back-to-top').fadeOut();
        }
    });
    /*counter section*/
    jQuery('.counter-count').each(function() {
        jQuery(this).prop('Counter', 0).animate({
            Counter: jQuery(this).text()
        }, {
            duration: 4000,
            easing: 'swing',
            step: function(now) {
                jQuery(this).text(Math.ceil(now));
            }
        });
    });
    /*featured banner slider*/
    jQuery('.layout-1 .featured-banner').slick({
        slidesToShow: 1,
        dots: false,
        arrows: true
    });
    jQuery('.layout-2 .featured-banner').slick({
        slidesToShow: 1,
        dots: true,
        arrows: false
    });
    jQuery('.post-content-wrap').slick({
        slidesToShow: 1,
        dots: false,
        arrows: true
    });
    /*hoverdir js */
    $('.gallery-section .gallery-item , .work-item').hoverdir();

    /* search toggle */
    $(".search-toggle").on("click", function() {
        $(".search-section").toggleClass("search-active");
		$('.search-section .search-field').focus();
		 
    });
	$(document).on('keyup', function(e){
        if ( e.keyCode === 27 && $('.search-section').hasClass('search-active') ) {
            $(".search-section").removeClass('search-active');
        }
//         removeClass = true;
    }); 
    /*scroll to go down to site-content*/
    jQuery(".scroll-down").on('click', function() {
        jQuery('html, body').animate({
            scrollTop: jQuery(".hgroup-wrap").offset().top
        }, 1000);
    });
    /*testimonial carousel*/
    jQuery('.testimonial-wrap').slick({
        slidesToShow: 1,
        slidesToScroll: 1,
        dots: false,
        arrows: true,
        centerMode: true,
        focusOnSelect: true,
        centerPadding: 0
    });
    /*.partner-wrap carousel*/
    jQuery('.partner-wrap').slick({
        slidesToShow: 5,
        slidesToScroll: 1,
        dots: false,
        arrows: true,
        centerMode: false,
        focusOnSelect: true,
        centerPadding: 0,
        responsive: [
        {
          breakpoint: 1024,
          settings: {
            slidesToShow: 4
          }
        },
        {
          breakpoint: 600,
          settings: {
            slidesToShow: 2
          }
        },
        {
          breakpoint: 480,
          settings: {
            slidesToShow: 1
          }
        }
      ]
    });
    /*.instagram-wrap carousel*/
    jQuery('.instagram-wrap').slick({
        slidesToShow: 7,
        slidesToScroll: 1,
        dots: false,
        arrows: true,
        centerMode: false,
        focusOnSelect: true,
        centerPadding: 0,

        responsive: [
        {
          breakpoint: 1024,
          settings: {
            slidesToShow: 5
          }
        },
        {
          breakpoint: 600,
          settings: {
            slidesToShow: 3
          }
        },
        {
          breakpoint: 480,
          settings: {
            slidesToShow: 1
          }
        }
      ]
    });
    /*initializing wow.js for animation*/
    new WOW().init({
        offset: 0
    });
    /*for pop up video*/
    jQuery('.popup-video').magnificPopup({
        disableOn: 700,
        type: 'iframe',
        mainClass: 'mfp-fade',
        removalDelay: 160,
        preloader: false,
        fixedContentPos: false
    });
    /*pop up of gallery sections*/
    $('.gallery').magnificPopup({
        delegate: 'a',
        type: 'image',
        tLoading: 'Loading image #%curr%...',
        mainClass: 'mfp-img-mobile',
        gallery: {
            enabled: true,
            navigateByImgClick: true,
            preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
        },
        image: {
            tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
            titleSrc: function(item) {
                return item.el.attr('title');
            }
        }
    });
    // tab js
    $('.member-tabs-option .member-title').on("click", function() {
        var tab_id = $(this).attr('data-tab');
        $('.member-tabs-option .member-title').removeClass('current');
        $('.member-section-wrap .member-wrap').removeClass('current');
        $(this).addClass('current');
        $("." + tab_id).addClass('current');
    });

    $('.about-tab-wrap .tab-title').on("click", function() {
        var tab_id = $(this).attr('data-tab');
        $('.about-tab-wrap .tab-title').removeClass('current');
        $('.about-tab-wrap .tab-content').removeClass('current');
        $(this).addClass('current');
        $("." + tab_id).addClass('current');
    });
    /*button for adding active class and removing */
    $(".filters-button-group li ").on( 'click', function() {
        $(".filters-button-group  li.active").removeClass("active"), 
        $(this).addClass("active")
    });
    $(".work-filters-button li ").on( 'click', function() {
        $(".work-filters-button  li.active").removeClass("active"), 
        $(this).addClass("active")
    });
    /*----------------------------------------------------
    fixed-flower-left and fixed-flower-right 
    disappear when reached to footer while scrolling page
    for home layout 2
    -----------------------------------------------------*/
    jQuery(window).scroll(function() {
        var footerTop =$('.site-footer').offset().top;
        var height = $('.site-footer').outerHeight();
        if (jQuery(window).scrollTop() > footerTop - height/2) {
            jQuery('.fixed-flower-left, .fixed-flower-right').fadeOut();
        } else {
            jQuery('.fixed-flower-left, .fixed-flower-right').fadeIn();
        }
    });
    /*-----------for sticky sidebar------------------*/
    jQuery('#primary, .widget-area-right , .widget-area-left').theiaStickySidebar({
      additionalMarginTop: 30
    });
})(jQuery);


