(function ($) {
	"use strict";

	/* Init Elementor Front Scripts */
	$(window).on('elementor/frontend/init', function () {

		// Global
		elementorFrontend.hooks.addAction( 'frontend/element_ready/widget', function( $scope ) {
			var editorActive = $('body').hasClass('elementor-editor-active');
			if( editorActive ) {

				/*
					- Preloader
				*/
				$(window).on("load", function() {
					$('body').addClass('animated--active');
					$('body').addClass('animated--swiper--active');
				});

				/**
					Splitting
				**/
				Splitting({ by: 'lines' });

				/**
					Header Menu Button
				**/
				$('.onovo-menu-btn').on('click', function(){
					var obj = $(this);
					if(obj.hasClass('btn--active')) {
						obj.removeClass('btn--active');
						obj.addClass('onovo--notouch');
						obj.parent().find('.onovo-menu-popup').removeClass('menu--ready');
						obj.parent().find('.onovo-menu-container').addClass('onovo--noscroll');
						setTimeout(function(){
							obj.parent().find('.onovo-menu-popup').removeClass('menu--open');
						}, 300);
						setTimeout(function(){
							obj.removeClass('onovo--notouch');
							obj.parent().find('.onovo-menu-popup').removeClass('menu--visible');
						}, 1600);
					}
					else {
						obj.addClass('btn--active');
						obj.addClass('onovo--notouch');
						obj.parent().find('.onovo-menu-popup').addClass('menu--visible');
						obj.parent().find('.onovo-menu-popup').addClass('menu--open');
						setTimeout(function(){
							obj.removeClass('onovo--notouch');
							obj.parent().find('.onovo-menu-container').removeClass('onovo--noscroll');
							obj.parent().find('.onovo-menu-popup').addClass('menu--ready');
						}, 600);
					}
					return false;
				});

				/*
					Header Menu Dropdown
				*/
				$('.onovo-menu').on('click', '.menu-item-has-children > .icon, .dropdown-link > a', function(){
					if($(this).closest('li').hasClass('opened')) {
						$(this).closest('li').removeClass('opened');
					} else {
						$(this).closest('ul').find('> li').removeClass('opened');
						$(this).closest('li').addClass('opened');
					}
					return false;
				});

				/*
					Footer Sticky
				*/
				if($('.footer--fixed').length) {
					var footer_fixed = $('.footer--fixed .onovo-footer').height();
					$('.wrapper').css({'margin-bottom':footer_fixed+'px'});
				}

				/*
					Pagepiling
				*/
				$('.js-hero-parallax').each(function() {
					var heroParallax = $(this);
					heroParallax.pagepiling({
						direction: 'vertical',
						scrollingSpeed: 700,
						easing: 'swing',
						normalScrollElementTouchThreshold: 5,
						touchSensitivity: 10,
						css3: true,
						loopTop: false,
						loopBottom: false,
						navigation: false,
						sectionSelector: '.onovo-hero-parallax-section',
						afterRender: function() {
							if (heroParallax.find('.onovo-hero-parallax-section.active').hasClass('section--dark')) {
								setDark();
							}
							$('.js-hero-parallax-navs').on('click', '.js-hero-parallax-prev', function(){
								$.fn.pagepiling.moveSectionUp();
							});
							$('.js-hero-parallax-navs').on('click', '.js-hero-parallax-next', function(){
								$.fn.pagepiling.moveSectionDown();
							});
						},
						afterLoad: function (anchorLink, index) {
							var current = heroParallax.find('.onovo-hero-parallax-section.active');
							if (current.hasClass('section--dark')) {
								setDark();
							} else {
								removeDark();
							}
						}
					});
					heroParallax.find('.image').each(function() {
						var img_d = $(this).attr('data-dimg');
						var img_m = $(this).attr('data-mimg');
						if($(window).width() < 768) {
							if(img_m != 0) {
								$(this).css({'background-image' : 'url('+img_m+')'});
							}
							else {
								$(this).css({'background-image' : 'url('+img_d+')'});
							}
						} else {
							if(img_d != 0) {
								$(this).css({'background-image' : 'url('+img_d+')'});
							}
						}
					});
				});
				function setDark() {
					$('.onovo-page').addClass('parallax--dark');
					$('.onovo-header').removeClass('header--white');
					$('.onovo-hero-parallax .onovo-prev').removeClass('nav--white');
					$('.onovo-hero-parallax .onovo-next').removeClass('nav--white');
				}
				function removeDark() {
					$('.onovo-page').removeClass('parallax--dark');
					$('.onovo-header').addClass('header--white');
					$('.onovo-hero-parallax .onovo-prev').addClass('nav--white');
					$('.onovo-hero-parallax .onovo-next').addClass('nav--white');
				}

				/*
					- Hero Slider
				*/
				$('.js-hero-slider').each(function() {
					var heroMainSwiper = $(this);
					var mainSliderSelector = new Swiper(heroMainSwiper, {
						slidesPerView: 1,
						spaceBetween: 0,
						loop: false,
						speed: 1200,
						parallax: true,
						autoplay: false,
						grabCursor: false,
						watchSlidesProgress: true,
						pagination: {
							el: '.js-hero-pagination',
							type: 'bullets',
							clickable: true,
						},
						navigation: {
							nextEl: '.js-hero-slider-next',
							prevEl: '.js-hero-slider-prev',
						},
						on: {
							progress: function(){
								var swiper = this;
								for (var i = 0; i < swiper.slides.length; i++) {
									var slideProgress = swiper.slides[i].progress, innerOffset = swiper.width * 0.5, innerTranslate = slideProgress * innerOffset;
									swiper.slides[i].querySelector('.image').style.transform = "translateX(" + innerTranslate + "px)";
								}
							},
							touchStart: function() {
								var swiper = this;
								for (var i = 0; i < swiper.slides.length; i++) {
									swiper.slides[i].style.transition = "";
								}
							},
							setTransition: function(speed) {
								var swiper = this;
								for (var i = 0; i < swiper.slides.length; i++) {
									swiper.slides[i].style.transition = speed + "ms";
									swiper.slides[i].querySelector('.image').style.transition = speed + "ms";
								}
							}
						}
					});
					heroMainSwiper.find('.image:not(.video)').each(function() {
						var img_d = $(this).attr('data-dimg');
						var img_m = $(this).attr('data-mimg');
						if($(window).width() < 768) {
							if(img_m != 0) {
								$(this).css({'background-image' : 'url('+img_m+')'});
							}
							else {
								$(this).css({'background-image' : 'url('+img_d+')'});
							}
						} else {
							if(img_d != 0) {
								$(this).css({'background-image' : 'url('+img_d+')'});
							}
						}
					});
				});

				/*
					- Hero Carousel
				*/
				$('.js-hero-carousel').each(function() {
					var heroCarousel = new Swiper('.js-hero-carousel', {
						slidesPerView: 'auto',
						rewind: false,
						loop: false,
						mousewheel: false,
						autoplay: false,
						spaceBetween: 20,
						pagination: false,
						navigation: {
							nextEl: '.js-hero-carousel-next',
							prevEl: '.js-hero-carousel-prev',
						}
					});
				});

				/*
					- Blog Carousel
				*/
				$('.js-blog-carousel').each(function() {
					var blogSwiper = $(this);
					var blogCarousel = new Swiper(blogSwiper, {
						slidesPerView: '2',
						loop: false,
						autoplay: false,
						spaceBetween: 20,
						pagination: {
							el: '.js-blog-pagination',
							type: 'bullets',
							clickable: true,
						},
						navigation: {
							nextEl: '.js-blog-carousel-next',
							prevEl: '.js-blog-carousel-prev',
						},
						breakpoints: {
							0: {
								slidesPerView: 1
							},
							1024: {
								slidesPerView: 2,
							}
						}
					});
				});

				/*
					- History Carousel
				*/
				$('.js-history-slider').each(function() {
					var hisSwiper = $(this);
					var hisCarousel = new Swiper(hisSwiper, {
						slidesPerView: 1,
						noSwipingSelector: 'a',
						watchSlidesProgress: true,
						watchSlidesVisibility: true,
						loop: false,
						autoplay: false,
						spaceBetween: 20,
						pagination: {
							el: '.js-history-pagination',
							type: 'bullets',
							clickable: true,
						},
						navigation: {
							nextEl: '.js-history-next',
							prevEl: '.js-history-prev',
						}
					});
					hisSwiper.find('.js-history-pagination .swiper-pagination-bullet').each(function() {
						var hisSwiper_index = $(this).index() + 1;
						var hisSwiper_date = hisSwiper.find('.swiper-slide:nth-child('+ hisSwiper_index +') .subtitle').text();
						$(this).html('<span>'+hisSwiper_date+'</span>');
					});
				});

				/*
					- Services Hover
				*/
				$('.onovo-service-grid-item.active--default').each(function() {
					$(this).closest('.elementor-inner-section').addClass('onovo-services-grid-fw');
					$(this).closest('.onovo-services-grid-fw').hover(function(){
						if ($(this).find('.onovo-service-grid-item').hasClass('active--default')) {
							$(this).find('.onovo-service-grid-item').removeClass('active');
						}
					},function(){
						if ($(this).find('.onovo-service-grid-item').hasClass('active--default')) {
							$(this).find('.onovo-service-grid-item.active--default').addClass('active');
						}
					});
				});

				/*
					- Number Text
				*/
				$('.onovo-circle-text .label').each(function() {
					$(this).html($(this).text().split('').map((char, i) => `<span style="transform:rotate(${i * 8.5}deg)">${char}</span>`).join(''));
				});

				/*
					- Portfolio Showcase Hover
				*/
				if ($('.onovo-showcase-items').length) {
					$('.onovo-showcase-items').find('.onovo-showcase-item:first-child').addClass('hover');
				}
				$('.onovo-showcase-item').mouseenter(function(){
					var obj = $(this);
					obj.closest('.onovo-showcase-items').find('.onovo-showcase-item').removeClass('hover');
					obj.addClass('hover');
				});

				/*
					- Services Showcase Hover
				*/
				if ($(window).width() > 767) {
					if ($('.onovo-services-showcase').length) {
						$('.onovo-services-showcase').find('.items ul li:first-child').addClass('hover');
					}
					$('.onovo-services-showcase .items ul li .title').mouseenter(function(){
						var obj = $(this).closest('li');
						obj.closest('ul').find('li').removeClass('hover');
						obj.addClass('hover');
					});
				}

				/**
					- Counter
				**/
				$('.onovo-counter').each(function() {
					var numbers = $(this).find('.js-counter');
					var animationIsDone = false;
					var scroll = $(window).scrollTop() + $(window).height();
					var offset = $(this).offset().top;

					if (!animationIsDone && scroll >= offset) {
						animateNumbers();
					}

					$(window).on('scroll', function() {
						scroll = $(window).scrollTop() + $(window).height();

						if (!animationIsDone && scroll >= offset) {
							animateNumbers();
						}
					});
					function animateNumbers() {
						numbers.each(function() {
							var endValue = parseInt($(this).attr('data-end-value'), 10);

							$(this).easy_number_animate({
								start_value: 0,
								end_value: endValue,
								duration: 2500
							});

						});

						animationIsDone = true;
					}
				});

				/*
					- Onovo Pagination
				*/
				$('.pager').each(function() {
					var btn_next = $(this).find('.next');
					var btn_prev = $(this).find('.prev');
					btn_next.html('<i></i>');
					btn_prev.html('<i></i>');
					btn_next.addClass('onovo-next onovo-hover-2');
					btn_prev.addClass('onovo-prev onovo-hover-2');
				});
				
			}
		} );
	});
})(jQuery);