// Cache selectors
var lastId,
	topMenu = $("#top-menu"),
	topMenuHeight = topMenu.outerHeight(),
	// All list items
	menuItems = topMenu.find("a"),
	// Anchors corresponding to menu items
	scrollItems = menuItems.map(function(){
	  var item = $($(this).attr("href"));
	  if (item.length) { return item; }
	});

// Bind click handler to menu items
// so we can get a fancy scroll animation
menuItems.click(function(e){
	var href = $(this).attr("href"),
		offsetTop = href === "#" ? 0 : $(href).offset().top-100;
	$('html, body').stop().animate({ 
		scrollTop: offsetTop
	}, 300);
	e.preventDefault();
});

// Bind to scroll
$(window).scroll(function(){
   // Get container scroll position
   var fromTop = $(this).scrollTop()+topMenuHeight;
   
   // Get id of current scroll item
   var cur = scrollItems.map(function(){
	 if ($(this).offset().top < fromTop)
	   return this;
   });
   // Get the id of the current element
   cur = cur[cur.length-1];
   var id = cur && cur.length ? cur[0].id : "";
   
   if (lastId !== id) {
	   lastId = id;
	   // Set/remove active class
	   menuItems
		 .parent().removeClass("active")
		 .end().filter("[href='#"+id+"']").parent().addClass("active");
   }                   
});

$(document).ready(function(){
	/* image popup start */
	var images = $('img.hs_screen')
	images.each(
		(index, item)=>
		{
			$(item).wrap(`<a class="hs_img_popup" href="${item.src}"></a>`)
		}
	)
	$('.hs_img_popup').magnificPopup({
	  type: 'image'
	});
	/* image popup end */
	
	/* custom scroll bar start */
	if($(".hs_custom_scrollbar").length){
		$(".hs_custom_scrollbar").mCustomScrollbar({
			scrollInertia:200,
		});
	}
	if($(".hs_custom_scrollbar_x").length){
		$(".hs_custom_scrollbar_x").mCustomScrollbar({
			scrollInertia:200,
			axis:"x"
		});
	}
	/* custom scroll bar end */

	/* dropdown nav start */
	$('.hs_dd_nav > .dd_toggle').on('click', function(){
		$('#top-menu > li > ul').slideUp(200);
		$(this).next('ul').slideDown(200);
	});
	/* dropdown nav end */

});