(function ($) {
	'use strict';
	// Mean Menu JS
	jQuery('.mean-menu').meanmenu({
		meanScreenWidth: "991"
	});

	// Preloader JS
	$(function () {
		$('body').addClass('loaded');
	});

	// Nice Select JS
	$('select').niceSelect();

	// Header Sticky JS
	$(window).on('scroll', function () {
		if ($(this).scrollTop() > 150) {
			$('.navbar-area').addClass("is-sticky");
		} else {
			$('.navbar-area').removeClass("is-sticky");
		}
	});

	
	// Rishikesh's Code starts

	// Navigation links active starts
	$('.nav-item .nav-link').removeClass('active')
	let url_active = window.location.pathname
	url_active = url_active.replace('/', '')
	let hasActive = false;
	$('.nav-item .nav-link').each(function() {
		let data_active = $(this).attr('data-active')
		if(url_active === data_active) {
			hasActive = true;
			$(this).addClass('active')
		}
	})
	if(hasActive === false){
		$('#why_choose_us').addClass('active')
	}
	// Navigation links active ends

	$('#show_password').on('change', function() {
		if($('#show_password').is(':checked')){
			$('#password_register').attr('type', 'text')
			$('#cpassword_register').attr('type', 'text')

		} else {
			$('#password_register').attr('type', 'password')
			$('#cpassword_register').attr('type', 'password')
		}
	})

	$('#prev').on('click', function() {
		// console.log($(this).attr('data-prev'))
		var prev = parseInt($(this).attr('data-prev'));
		insertParam('page', prev)
		// let pathname = window.location.pathname;
		// let search = window.location.search;
		// if(search === ''){
		// 	search = search+'?page='+prev;
		// } else {
		// 	if(search.indexOf('?page') > -1){
		// 	search = search.split('?page');
		// 	search = search[0];
		// 	search = search+'?page='+prev;
		// 	} else if(search.indexOf('&page') > -1){
		// 	search = search.split('&page');
		// 	search = search[0];
		// 	search = search+'&page='+prev;
		// 	} else {
		// 	search = search+'&page='+prev;
		// 	}
		// }
		// let url = pathname+search
		// // console.log(url);
      	// window.location = url;

	})

	$('#next').on('click', function() {
		// console.log($(this).attr('data-next'))
		var next = parseInt($(this).attr('data-next'));
		insertParam('page', next)
		// let pathname = window.location.pathname;
		// let search = window.location.search;
		// if(search === ''){
		// 	search = search+'?page='+next;
		// } else {
		// 	if(search.indexOf('?page') > -1){
		// 	search = search.split('?page');
		// 	search = search[0];
		// 	search = search+'?page='+next;
		// 	} else if(search.indexOf('&page') > -1){
		// 	search = search.split('&page');
		// 	search = search[0];
		// 	search = search+'&page='+next;
		// 	} else {
		// 	search = search+'&page='+next;
		// 	}
		// }
		// let url = pathname+search
		// // console.log(url);
      	// window.location = url;
	})

	// FUNCTION for txnid
	function makeid(length) {
		var result           = '';
		var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
		var charactersLength = characters.length;
		for ( var i = 0; i < length; i++ ) {
		   result += characters.charAt(Math.floor(Math.random() * charactersLength));
		}
		return result;
	}

	// PayU Money Starts

	$('#checkout_btn').on('click', function(e) {

		var has_Error = false;
		$('.show_error').hide();

		if($('#gender').val() === ''){
			has_Error = true;
			$('#gender').siblings('.nice-select').after('<div class="show_error">This field is required</div>');
		}

		if($('#age_group').val() === ''){
			has_Error = true;
			$('#age_group').siblings('.nice-select').after('<div class="show_error">This field is required</div>');
		}

		if($('#pincode_checkout').val() === ''){
			has_Error = true;
			$('#pincode_checkout').after('<div class="show_error">This field is required</div>');
		}

		var batch = document.getElementsByClassName('checked');

		if(batch.length <= 0){
			has_Error = true;
			$('#checkout_btn').after('<div class="show_error mt-3">Please Select A Batch First</div>');
		}


		if(has_Error === true){
			return false;
		} else {
			console.log('true')
			e.preventDefault();
			var txnid = makeid(10);
			var id = $(this).attr('data-course');
			var title = $(this).attr('data-name');
			var name = $('#student_name_checkout').val()
			var email = $('#parent_email_checkout').val()
			var number = $('#parent_number_checkout').val()
			$.ajax({
				type: "POST",
				url: '/payment/payumoneyhash',
				data: {
					txnid: txnid,
					id: id,
					name: name,
					email: email
				},
				success: function(response){
					var RequestData = {
						key: '4vOFh2wD',
						txnid: txnid,
						hash: response.hash,
						amount: response.amount,
						firstname: name,
						email: email,
						phone: number,
						productinfo: title,
						// mode:'dropout'
						surl: 'http://localhost:3000/payment/payumoney/success',
						furl: 'http://localhost:3000/payment/payumoney/fail',
					}
	
					// 4012 0010 3714 1112 
					var Handler = {
	
						responseHandler: function(BOLT){
				  
						// your payment response Code goes here, BOLT is the response object
							// console.log(BOLT)
							$('#txnid').val(BOLT.response.payuMoneyId)
							$('#status').val(BOLT.response.status)
							let form = $('#checkout_form');
							form.submit();
						},
						catchException: function(BOLT){
						  // the code you use to handle the integration errors goes here
						  console.log(BOLT)
						}
					}
					bolt.launch( RequestData, Handler ); 
				}
			})
		}
	})
	
	// PayU Money Ends

	// Form Validation start
	
	$('#btn_login').on('click', function() {
		let has_Error = false;
		$('.show_error').hide();


		let email_login = $('#email_login').val();
		let password_login = $('#password_login').val();

		if(email_login === ''){
			has_Error = true;
            $('#email_login').after('<div class="show_error">This field is required</div>');
		}

		if(password_login === ''){
			has_Error = true;
            $('#password_login').after('<div class="show_error">This field is required</div>');
		}

		if(has_Error === true) {
            return false;
        } else {
            return true;
        }
	
	})

	$('#btn_register').on('click', function(){
		let has_Error = false;
		$('.show_error').hide();


		let name_register = $('#name_register').val();
		let number_register = $('#number_register').val();
		let email_register = $('#email_register').val();
		let address_register = $('#address_register').val();
		let student_name = $('#student_name').val();
		let student_age = $('#student_age').val();
		let student_school = $('#student_school').val();
		let student_class = $('#student_class').val();
		let password_register = $('#password_register').val();
		let cpassword_register = $('#cpassword_register').val();


		if(name_register === ''){
			has_Error = true;
            $('#name_register').after('<div class="show_error">This field is required</div>');
		}

		if(number_register === ''){
			has_Error = true;
            $('#number_register').after('<div class="show_error">This field is required</div>');
		}

		if(email_register === ''){
			has_Error = true;
            $('#email_register').after('<div class="show_error">This field is required</div>');
		}

		if(address_register === ''){
			has_Error = true;
            $('#address_register').after('<div class="show_error">This field is required</div>');
		}

		if(student_name === ''){
			has_Error = true;
            $('#student_name').after('<div class="show_error">This field is required</div>');
		}

		if(student_age === ''){
			has_Error = true;
            $('#student_age').after('<div class="show_error">This field is required</div>');
		}

		if(student_school === ''){
			has_Error = true;
            $('#student_school').after('<div class="show_error">This field is required</div>');
		}

		if(student_class === ''){
			has_Error = true;
            $('#student_class').after('<div class="show_error">This field is required</div>');
		}

		if(password_register === ''){
			has_Error = true;
            $('#password_register').after('<div class="show_error">This field is required</div>');
		}

		if(cpassword_register === ''){
			has_Error = true;
            $('#cpassword_register').after('<div class="show_error">This field is required</div>');
		}

		if(password_register !== cpassword_register){
			has_Error = true;
            $('#cpassword_register').after('<div class="show_error">Passwords don\'t match</div>');
		}


		if(has_Error === true) {
            return false;
        } else {
            return true;
        }
	})

	$('#btn_contact').on('click', function() {
		let has_Error = false;
		$('.show_error').hide();


		let name_contact = $('#name_contact').val();
		let number_contact = $('#number_contact').val();
		let email_contact = $('#email_contact').val();
		let message = $('#message').val();

		if(name_contact === ''){
			has_Error = true;
            $('#name_contact').after('<div class="show_error">This field is required</div>');
		}

		if(number_contact === ''){
			has_Error = true;
            $('#number_contact').after('<div class="show_error">This field is required</div>');
		}

		if(email_contact === ''){
			has_Error = true;
            $('#email_contact').after('<div class="show_error">This field is required</div>');
		}

		if(message === ''){
			has_Error = true;
            $('#message').after('<div class="show_error">This field is required</div>');
		}

		if(has_Error === true) {
            return false;
        } else {
			console.log(true)
			var data = {
				name: $('#name_contact').val(),
				email: $('#email_contact').val(),
				number: $('#number_contact').val(),
				message: $('#message').val()
			}
            $.ajax({
				type: 'POST',
				url: '/contact',
				data: data,
				success: function(response) {
					if(response){
						$('#contact_form').trigger('reset');
						$('#btn_contact').after('<span style="font-size: 14px; color: green;" class="mt-3">Thank you for contacting us! We\'ll get back to you soon.</span>')
					}
				}
			})
        }
	
	})


	// Form Validation ends

	// Courses Filtering starts

	function insertParam(key, value) {
		key = encodeURIComponent(key);
		value = encodeURIComponent(value);
	
		// kvp looks like ['key1=value1', 'key2=value2', ...]
		var kvp = document.location.search.substr(1).split('&');
		let i=0;
	
		for(; i<kvp.length; i++){
			if (kvp[i].startsWith(key + '=')) {
				let pair = kvp[i].split('=');
				pair[1] = value;
				kvp[i] = pair.join('=');
				break;
			}
		}
	
		if(i >= kvp.length){
			kvp[kvp.length] = [key,value].join('=');
		}
	
		// can return this or...
		let params = kvp.join('&');
	
		// reload page with new params
		document.location.search = params;
	}

	$('#age_group_courses option').each(function(){
		if($(this).val() === $(this).attr('data-selected')){
			$(this).attr('selected', 'selected')
			$('select').niceSelect('update');
		}
	})

	$('#category_courses option').each(function(){
		if($(this).val() === $(this).attr('data-selected')){
			$(this).attr('selected', 'selected')
			$('select').niceSelect('update');
		}
	})


	$('#age_group_courses').on('change', function() {
		let age_group = $(this).val();
		if(age_group !== ''){
			console.log(age_group)
			insertParam('age', age_group)
		}
	})

	$('#category_courses').on('change', function() {
		let categoryVal = $(this).val();
		categoryVal = categoryVal.replace('&', 'and')
		if(categoryVal !== ''){
			console.log(categoryVal)
			insertParam('category', categoryVal)
		}
	})

	// Courses Filtering ends

	// Hide Show Test starts

	// $('.hide_text').hide()
	// $('.hide_text_2').hide()

	// let hidden_1 = true
	// $('#read_more_btn_1').on('click', function() {
	// 	if(hidden_1){
	// 		$('.hide_text:eq(0)').fadeIn(800)
	// 		$('.hide_text:eq(1)').fadeIn(1600)
	// 		$('.hide_text:eq(2)').fadeIn(2400)
	// 		$(this).text('Read Less')
	// 		hidden_1 = false;
	// 	} else {
	// 		$('.hide_text:eq(0)').fadeOut(2400)
	// 		$('.hide_text:eq(1)').fadeOut(1600)
	// 		$('.hide_text:eq(2)').fadeOut(800)
	// 		$(this).text('Read More')
	// 		hidden_1 = true;
	// 	}
	// })

	// let hidden_2 = true
	// $('#read_more_btn_2').on('click', function() {
	// 	if(hidden_2){
	// 		$('.hide_text_2:eq(0)').fadeIn(800)
	// 		$('.hide_text_2:eq(1)').fadeIn(1600)
	// 		$('.hide_text_2:eq(2)').fadeIn(2400)
	// 		$(this).text('Read Less')
	// 		hidden_2 = false;
	// 	} else {
	// 		$('.hide_text_2:eq(0)').fadeOut(2400)
	// 		$('.hide_text_2:eq(1)').fadeOut(1600)
	// 		$('.hide_text_2:eq(2)').fadeOut(800)
	// 		$(this).text('Read More')
	// 		hidden_2 = true;
	// 	}
	// })
	var hidden_1 = true;
	$('#read_more_btn_1').on('click', function() {
		if(hidden_1){
			$(this).siblings('#show_more_less').removeClass('show_more_less')
			$(this).text('Read Less')
			hidden_1 = false
		} else {
			$(this).siblings('#show_more_less').addClass('show_more_less')
			$(this).text('Read More')
			hidden_1 = true
		}
	})

	var hidden_2 = true;
	$('#read_more_btn_2').on('click', function() {
		if(hidden_2){
			$(this).siblings('#show_more_less_2').removeClass('show_more_less')
			$(this).text('Read Less')
			hidden_2 = false
		} else {
			$(this).siblings('#show_more_less_2').addClass('show_more_less')
			$(this).text('Read More')
			hidden_2 = true
		}
	})


	// Hide Show Test ends


	// Set cookie for banner starts
	
	// let disabled = $.cookie("disabled")

	// if(!disabled || disabled == null){
	// 	$('#advertisement').show()
	// } else {
	// 	$('#advertisement').hide()
	// }

	// $('#advertisement_btn').on('click', function() {
	// 	// set cookie
    //     $.cookie('disabled', 'yes', { expires: 1, path: '/' });
	// })

	if(!document.cookie.includes('DISABLED=YES')){
		$('#advertisement').show()
	} else {
		$('#advertisement').hide()
	}
	  
	  $('#advertisement_btn').on('click', function() {
		var expiryDate = new Date();
		expiryDate.setMonth(expiryDate.getMonth() + 2);
		document.cookie = `DISABLED=YES;expires=${expiryDate};`
	  });


	// Set cookie for banner ends

	// About us scroll starts

	$(".goto").on('click', function() {
		let goto = $(this).attr('data-goto')
		$('html, body').animate({
			scrollTop: $(goto).offset().top-70
		}, 500);
	});

	$(".goto_2").on('click', function() {
		let goto = $(this).attr('data-goto')
		$('html, body').animate({
			scrollTop: $(goto).offset().top-85
		}, 500);
	});

	// About us scroll ends

	// Rishikesh's Code ends

	// Dashboard menu
	function filterClose() {
		$('.dashboard-main-menu').removeClass('dashboard-main-menu-open');
	}

	$('.filter-btn').on('click', function () {
		$('.dashboard-main-menu').addClass('dashboard-main-menu-open');
	});

	$('.dashboard-main-menu-close').on('click', function () {
		filterClose();
	});
	// filter end

	// to close sidemenu & filter section start
	// $('.wrapper').on('click', function (e) {
	// 	if ($(e.target).hasClass('overlay')) {
	// 		sidenavCloseAction();
	// 		filterClose();
	// 	}
	// });

	// $(window).on('resize', function () {
	// 	if ($(this).width() > 991) {
	// 		sidenavCloseAction();
	// 		filterClose();
	// 	}
	// });

	// Partner Wrap JS
	$('.partner-wrap').owlCarousel({
		loop: true,
		margin: 30,
		nav: false,
		dots: false,
		autoplay: true,
		smartSpeed: 1000,
		autoplayHoverPause: true,
		responsive: {
			0: {
				items: 2,
			},
			576: {
				items: 3,
			},
			768: {
				items: 4,
			},
			992: {
				items: 6,
			},
			1200: {
				items: 6,
			}
		}
	});

	// Banner Wrap JS
	$('.banner-slider').owlCarousel({
		loop: true,
		nav: false,
		items: 1,
		dots: true,
		// autoplay: true,
		autoplayTimeout: 6000,
		smartSpeed: 1000,
		autoplayHoverPause: true,
	});

	// Feedback Wrap JS
	$('.feedback-slider').owlCarousel({
		loop: true,
		margin: 30,
		nav: false,
		items: 1,
		dots: true,
		autoplay: true,
		smartSpeed: 1000,
		autoplayHoverPause: true,
	});

	// Discover Slider JS
	$('.discover-slider').owlCarousel({
		loop: true,
		margin: 30,
		nav: false,
		dots: true,
		autoplay: true,
		smartSpeed: 1000,
		autoplayHoverPause: true,
		responsive: {
			0: {
				items: 1,
			},
			576: {
				items: 2,
			},
			768: {
				items: 2,
			},
			992: {
				items: 2,
			},
			1200: {
				items: 2,
			}
		}
	});

	// Courses Slider Two JS
	$('.courses-slider-two').owlCarousel({
		loop: true,
		margin: 30,
		nav: false,
		dots: true,
		autoplay: true,
		smartSpeed: 1000,
		autoplayHoverPause: true,
		responsive: {
			0: {
				items: 1,
			},
			576: {
				items: 2,
			},
			768: {
				items: 2,
			},
			992: {
				items: 3,
			},
			1200: {
				items: 3,
			}
		}
	});

	// Courses Slider Three JS
	$('.courses-slider-three').owlCarousel({
		loop: true,
		margin: 30,
		nav: true,
		dots: false,
		autoplay: true,
		smartSpeed: 1000,
		autoplayHoverPause: true,
		navText: [
			"<i class='bx bx-left-arrow-alt'></i>",
			"<i class='bx bx-right-arrow-alt'></i>",
		],
		responsive: {
			0: {
				items: 1,
			},
			576: {
				items: 2,
			},
			768: {
				items: 2,
			},
			992: {
				items: 3,
			},
			1200: {
				items: 3,
			}
		}
	});

	// Go To Top JS
	// Scroll Event
	$(window).on('scroll', function () {
		var scrolled = $(window).scrollTop();
		if (scrolled > 300) $('.go-top').addClass('active');
		if (scrolled < 300) $('.go-top').removeClass('active');
	});

	// Click Event JS
	$('.go-top').on('click', function () {
		$("html, body").animate({
			scrollTop: "0"
		}, 500);
	});

	// FAQ Accordion JS
	$('.accordion').find('.accordion-title').on('click', function () {
		// Adds Active Class
		$(this).toggleClass('active');
		// Expand or Collapse This Panel
		$(this).next().slideToggle('fast');
		// Hide The Other Panels
		$('.accordion-content').not($(this).next()).slideUp('fast');
		// Removes Active Class From Other Titles
		$('.accordion-title').not($(this)).removeClass('active');
	});

	// Count Time JS
	function makeTimer() {
		var endTime = new Date("november  30, 2020 17:00:00 PDT");
		var endTime = (Date.parse(endTime)) / 1000;
		var now = new Date();
		var now = (Date.parse(now) / 1000);
		var timeLeft = endTime - now;
		var days = Math.floor(timeLeft / 86400);
		var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
		var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600)) / 60);
		var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));
		if (hours < "10") {
			hours = "0" + hours;
		}
		if (minutes < "10") {
			minutes = "0" + minutes;
		}
		if (seconds < "10") {
			seconds = "0" + seconds;
		}
		$("#days").html(days + "<span>Days</span>");
		$("#hours").html(hours + "<span>Hours</span>");
		$("#minutes").html(minutes + "<span>Minutes</span>");
		$("#seconds").html(seconds + "<span>Seconds</span>");
	}
	setInterval(function () {
		makeTimer();
	}, 300);

	// Popup Video JS
	$('.popup-youtube, .popup-vimeo').magnificPopup({
		disableOn: 300,
		type: 'iframe',
		mainClass: 'mfp-fade',
		removalDelay: 160,
		preloader: false,
		fixedContentPos: false,
	});

	// Gallery Popup JS
	$('.gallery-popup').each(function () {
		$(this).magnificPopup({
			delegate: 'a',
			type: 'image',
			gallery: {
				enabled: true
			}
		});
	});

	// custom radio buttons
	$('.custom-form-check').on('click', function (e) {
		// if ($(this).children('input:checked')) {
			e.stopPropagation();
			console.log(11);
			// console.log($(this).find('input').val())
			$('.custom-form-check').removeClass('checked');
			$(this).addClass('checked');
			// $(this).children('label').children('input[type="radio"]').attr('checked', 'checked')
			$('input[type="radio"]').removeAttr('checked')
			$(this).children('label').children('input[type="radio"]').attr("checked", "checked")
			// console.log($(this).children('label').children('input[type="radio"]').val());
		// }
	})

	// Tabs JS
	$('.tab ul.tabs').addClass('active').find('> li:eq(0)').addClass('current');
	$('.tab ul.tabs li').on('click', function (g) {
		var tab = $(this).closest('.tab'),
			index = $(this).closest('li').index();
		tab.find('ul.tabs > li').removeClass('current');
		$(this).closest('li').addClass('current');
		tab.find('.tab_content').find('div.tabs_item').not('div.tabs_item:eq(' + index + ')').slideUp();
		tab.find('.tab_content').find('div.tabs_item:eq(' + index + ')').slideDown();
		g.preventDefault();
	});

	// Subscribe form JS
	$(".newsletter-form").validator().on("submit", function (event) {
		if (event.isDefaultPrevented()) {
			// handle the invalid form...
			formErrorSub();
			submitMSGSub(false, "Please enter your email correctly.");
		} else {
			// everything looks good!
			event.preventDefault();
		}
	});

	function callbackFunction(resp) {
		if (resp.result === "success") {
			formSuccessSub();
		} else {
			formErrorSub();
		}
	}

	function formSuccessSub() {
		$(".newsletter-form")[0].reset();
		submitMSGSub(true, "Thank you for subscribing!");
		setTimeout(function () {
			$("#validator-newsletter, #validator-newsletter-2").addClass('hide');
		}, 4000)
	}

	function formErrorSub() {
		$(".newsletter-form").addClass("animated shake");
		setTimeout(function () {
			$(".newsletter-form").removeClass("animated shake");
		}, 1000)
	}

	function submitMSGSub(valid, msg) {
		if (valid) {
			var msgClasses = "validation-success";
		} else {
			var msgClasses = "validation-danger";
		}
		$("#validator-newsletter, #validator-newsletter-2").removeClass().addClass(msgClasses).text(msg);
	}

	// AJAX MailChimp JS
	$(".newsletter-form").ajaxChimp({
		url: "https://Envy Theme.us20.list-manage.com/subscribe/post?u=60e1ffe2e8a68ce1204cd39a5&amp;id=42d6d188d9", // Your url MailChimp
		callback: callbackFunction
	});

	// Input Plus & Minus Number JS
	$('.input-counter').each(function () {
		var spinner = jQuery(this),
			input = spinner.find('input[type="text"]'),
			btnUp = spinner.find('.plus-btn'),
			btnDown = spinner.find('.minus-btn'),
			min = input.attr('min'),
			max = input.attr('max');

		btnUp.on('click', function () {
			var oldValue = parseFloat(input.val());
			if (oldValue >= max) {
				var newVal = oldValue;
			} else {
				var newVal = oldValue + 1;
			}
			spinner.find("input").val(newVal);
			spinner.find("input").trigger("change");
		});
		btnDown.on('click', function () {
			var oldValue = parseFloat(input.val());
			if (oldValue <= min) {
				var newVal = oldValue;
			} else {
				var newVal = oldValue - 1;
			}
			spinner.find("input").val(newVal);
			spinner.find("input").trigger("change");
		});
	});

	// Newsletter Modal JS
	// $('#exampleModal').modal({
	// 	show: true
	// });

	// hide show dependent modal
	$('.forgot-password-link').on('click', function () {
		$('#sign-in-modal').modal('hide');
		$('#register-modal').modal('hide');
	});
	$('.login-link').on('click', function () {
		$('#forgot-password-modal').modal('hide');
		$('#register-modal').modal('hide');
	});
	$('.register-link').on('click', function () {
		$('#sign-in-modal').modal('hide');
		$('#forgot-password-modal').modal('hide');
	});

	// next & previous step of registration form
	$('#next-button').on('click', function () {
		$('#first-step').hide().removeClass('d-flex');
		$('#second-step').fadeIn().addClass('d-flex');
	});
	$('#previous-button').on('click', function () {
		$('#second-step').hide().removeClass('d-flex');
		$('#first-step').fadeIn().addClass('d-flex');
	});

	$("#register-modal").on("hide.bs.modal", function () {
		$(this).find('form')[0].reset();
		$('#second-step').hide().removeClass('d-flex');
		$('#first-step').fadeIn().addClass('d-flex');
	});

	// Odometer JS
	$('.odometer').appear(function (e) {
		var odo = $(".odometer");
		odo.each(function () {
			var countNumber = $(this).attr("data-count");
			$(this).html(countNumber);
		});
	});

	// Search Popup JS
	$('.close-btn').on('click', function () {
		$('.search-overlay').fadeOut();
		$('.search-btn').show();
		$('.close-btn').removeClass('active');
	});
	$('.search-btn').on('click', function () {
		$(this).hide();
		$('.search-overlay').fadeIn();
		$('.close-btn').addClass('active');
	});

	// Others Option For Responsive JS
	$(".others-option-for-responsive .dot-menu").on("click", function () {
		$(".others-option-for-responsive .container .container").toggleClass("active");
	});

	//WOW JS
	new WOW().init();

	// Product View Slider
	var bigimage = $("#big");
	var thumbs = $("#thumbs");
	//var totalslides = 10;
	var syncedSecondary = true;

	bigimage
		.owlCarousel({
			items: 1,
			slideSpeed: 2000,
			nav: true,
			autoplay: true,
			dots: false,
			loop: true,
			responsiveRefreshRate: 200,
			navText: [
				"<i class='bx bx-left-arrow-alt'></i>",
				"<i class='bx bx-right-arrow-alt'></i>",
			]
		})
		.on("changed.owl.carousel", syncPosition);

	thumbs
		.on("initialized.owl.carousel", function () {
			thumbs
				.find(".owl-item")
				.eq(0)
				.addClass("current");
		})
		.owlCarousel({
			items: 5,
			dots: false,
			nav: false,
			navText: [
				"<i class='bx bx-left-arrow-alt'></i>",
				"<i class='bx bx-right-arrow-alt'></i>",
			],
			smartSpeed: 200,
			slideSpeed: 500,
			slideBy: 4,
			responsiveRefreshRate: 100
		})
		.on("changed.owl.carousel", syncPosition2);

	function syncPosition(el) {
		//if loop is set to false, then you have to uncomment the next line
		//var current = el.item.index;

		//to disable loop, comment this block
		var count = el.item.count - 1;
		var current = Math.round(el.item.index - el.item.count / 2 - 0.5);

		if (current < 0) {
			current = count;
		}
		if (current > count) {
			current = 0;
		}

		//to this
		thumbs
			.find(".owl-item")
			.removeClass("current")
			.eq(current)
			.addClass("current");
		var onscreen = thumbs.find(".owl-item.active").length - 1;
		var start = thumbs
			.find(".owl-item.active")
			.first()
			.index();
		var end = thumbs
			.find(".owl-item.active")
			.last()
			.index();

		if (current > end) {
			thumbs.data("owl.carousel").to(current, 100, true);
		}
		if (current < start) {
			thumbs.data("owl.carousel").to(current - onscreen, 100, true);
		}
	}

	function syncPosition2(el) {
		if (syncedSecondary) {
			var number = el.item.index;
			bigimage.data("owl.carousel").to(number, 100, true);
		}
	}
	thumbs.on("click", ".owl-item", function (e) {
		e.preventDefault();
		var number = $(this).index();
		bigimage.data("owl.carousel").to(number, 300, true);
	});
})(jQuery);