(function ($) {
  "use strict";
  
  //  Main Menu Offcanvas
  $('.primary-menu').find('li a').each(function () {
    if ($(this).next().length > 0) {
      $(this).parent('li').append('<span class="menu-trigger"><i class="fa fa-angle-down"></i></span>');
    }
  });

    // expands the dropdown menu on each click
    $('.primary-menu').find('li .menu-trigger').on('click', function (e) {
      e.preventDefault();
      $(this).toggleClass('open').parent('li').children('ul').stop(true, true).slideToggle(350);
      $(this).find("i").toggleClass("fa-angle-up fa-angle-down");
    });

  // YouTubePopUp		
	// jQuery("a.video-icon").YouTubePopUp({ autoplay: 0 });

  // check browser width in real-time
  function breakpointCheck() {
    var windoWidth = window.innerWidth;

    if (windoWidth <= 768) {
      $('.header-navbar').addClass('mobile-menu');
    } else {
      $('.header-navbar').removeClass('mobile-menu');
    }
  }

  breakpointCheck();
  $(window).on('resize', function () {
    breakpointCheck();
  });


  $('.nav-toggler').on('click', function (e) {
    $('.site-navbar').toggleClass('menu-on');
    e.preventDefault();
  });

  // Close menu on toggler click
  $('.nav-close').on('click', function (e) {
    $('.site-navbar').removeClass('menu-on');
    e.preventDefault();
  });


  // Offcanvas Info menu

  $('.offcanvas-icon').on('click', function (e) {
    $('.offcanvas-info').toggleClass('offcanvas-on');
    e.preventDefault();
  });

  // Close menu on toggler click
  $('.info-close').on('click', function (e) {
    $('.offcanvas-info').removeClass('offcanvas-on');
    e.preventDefault();
  });

 //Search Box addClass removeClass
 $('.header_search_btn > a').on('click', function(){
  $('.page_search_box').addClass('active')
  });
  $('.search_close > i').on('click', function(){
      $('.page_search_box').removeClass('active')
  });



  /* ---------------------------------------------
      Sticky Fixed Menu
  --------------------------------------------- */

  $(window).scroll(function () {
    var window_top = $(window).scrollTop() + 1;

    if (window_top > 50) {
      $('.fixed-btm-top').addClass('reveal');
    } else {
      $('.fixed-btm-top').removeClass('reveal');
    }
  });


  /* ---------------------------------------------
     Bottom To Top hide
  --------------------------------------------- */

  $(window).scroll(function () {
    var window_top = $(window).scrollTop() + 1;

    if (window_top > 50) {
      $('.fixed-btm-top').addClass('reveal');
    } else {
      $('.fixed-btm-top').removeClass('reveal');
    }
  });

  //  Sticky Menu

$(window).scroll(function () {
    var window_top = $(window).scrollTop() + 1;
    if (window_top > 50) {
      $('.navbar-sticky').addClass('menu_fixed animated fadeInDown');
    } else {
      $('.navbar-sticky').removeClass('menu_fixed animated fadeInDown');
    }
  });
 

  	////////////////////////////////////////////////////
	// 07. Nice Select Js
	$('.tp-shop-area select, .tp-blog-area select,  .contact__area select, .footer__area select').niceSelect();

  
  


// 03. Offcanvas Js
$(".cartmini-open-btn").on("click", function () {
  $(".cartmini__area").addClass("cartmini-opened");
  $(".body-overlay").addClass("opened");
});


$(".cartmini-close-btn").on("click", function () {
  $(".cartmini__area").removeClass("cartmini-opened");
  $(".body-overlay").removeClass("opened");
});



function smoothSctollTop() {
  $('.smooth a').on('click', function (event) {
    var target = $(this.getAttribute('href'));
    if (target.length) {
      event.preventDefault();
      $('html, body').stop().animate({
        scrollTop: target.offset().top - 150
      }, 1000);
    }
  });
}
smoothSctollTop();




	////////////////////////////////////////////////////
	// 17. Show Login Toggle Js
	$('#showlogin').on('click', function () {
		$('#checkout-login').slideToggle(900);
	});

	////////////////////////////////////////////////////
	// 18. Show Coupon Toggle Js
	$('#showcoupon').on('click', function () {
		$('#checkout_coupon').slideToggle(900);
	});

	////////////////////////////////////////////////////
	// 19. Create An Account Toggle Js
	$('#cbox').on('click', function () {
		$('#cbox_info').slideToggle(900);
	});

	////////////////////////////////////////////////////
	// 20. Shipping Box Toggle Js
	$('#ship-box').on('click', function () {
		$('#ship-box-info').slideToggle(1000);
	});

  if ($('#marker').length > 0) {
		function tp_tab_line(){
			var marker = document.querySelector('#marker');
			var item = document.querySelectorAll('.tp-tab-menu button');
			var itemActive = document.querySelector('.tp-tab-menu .nav-link.active');

			// rtl settings
			var tp_rtl = localStorage.getItem('tp_dir');
			let rtl_setting = tp_rtl == 'rtl' ? 'right' : 'left';

			function indicator(e){
				marker.style.left = e.offsetLeft+"px";
				marker.style.width = e.offsetWidth+"px";
			}
				
		
			item.forEach(link => {
				link.addEventListener('click', (e)=>{
					indicator(e.target);
				});
			});
			
			var activeNav = $('.nav-link.active');
			var activewidth = $(activeNav).width();
			var activePadLeft = parseFloat($(activeNav).css('padding-left'));
			var activePadRight = parseFloat($(activeNav).css('padding-right'));
			var totalWidth = activewidth + activePadLeft + activePadRight;
			
			var precedingAnchorWidth = anchorWidthCounter();
		
		
			$(marker).css('display','block');
			
			$(marker).css('width', totalWidth);
		
			function anchorWidthCounter() {
				var anchorWidths = 0;
				var a;
				var aWidth;
				var aPadLeft;
				var aPadRight;
				var aTotalWidth;
				$('.tp-tab-menu button').each(function(index, elem) {
					var activeTest = $(elem).hasClass('active');
					marker.style.left = elem.offsetLeft+"px";
					if(activeTest) {
					// Break out of the each function.
					return false;
					}
			
					a = $(elem).find('button');
					aWidth = a.width();
					aPadLeft = parseFloat(a.css('padding-left'));
					aPadRight = parseFloat(a.css('padding-right'));
					aTotalWidth = aWidth + aPadLeft + aPadRight;
			
					anchorWidths = anchorWidths + aTotalWidth;
	
				});
		
				return anchorWidths;
			}
		}
		tp_tab_line();
	}

	if ($('#marker-vertical').length > 0) {
		function tp_tab_line_2(){
				var marker = document.querySelector('#marker-vertical');
				var item = document.querySelectorAll('.tp-tab-menu button');
				var itemActive = document.querySelector('.tp-tab-menu .nav-link.active');
			
				
			
				function indicator(e){
					marker.style.top = e.offsetTop+"px";
					marker.style.height = e.offsetHeight+"px";
				}
			
			
				item.forEach(link => {
					link.addEventListener('click', (e)=>{
						indicator(e.target);
					});
				});
				var activeNav = $('.nav-link.active');
				var activewidth = $(activeNav).height();
				var activePadLeft = parseFloat($(activeNav).css('padding-top'));
				var activePadRight = parseFloat($(activeNav).css('padding-bottom'));
				var totalWidth = activewidth + activePadLeft + activePadRight;
				
				var precedingAnchorWidth = anchorWidthCounter();
			
			
				$(marker).css('display','block');
				
				$(marker).css('height', totalWidth);
			
				function anchorWidthCounter() {
					var anchorWidths = 0;
					var a;
					var aWidth;
					var aPadLeft;
					var aPadRight;
					var aTotalWidth;
					$('.tp-tab-menu button').each(function(index, elem) {
					  var activeTest = $(elem).hasClass('active');
					  marker.style.top = elem.offsetTop+"px";
					  if(activeTest) {
						// Break out of the each function.
						return false;
					  }
				
					  a = $(elem).find('button');
					  aWidth = a.width();
					  aPadLeft = parseFloat(a.css('padding-top'));
					  aPadRight = parseFloat(a.css('padding-bottom'));
					  aTotalWidth = aWidth + aPadLeft + aPadRight;
				
					  anchorWidths = anchorWidths + aTotalWidth;
			
					});
				
					return anchorWidths;
				  }
	
		}
		tp_tab_line_2();
	}

  

})(jQuery);