;(function ($) {
	"use strict";

	//*=============menu sticky js =============*//
	var $window = $(window);
	var didScroll,
		lastScrollTop = 0,
		delta = 5,
		$mainNav = $("#sticky"),
		$mainNavHeight = $mainNav.outerHeight(),
		scrollTop;

	$window.on("scroll", function () {
		didScroll = true;
		scrollTop = $(this).scrollTop();
	});

	setInterval(function () {
		if (didScroll) {
			hasScrolled();
			didScroll = false;
		}
	}, 200);

	function hasScrolled() {
		if (Math.abs(lastScrollTop - scrollTop) <= delta) {
			return;
		}
		if (scrollTop > lastScrollTop && scrollTop > $mainNavHeight) {
			$mainNav.removeClass("fadeInDown").addClass("fadeInUp").css('top', -$mainNavHeight);
		} else {
			if (scrollTop + $(window).height() < $(document).height()) {
				$mainNav.removeClass("fadeInUp").addClass("fadeInDown").css('top', 0);
			}
		}
		lastScrollTop = scrollTop;
	}

	function navbarFixed() {
		if ($('#sticky').length) {
			$(window).scroll(function () {
				var scroll = $(window).scrollTop();
				if (scroll) {
					$("#sticky").addClass("navbar_fixed");
					$(".sticky-nav-doc .body_fixed").addClass("body_navbar_fixed");
				} else {
					$("#sticky").removeClass("navbar_fixed");
					$(".sticky-nav-doc .body_fixed").removeClass("body_navbar_fixed");
				}
			});
		};
	};
	navbarFixed();

	function navbarFixedTwo() {
		if ($('#stickyTwo').length) {
			$(window).scroll(function () {
				var scroll = $(window).scrollTop();
				if (scroll) {
					$("#stickyTwo").addClass("navbar_fixed");
				} else {
					$("#stickyTwo").removeClass("navbar_fixed");
				}
			});
		};
	};
	navbarFixedTwo();

	//*=============menu sticky js =============*//

	//         page scroll
	function bodyFixed() {
		var windowWidth = $(window).width();
		if ($('#sticky_doc').length) {
			if (windowWidth > 576) {
				var tops = $('#sticky_doc');
				var leftOffset = tops.offset().top;

				$(window).on('scroll', function () {
					var scroll = $(window).scrollTop();
					if (scroll >= leftOffset) {
						tops.addClass("body_fixed");
					} else {
						tops.removeClass("body_fixed");
					}
				});
			}
		}
	}

	bodyFixed();


	/*  Menu Click js  */
	function Menu_js() {
		if ($('.submenu').length) {
			$('.submenu > .dropdown-toggle').click(function () {
				var location = $(this).attr('href');
				window.location.href = location;
				return false;
			});
		}
	}

	Menu_js();


	$('.doc_menu a[href^="#"]:not([href="#"]').on('click', function (event) {
		var $anchor = $(this);
		$('html, body').stop().animate({
			scrollTop: $($anchor.attr('href')).offset().top
		}, 900);
		event.preventDefault();
	});

	$(window).on("load", function () {
		if ($('.scroll').length) {
			$(".scroll").mCustomScrollbar({
				mouseWheelPixels: 50,
				scrollInertia: 0,
			});
		}
	});

	/*--------------- doc_documentation_area Switcher js--------*/
	if ($(".doc_documentation_area").length > 0) {
		//switcher
		var switchs = true;
		$("#right").on("click", function (e) {
			e.preventDefault();
			if (switchs) {
				$(".doc_documentation_area,#right").addClass("overlay");
				$(".doc_right_mobile_menu").animate({
					"right": "0px"
				}, 100);
				switchs = false;
			} else {
				$(".doc_documentation_area,#right").removeClass("overlay");
				$(".doc_right_mobile_menu").animate({
					"right": "-250px"
				}, 100);
				switchs = true;
			}
		});

		$("#left").on("click", function (e) {
			e.preventDefault();
			if (switchs) {
				$(".doc_documentation_area,#left").addClass("overlay");
				$(".doc_mobile_menu").animate({
					"left": "0px"
				}, 300);
				switchs = false;
			} else {
				$(".doc_documentation_area,#left").removeClass("overlay");
				$(".doc_mobile_menu").animate({
					"left": "-245px"
				}, 300);
				switchs = true;
			}
		});
	}

	if ($(".mobile_menu").length > 0) {
		var switchs = true;
		$(".mobile_btn").on("click", function (e) {
			if (switchs) {
				$(".mobile_menu").addClass("open");
			}
		})
	}

	/*--------------- slick js--------*/
	if ($('.doc_feedback_slider').length) {
		$('.doc_feedback_slider').slick({
			autoplay: true,
			slidesToShow: 1,
			slidesToScroll: 1,
			autoplaySpeed: 2000,
			speed: 1000,
			dots: false,
			arrows: true,
			prevArrow: '.prev',
			nextArrow: '.next',
		});
	}

	/*--------------- parallaxie js--------*/
	function parallax() {
		if ($(".parallaxie").length) {
			$('.parallaxie').parallaxie({
				speed: 0.5,
			});
		}
	}

	parallax();

	/*--------------- tooltip js--------*/
	function tooltip() {
		if ($('.tooltips').length) {
			$('.tooltips').tooltipster({
				interactive: true,
				arrow: true,
				animation: 'grow',
				delay: 200,
			});
		}
	}

	tooltip();
	$('.tooltips_one').data('tooltip-custom-class', 'tooltip_blue').tooltip();
	$('.tooltips_two').data('tooltip-custom-class', 'tooltip_danger').tooltip();

	$(document).on('inserted.bs.tooltip', function (e) {
		var tooltip = $(e.target).data('bs.tooltip');
		$(tooltip.tip).addClass($(e.target).data('tooltip-custom-class'));
	});

	/*--------------- wavify js--------*/
	if ($('.animated-waves').length) {
		$('#animated-wave-three').wavify({
			height: 40,
			bones: 4,
			amplitude: 70,
			color: "rgba(188, 214, 234, 0.14)",
			speed: .3
		});

		$('#animated-wave-four').wavify({
			height: 60,
			bones: 5,
			amplitude: 90,
			color: "rgba(188, 214, 234, 0.14)",
			speed: .2
		});
	}

	/*--------------- nav-sidebar js--------*/
	if ($('.nav-sidebar > li').hasClass('active')) {
		$(".nav-sidebar > li.active").find('ul').slideDown(700);
	}

	function active_dropdown() {
		$('.nav-sidebar > li .icon').on('click', function (e) {
			$(this).parent().find('ul').first().toggle(300);
			$(this).parent().siblings().find('ul').hide(300);
		});
	}

	active_dropdown();

	$('.nav-sidebar > li .icon').each(function () {
		var $this = $(this);
		$this.on('click', function (e) {
			var has = $this.parent().hasClass('active');
			$('.nav-sidebar li').removeClass('active');
			if (has) {
				$this.parent().removeClass('active');
			} else {
				$this.parent().addClass('active');
			}
		});
	});

	/*--------------- mobile dropdown js--------*/
	function active_dropdown2() {
		$('.menu > li .mobile_dropdown_icon').on('click', function (e) {
			$(this).parent().find('ul').first().slideToggle(300);
			$(this).parent().siblings().find('ul').hide(300);
		});
	}

	active_dropdown2();

	/*--------------- search js--------*/
	$('.search a').on('click', function () {
		if ($(this).parent().hasClass('open')) {
			$(this).parent().removeClass('open')
		} else {
			$(this).parent().addClass('open')
		}
		return false
	});

	/*--------------- niceSelect js--------*/
	function select() {
		if ($('.custom-select').length) {
			$('.custom-select').niceSelect();
		}
		if ($('#mySelect').length) {
			$('#mySelect').selectpicker();
		}
	}

	select();

	/*--------------- counterUp js--------*/
	function counterUp() {
		if ($('.counter').length) {
			$('.counter').counterUp({
				delay: 1,
				time: 250
			});
		};
	};

	counterUp();

	/*--------------- popup-js--------*/
	function popupGallery() {
		if ($(".img_popup").length) {
			$(".img_popup").each(function () {
				$(".img_popup").magnificPopup({
					type: 'image',
					closeOnContentClick: true,
					closeBtnInside: false,
					fixedContentPos: true,
					removalDelay: 300,
					mainClass: 'mfp-no-margins mfp-with-zoom',
					image: {
						enabled: true,
						navigateByImgClick: true,
						preload: [0, 1] // Will preload 0 - before current, and 1 after the current image,
					}
				});
			})
		}
	}

	popupGallery();

	/*--------------- video js--------*/
	function video() {
		if ($("#inline-popups").length) {
			$('#inline-popups').magnificPopup({
				delegate: 'a',
				removalDelay: 500, //delay removal by X to allow out-animation
				mainClass: 'mfp-no-margins mfp-with-zoom',
				preloader: false,
				midClick: true
			});
		}
	}

	video();

	/*=========== Font size switcher/controller ===========*/
	if ($('#post').length > 0) {
		$.rvFontsize({
			targetSection: '#post',
			store: true, // store.min.js required!
			controllers: {
				appendTo: '#rvfs-controllers',
				showResetButton: true
			}
		});
	}

	/*=========== anchors js ===========*/

	if ($(".load-order-2").length) {
		var Anchor1 = new AnchorJS();
		document.addEventListener("DOMContentLoaded", function (event) {
			Anchor1 = new AnchorJS();
			Anchor1.add('.load-order-2');
		});
	}


	/*--------- WOW js-----------*/
	function bodyScrollAnimation() {
		var scrollAnimate = $('body').data('scroll-animation');
		if (scrollAnimate === true) {
			new WOW({}).init()
		}
	}

	bodyScrollAnimation();

	$('.mobile_menu_btn').on('click', function () {
		$('body').removeClass('menu-is-closed').addClass('menu-is-opened');
	});
	$('.close_nav').on("click", function (e) {
		if ($('.side_menu').hasClass('menu-opened')) {
			$('.side_menu').removeClass('menu-opened');
			$('body').removeClass('menu-is-opened')
		} else {
			$('.side_menu').addClass('menu-opened');
		}
	});

	$('.click_capture').on('click', function () {
		$('body').removeClass('menu-is-opened').addClass('menu-is-closed');
		$('.side_menu').removeClass('menu-opened');
	});


	/*--------------- Tab button js--------*/
	$('.next').on('click', function () {
		$('.v_menu .nav-item > .active').parent().next('li').find('a').trigger('click');
	});

	$('.previous').on('click', function () {
		$('.v_menu .nav-item > .active').parent().prev('li').find('a').trigger('click');
	});

	function Click_menu_hover() {
		if ($('.tab-demo').length) {
			$.fn.tab = function (options) {
				var opts = $.extend({}, $.fn.tab.defaults, options);
				return this.each(function () {
					var obj = $(this);

					$(obj).find('.tabHeader li').on(opts.trigger_event_type, function () {
						$(obj).find('.tabHeader li').removeClass('active');
						$(this).addClass('active');

						$(obj).find('.tabContent .tab-pane').removeClass('active show');
						$(obj).find('.tabContent .tab-pane').eq($(this).index()).addClass('active show');

					})
				});
			}
			$.fn.tab.defaults = {
				trigger_event_type: 'click', //mouseover | click é»˜è®¤æ˜¯click
			};
		}
	}

	Click_menu_hover();

	function Tab_menu_activator() {
		if ($('.tab-demo').length) {
			$('.tab-demo').tab({
				trigger_event_type: 'mouseover'
			});
		}
	}

	Tab_menu_activator();

	function fAqactive() {
		$(".doc_faq_info .card").on('click', function () {
			$(".doc_faq_info .card").removeClass("active");
			$(this).addClass('active');
		});
	}

	fAqactive();

	function general() {

		$('.collapse-btn').on('click', function (e) {
			e.preventDefault();
			$(this).toggleClass('active')
			$(".collapse-wrap").slideToggle(500);

		});

		
		$('.short-by a').click( function() {
			$(this).toggleClass('active-short').siblings().removeClass('active-short');
		});
	}

	general()
	/*-------------------------------------
	Intersection Observer
	-------------------------------------*/
	if (!!window.IntersectionObserver) {
		let observer = new IntersectionObserver((entries, observer) => {
			entries.forEach(entry => {
				if (entry.isIntersecting) {
					entry.target.classList.add("active-animation");
					//entry.target.src = entry.target.dataset.src;
					observer.unobserve(entry.target);
				}
			});
		}, {
			rootMargin: "0px 0px -100px 0px"
		});
		document.querySelectorAll('.has-animation').forEach(block => {
			observer.observe(block)
		});
	} else {
		document.querySelectorAll('.has-animation').forEach(block => {
			block.classList.remove('has-animation')
		});
	}

	// === Image Magnify
	if ($('.zoom').length) {
			$('.zoom').magnify({
					afterLoad: function () {
							console.log('Magnification powers activated!');
					}
			});
	}

		// === Back to Top Button
	var back_top_btn = $('#back-to-top');

	$(window).scroll(function() {
		if ($(window).scrollTop() > 300) {
			back_top_btn.addClass('show');
		} else {
			back_top_btn.removeClass('show');
		}
	});

	back_top_btn.on('click', function(e) {
		e.preventDefault();
		$('html, body').animate({scrollTop:0}, '300');
	});

	$('.custom-select').change(function() {
		if($('.custom-select').val() !== 'default' ) {
			window.open($('.custom-select').val(), '_blank');
		}
	});

	$('.btn-model-example').click(function() {
		$(this).css('font-weight', 'bold').parents('.request-box-value').find('.model-example').show();
		$(this).parents('.request-box-value').find('.model-definition').hide();
		$(this).parents('.request-box-value').find('.btn-model-definition').css('font-weight', 'normal');
	});

	$('.btn-model-definition').click(function() {
		$(this).parents('.request-box-value').find('.model-example').hide()
		$(this).css('font-weight', 'bold').parents('.request-box-value').find('.model-definition').show()
		$(this).parents('.request-box-value').find('.btn-model-example').css('font-weight', 'normal');
	});

	$('.zama-code-button').click(function() {
		const name = $(this).attr('data-name');
		const zamaCode = $(this).parents('.zama-code');
		zamaCode.find('.zama-code-button').removeClass('active');
		zamaCode.find(`.zama-code-button[data-name=${name}]`).addClass('active');
		zamaCode.find('.highlight').hide();
		zamaCode.find(`.highlight.${name}`).show();
	});

	$('.navbar-toggler').click(function() {
		if ($('.doc_mobile_menu').attr('style')) {
			return window.zamaCloseBtnHandler();
		}

		$('.doc_mobile_menu').css('position', 'fixed').css("z-index", 1000).show().find('.nav_title');
		$('html, body').scrollTop(0)
		TweenMax.to(document.body, 0.5, {x: 300});
		TweenMax.fromTo($('.doc_mobile_menu'), 1, {scale: 1, x: -35}, { scale: 1, x: -35});
		$('a.nav-link').click(() => {
			$('.doc_mobile_menu').attr('style', '');
			TweenMax.to(document.body, 0.5, {x: 0, onComplete: () => $(document.body).attr('style', '')});
		});
	});

	window.zamaCloseBtnHandler = () => {
		$('.doc_mobile_menu').attr('style', '');
		$('a.nav-link').off('click');
		TweenMax.to(document.body, 0.5, {x: 0, onComplete: () => $(document.body).attr('style', '')});
	}

	$('.api-path-try-btn').click(function() {
		const pathId = $(this).attr('data-id');
		window.zamaPopup.createRequest(pathId);
	});

	const zamaSearchOpen = () => {
		$('html, body').scrollTop(0);
		$('.zama-search-open-btn').hide();
		$('.zama-search-close-btn').show();
		$('.search_form input').show()
		TweenMax.to($('.zama-search-txt'), 0.5, {opacity: 1});
		TweenMax.to(document.body, 0.5, {y: 300, scale: 0.8, boxShadow: 'rgba(0, 0, 0, 0.2) 4px -20px 20px 0px'});
		if ($(window).width() > 500) {
			TweenMax.to($('.search_form'), 0.5, {y: -400, x: '-65%', scale: 2, width: '40%'});
		} else {
			TweenMax.to($('.search_form'), 0.5, {y: -400, x: '-30%', scale: 2, width: '60%'});
		}
		$('.zama-search-result').show();
		$('.zama-search-txt').focus();
	}

	const zamaSearchClose = () => {
		$('.zama-search-open-btn').show();
		$('.zama-search-close-btn').hide();
		TweenMax.to($('.zama-search-txt'), 0.5, {opacity: 0});
		TweenMax.to(document.body, 0.5, {y: 0, scale: 1, onComplete: () => $(document.body).attr('style', '')});
		TweenMax.to($('.search_form'), 0.5, {y: 0, x: '0%', scale: 1, width: 50, onComplete: () => $('.search_form input').hide()});
		$('.zama-search-result').hide();
	}

	$('.zama-search-open-btn').click(function() {
		zamaSearchOpen();
	});

	$('.zama-search-close-btn').click(function() {
		zamaSearchClose();
	});

	$('.zama-search-txt').on('input', function() {
		const lc = (str) => (str || '').toLowerCase();
		const value = lc($(this).val());
		if (value.length > 1) {
			const {paths = []} = pathsObject;
			const filteredPaths = paths.filter(({summary = '', pathName = '', tags = []}) => lc(summary).includes(value) || lc(pathName).includes(value) || lc(tags.join(' ')).includes(value));
			$('.zama-search-result').html('');

			filteredPaths.forEach(({ id, summary, tags, pathName }) => {
				$('.zama-search-result').append(`<h5 data-id="${id}">${summary || `${tags}: ${pathName}`}</h5>`);
			})

			$('.zama-search-result h5').off('mousedown');
			$('.zama-search-result h5').mousedown(function() {
				zamaSearchClose();
				const id = $(this).attr('data-id');
				setTimeout(() => {
					$('html, body').animate({scrollTop: $(`#${id}`).offset().top}, '2000');
				}, 500);
			});
		} else {
			$('.zama-search-result').html('');
		}
	});

	$('.zama-search-txt').blur(function() {});

	window.zamaPopup = new ZamaPopup();
	window.zamaPopup.injectPopup();
})(jQuery);