(function ($) {

  $('.popup-youtube, .popup-vimeo').magnificPopup({
    // disableOn: 700,
    type: 'iframe',
    mainClass: 'mfp-fade',
    removalDelay: 160,
    preloader: false,
    fixedContentPos: false
  });
  
  $('.banner_text').slick({
    vertical:true,
    verticalSwiping:true,
    slidesToShow: 1,
    slidesToScroll: 1,
    autoplay: true,
    arrows: true,
    autoplaySpeed: 10000,
    pauseOnHover: true,
    pauseOnHover: true,
    touchMove: true,
    verticalSwiping: true,
    prevArrow: $('.prev'),
    nextArrow: $('.next'),
  });



  // mainslider_slider js code
 var mainslider = $('.mainslider_slider');
  if (mainslider.length) {
    mainslider.owlCarousel({
      items: 1,
      loop: true,
      dots: false,
      autoplay: true,
      autoplayHoverPause: true,
      autoplayTimeout: 5000,
      nav: true,
      smartSpeed:500,
      navText: [
        '<i class="ti-angle-left"></i>',
        '<i class="ti-angle-right"></i>'
      ],
      responsive: {
        0: {
          nav: false,
        },
        768: {
          nav: true,
        },
        992: {
          nav: true,
        }
      }
    });
  }
  
  

  // service_slider js code
  var service = $('.service_slider');
  if (service.length) {
    service.owlCarousel({
      items: 1,
      loop: true,
      dots: false,
      autoplay: true,
      autoplayHoverPause: true,
      autoplayTimeout: 5000,
      nav: true,
      smartSpeed:500,
      navText: [
        '<i class="ti-angle-left"></i>',
        '<i class="ti-angle-right"></i>'
      ],
      responsive: {
        0: {
          nav: false,
        },
        768: {
          nav: true,
        },
        992: {
          nav: true,
        }
      }
    });
  }
  // project_slider js code
  var project = $('.project_slider');
  if (project.length) {
    project.owlCarousel({
      items: 1,
      loop: true,
      dots: false,
      autoplay: true,
      autoplayHoverPause: true,
      autoplayTimeout: 5000,
      nav: true,
      smartSpeed: 500,
      navText: [
        '<i class="flaticon-left-arrow"></i>',
        '<i class="flaticon-right-arrow"></i>'

      ],
      responsive: {
        0: {
          nav: false,
        },
        768: {
          nav: true,
        },
        992: {
          nav: true,
        }
      }
    });
  }
  // blog_slider js code
  var single_page = $('.single_page_special_item');
  if (single_page.length) {
    single_page.owlCarousel({
      items: 4,
      loop: true,
      dots: false,
      autoplay: true,
      autoplayHoverPause: true,
      autoplayTimeout: 5000,
      nav: true,
      smartSpeed: 500,
      navText: [
        '<i class="flaticon-left-arrow"></i>',
        '<i class="flaticon-right-arrow"></i>'

      ],
      responsive: {
        0: {
          nav: false,
          items: 1
        },
        576:{
          items: 1
        },
        768: {
          nav: true,
          items: 2
        },
        992: {
          nav: true,
          items: 3
        },
        1200: {
          nav: true,
          items: 3
        }
      }
    });
  }

  // blog_post_slider js code
  // var blog = $('.blog_post_slider');
  // if (blog.length) {
  //   blog.owlCarousel({
  //     items: 1,
  //     loop: true,
  //     dots: false,
  //     autoplay: false,
  //     autoplayHoverPause: true,
  //     autoplayTimeout: 5000,
  //     nav: true,
  //     smartSpeed: 2000,
  //     navText: [
  //       '',
  //       'NEXT'


  //     ]
  //   });
  // }


  $('.blog_post_slider').on('initialized.owl.carousel changed.owl.carousel', function (e) {
    if (!e.namespace) {
      return;
    }
    var carousel = e.relatedTarget;
    $('.slider-counter').text(carousel.relative(carousel.current()) + 1 + '/' + carousel.items().length);
  }).owlCarousel({
    items: 1,
    loop: true,
    dots: false,
    autoplay: true,
    autoplayHoverPause: true,
    autoplayTimeout: 5000,
    nav: true,
    smartSpeed: 500,
    navText: [
      '',
      'NEXT'


    ]
  });
  // map js code
  var map = $('.map');
  if (map.length) {
    $('.map')
      .gmap3({
        center: [40.740, -74.18],
        zoom: 12
      })
  }
  // menu fixed js code'
  var scroll_element='.mb-content'
  
  
  //screen width
  var screen_type='';
  
      if (window.matchMedia("(max-width: 413px)").matches) { 
            
            // The viewport is less than 413 pixels wide 
			scroll_element='#document';
			screen_type='extra_extra_small';
			//alert("tablet");
        
		}else if (window.matchMedia("(max-width:575px)").matches){

			// The viewport is less than 575 pixels wide 
			scroll_element='#document';
			screen_type='extra_small';
			//alert("tablet");

			
		}else if (window.matchMedia("(max-width:767px)").matches){
		
			// The viewport is less than 767 pixels wide 
			scroll_element='#document';
			screen_type='small';
			//alert("tablet");		
		
		
		}else if (window.matchMedia("(max-width:991px)").matches){
		
			// The viewport is less than 992 pixels wide 
			scroll_element='#document';
			screen_type='meduim';
			//alert("tablet");		
		
		
		}else if (window.matchMedia("(max-width:1199px)").matches){
		
			// The viewport is less than 1199 pixels wide 
			scroll_element='#document';
			screen_type='large';
			//alert("tablet");		
		
		
		} else { 
            
            // The viewport is more than 1199 pixels wide 
			scroll_element='#document';
			screen_type='extra_large';
			//alert("tablet");	
        }
		


  //alert(scroll_element);
  
  //alert($(".blog_right_sidebar").height());
  
   var fixed_left_menu=parseInt($(".blog_right_sidebar").height());
   var end_fixed=parseInt($(".posts-list").height());
  
  var lastScrollTop = 0;
  var current_scroll=0;
  var is_up=0;
  var is_down=0;
  
  
  //alert($(".share_part").scrollTop());
  	current_scroll =   $(window).scrollTop();
	if(current_scroll >0){
		$('.main_menu').removeClass('fadeInDown').addClass("fadeOutUp");
	}
	
	
	
	
	
  $(window).scroll(function () {
	current_scroll = $(this).scrollTop();
	//alert($(window).width());

//ثبيت العمود الايسر
	if(current_scroll>=fixed_left_menu && current_scroll<end_fixed && $(window).width() > 991){
		
		$(".blog_right_sidebar").addClass("fixed_left_menu");
		
	}else{
		
		$(".blog_right_sidebar").removeClass("fixed_left_menu");
	}
	 
    if ( current_scroll < lastScrollTop) {
		
				//alert("up");
				$('.main_menu').addClass('show');
				
				if(current_scroll<=200){
					$('.main_menu').removeClass('fadeOutUp').addClass('fadeInDown').removeClass('fixed_menu').addClass('absolute_menu');
					$("#to_top").fadeOut();
					
				}else{
					$('.main_menu').removeClass('fadeOutUp').addClass('fadeInDown').addClass('fixed_menu').removeClass('absolute_menu');
				}
				

				
		
    } else {
		
			//alert("down");
			
			if( current_scroll>200 && $('.main_menu').hasClass('fadeInDown'))  {
				
				$('.main_menu').removeClass('fadeInDown').addClass("fadeOutUp").addClass('absolute_menu').removeClass('fixed_menu');
				$('.main_menu').removeClass('show');
				
				if (screen_type=='mobile'){
					$("#to_top").fadeIn();
				}
			}
		 }
   
	
	
		if(current_scroll<200){
			
			$(".logo").find('img').removeAttr("style");
			
			if (screen_type=='extra_extra_small'){
			
			$(".main_menu span.menu-trigger").css("margin-top","5px");
			$(".search_icon").css("margin-top","0px");
			
			}else if (screen_type=='extra_small'){
				
			$(".main_menu span.menu-trigger").css("margin-top","5px");
			$(".search_icon").css("margin-top","0px");
			
			}else if (screen_type=='small'){
				
			$(".main_menu span.menu-trigger").css("margin-top","5px");
			$(".search_icon").css("margin-top","0px");
			
			}else if (screen_type=='meduim'){
				
			$(".main_menu span.menu-trigger").css("margin-top","5px");
			$(".search_icon").css("margin-top","0px");
			
			}else if (screen_type=='large'){
				
			$(".main_menu span.menu-trigger").css("margin-top","5px");
			$(".search_icon").css("margin-top","0px");
			
			}else{
			$(".main_menu span.menu-trigger").css("margin-top","5px");
			$(".search_icon").css("margin-top","0px");
				
			}
			
			
		}else{
			
			
			if (screen_type=='extra_extra_small' || screen_type=='extra_small' || screen_type=='small' || screen_type=='meduim' ){
				$(".logo").find('img').css({"height":"55px","margin-top":"9px","margin-bottom": "0px"});
				$(".main_menu span.menu-trigger").css("margin-top","5px");
				$(".search_icon").css("margin-top","2px");
			}else{
				$(".logo").find('img').css({"height":"60px","margin-top":"5px","margin-right":"10px","margin-bottom":"0px"});
				$(".main_menu span.menu-trigger").css("margin-top","5px");
				$(".search_icon").css("margin-top","5px");
			}

		
		}
	
	lastScrollTop = current_scroll;
	
  });

  // Search Toggle
  $("#search_input_box").hide();
  $("#search_1").on("click", function () {
    $("#search_input_box").slideToggle();
    $("#search_input").focus();
  });
  $("#close_search").on("click", function () {
    $('#search_input_box').slideUp(500);
  });


  //memnu js
  jQuery(document).ready(function ($) {
    $(".menu-trigger").on('click', function () {
      $(".off-canven-menu").addClass("active");
      $(".offcanvas-overlay").addClass("active")
	  
    });
    $(".close-icon i, .offcanvas-overlay").on('click', function () {
      $(".off-canven-menu").removeClass("active");
      $(".offcanvas-overlay").removeClass("active")
    });
  
  });

  //gallery js
  $('.grid').masonry({
    itemSelector: '.grid-item',
    columnWidth: '.grid-sizer',
    percentPosition: true
  });
  
  $('.gallery').each(function() { // the containers for all your galleries
    $(this).magnificPopup({
        delegate: 'a', // the selector for gallery item
        type: 'image',
        gallery: {
          enabled:true
        }
    });
});

//------- Mailchimp js --------//  
function mailChimp() {
  $('#mc_embed_signup').find('form').ajaxChimp();
}
mailChimp();


}(jQuery));