$(document).ready(function () {
	$('.dropdown').css('pointer-events', 'auto');

	$('#nav-lower-container .dropdown.hidden-xs').on('mouseenter mouseleave', function (event) {
		event.stopPropagation();
		event.preventDefault();
		$(this).toggleClass("open");
	});

	$('#nav-lower-container .dropdown.visible-xs').on('show.bs.dropdown', function () {$(this).find('.caret').addClass('down');});

	$('#nav-lower-container .dropdown.visible-xs').on('hide.bs.dropdown', function () {$(this).find('.caret').removeClass('down');});

	$('.navbar-collapse').on('shown.bs.collapse', function () {
		//$('body').css('overflow', 'hidden')
		$('body').addClass('sidenav-open');
	})

	$('.navbar-collapse').on('hidden.bs.collapse', function () {
		//$('body').css('overflow', 'visible')
		$('body').removeClass('sidenav-open');
	})

	/*$(window).resize(function() {
		if($(window).width() >= 745){
			$("#nav-lower-container").css("width", "auto");
		}
	}).resize();*/

	$(window).on('resize orientationchange', function(){
		if ($(window).width() < 768) {
			var sizeMenuHeight = $(window).height() - $('.navbar-fixed-top').height();
			$('#nav-lower-container').css({'max-height': sizeMenuHeight+'px', 'overflow-y': 'auto'});
		}
	}).resize();

	var nav = $('#nav-lower.homepage');
	var nav_class = 'nav-shadow';
	var threshold = 620;

	$(window).scroll(function () {
		var distance = $(this).scrollTop();
		if (distance > threshold) { // If scrolled past threshold
			nav.addClass(nav_class); // Add class to nav
		}
		else { // If user scrolls back to top
			if (nav.hasClass(nav_class)) { // And if class has been added
				nav.removeClass(nav_class); // Remove it
			}
		}
	});

	$('a[href*="#ep-scroll-"]').on('click', function (e) {
		e.preventDefault();
		var $that = $(this),
		target = $that.attr('href');
		if ($(target).length) {
			$('html, body').animate({
				scrollTop: $(target).offset().top - $('.navbar-fixed-top').height()
			}, 1000);
		}
	});

	$('.scroll-button').on('click', function(e){
		e.preventDefault();
		var $that = $(this);
		$('html, body').animate({
			scrollTop: $that.siblings('.container').offset().top - $('.navbar-fixed-top').height()
		},1000);
	});
});
