(function ($) {

	"use strict";

	// Window Resize Mobile Menu Fix
	mobileNav();
	welcomeFix();


	// Scroll animation init
	window.sr = new scrollReveal();


	// // Welcome area init
	if ($('.owl-carousel').length) {
		var welcomeSlider = $(".owl-carousel");
		welcomeSlider.owlCarousel({
			loop: true,
			margin: 10,
			nav: false,
			margin: 30,
			autoplay: true,
			autoplayTimeout: 4000,
			autoplayHoverPause: true,
			responsive: {
				0: {
					items: 1.5
				},
				600: {
					items: 2.5
				},
				1000: {
					items: 2.5
				}
			}
		});

		checkClasses();
		welcomeSlider.on('translated.owl.carousel', function (event) {
			checkClasses();
		});

		function checkClasses() {
			var total = $('.owl-carousel .owl-stage .owl-item.active').length;

			$('.owl-carousel .owl-stage .owl-item').removeClass('firstActiveItem');

			$('.owl-carousel .owl-stage .owl-item.active').each(function (index) {
				if (index === 0) {
					$(this).addClass('firstActiveItem');
				}
			});
		}

		$('.base .prev').on('click', function () {
			welcomeSlider.trigger('prev.owl.carousel');
		});

		$('.base .next').on('click', function () {
			welcomeSlider.trigger('next.owl.carousel');
		});
	}


	// Menu Dropdown Toggle
	if ($('.menu-trigger').length) {
		$(".menu-trigger").on('click', function () {
			$(this).toggleClass('active');
			$('.header-area .nav').slideToggle(200);
		});
	}


	// About me progressbar
	if ($('.skill-wrapper').length) {
		$('.skill-wrapper .skill-item').each(function (index) {
			var val = $(this).find('.line').data('value');
			$(this).find('.line').css('width', val);
		});
	}


	// Home number counterup
	if ($('.count-item').length) {
		$('.count-item strong').counterUp({
			delay: 10,
			time: 1000
		});
	}


	// Blog cover image
	if ($('.blog-post-single').length) {
		$('.blog-post-single').imgfix();
	}


	// Blog grid cover image
	if ($('.blog-post-grid').length) {
		$('.blog-post-grid').imgfix();
	}


	// Sidebar contact banner image
	if ($('.sidebar .box').length) {
		$('.sidebar .box').imgfix();
	}


	// Project grid cover image
	if ($('.project-grid-item').length) {
		$('.project-grid-item .img').imgfix();
	}


	// Project list cover image
	if ($('.project-list-item').length) {
		$('.project-list-item .img').imgfix();
	}


	// Page standard gallery
	if ($('.page-gallery').length && $('.page-gallery-wrapper').length) {
		$('.page-gallery').imgfix({
			scale: 1.1
		});

		$('.page-gallery').magnificPopup({
			type: 'image',
			gallery: {
				enabled: true
			},
			zoom: {
				enabled: true,
				duration: 300,
				easing: 'ease-in-out',
			}
		});
	}


	// Youtube Player
	if ($('.play').length) {
		$('.play').magnificPopup({
			disableOn: 700,
			type: 'iframe',
			mainClass: 'mfp-fade',
			removalDelay: 160,
			preloader: false,
			fixedContentPos: false
		});
	}


	// Page loading animation
	$(window).on('load', function () {
		if ($('.cover').length) {
			$('.cover').parallax({
				imageSrc: $('.cover').data('image'),
				zIndex: '1'
			});
		}

		$(".preloader-wrapper").animate({
			'opacity': '0'
		}, 600, function () {
			setTimeout(function () {
				// Home Parallax
				if ($('.parallax-image').length) {
					$('.parallax-image').parallax({
						imageSrc: 'assets/images/banner-bg-3.jpg',
						zIndex: '1'
					});
				}

				// Home Parallax Counterup
				if ($('.parallax-counter').length) {
					$('.parallax-counter').parallax({
						imageSrc: 'assets/images/banner-bg-3.jpg',
						zIndex: '1'
					});
				}
				$(".preloader-wrapper").css("visibility", "hidden").fadeOut();
			}, 300);
		});
	});


	// Window Resize Mobile Menu Fix
	$(window).on('resize', function () {
		mobileNav();
		welcomeFix();
	});


	// Window Resize Mobile Menu Fix
	function mobileNav() {
		var width = $(window).width();
		$('.submenu').on('click', function () {
			if (width < 992) {
				$('.submenu ul').removeClass('active');
				$(this).find('ul').toggleClass('active');
			}
		});
	}


	// Welcome area set position
	function welcomeFix() {
		if ($('.welcome').length) {
			var height = $(window).height();
			var wwidth = $(window).width();

			if (wwidth > 992) {
				$('.welcome').css('height', height);
				var sliderPosition = ($('.slider-position').offset().left);

				$('.slider-wrapper').css({
					'left': sliderPosition,
					'width': wwidth - sliderPosition,
					'position': 'absolute'
				});
			} else {
				$('.welcome').css('height', 'auto');
				$('.slider-wrapper').css({
					'left': '0px',
					'width': '100%',
					'position': 'relative'
				});
			}
		}
	}

	// feature card slider

	$('.slider-product').slick({
		slidesToShow: 4,
		sliderToScroll: 1,
		dots: true,
		loop: true,
		speed: 800,
		autoplay: true,
		autoplaySpeed: 2000,
		arrows: false,
		centerMode: false,
		grabCursor: true,
		responsive: [
			{
				breakpoint: 1024,
				settings: {
					slidesToShow: 3,
				}
			},
			{
				breakpoint: 600,
				settings: {
					slidesToShow: 2,
				}
			},
			{
				breakpoint: 480,
				settings: {
					slidesToShow: 1,
				}
			}
		]
	});

	// Gallery slider
	var swiper = new Swiper(".mySwiper", {
		loop: true,
		speed: 800,
		slidesPerView: 2, // or 'auto'
		grabCursor: true,
		centeredSlides: true,
		effect: 'coverflow', // 'cube', 'fade', 'coverflow',
		coverflowEffect: {
			rotate: 50, // Slide rotate in degrees
			stretch: 0, // Stretch space between slides (in px)
			depth: 100, // Depth offset in px (slides translate in Z axis)
			modifier: 1, // Effect multipler
			slideShadows: true, // Enables slides shadows
		},
		autoplay: {
			delay: 2500,
			disableOnInteraction: false,
		},
		pagination: {
			el: ".swiper-pagination",
		},
		breakpoints: {
			640: {
				slidesPerView: 2,
				//   spaceBetween: 20,
			},
			320: {
				  spaceBetween: 10,

			}
		},
	});

	const inputs = document.querySelectorAll(".input");

	function focusFunc() {
		let parent = this.parentNode;
		parent.classList.add("focus");
	}

	function blurFunc() {
		let parent = this.parentNode;
		if (this.value == "") {
			parent.classList.remove("focus");
		}
	}

	inputs.forEach((input) => {
		input.addEventListener("focus", focusFunc);
		input.addEventListener("blur", blurFunc);
	});

	// Navbar
	$("<span class='clickD'></span>").insertAfter(".navbar-nav li.menu-item-has-children > a");
	$('.navbar-nav li .clickD').click(function (e) {
		e.preventDefault();
		var $this = $(this);
		if ($this.next().hasClass('show')) {
			$this.next().removeClass('show');
			$this.removeClass('toggled');
		}
		else {
			$this.parent().parent().find('.sub-menu').removeClass('show');
			$this.parent().parent().find('.toggled').removeClass('toggled');
			$this.next().toggleClass('show');
			$this.toggleClass('toggled');
		}
	});

	$(window).on('resize', function () {
		if ($(this).width() < 1025) {
			$('html').click(function () {
				$('.navbar-nav li .clickD').removeClass('toggled');
				$('.toggled').removeClass('toggled');
				$('.sub-menu').removeClass('show');
			});
			$(document).click(function () {
				$('.navbar-nav li .clickD').removeClass('toggled');
				$('.toggled').removeClass('toggled');
				$('.sub-menu').removeClass('show');
			});
			$('.navbar-nav').click(function (e) {
				e.stopPropagation();
			});
		}
	});
	// Navbar end
	/* ===== For menu animation === */
	$(".navbar-toggler").click(function () {
		$(".navbar-toggler").toggleClass("open");
		$(".navbar-toggler .stick").toggleClass("open");
		$('body,html').toggleClass("open-nav");
	});

	// search toggle

	$(".search-icon").click(function() {
        $(this).toggleClass("active");
		$(this).parent().toggleClass("open");
    });


})(window.jQuery);