$(function() {
	var $body = $('body')
	var $header = $('.js-header')
	var $logo = $('.js-dropdown-logo')
	var logoUrl = $logo.attr('src')
	var $menuMobileToggle = $('.js-menu-mobile-toggle')
	var $menuMobileBox = $('.js-menu-mobile-box')

	function init() {
		if ($header.hasClass('--dark')) {
			isDark = true
		}

		$menuMobileToggle.on('click', function() {
			if ($(this).hasClass('is-active')) {
				$(this).removeClass('is-active')
				$body.removeClass('overflow-hidden')
				$header.removeClass('is-active')
				$logo.attr('src', logoUrl)
				$menuMobileBox.removeClass('is-active')

				if (isDark) {
					$header.addClass('--dark')
				}
			} else {
				$(this).addClass('is-active')
				$body.addClass('overflow-hidden')
				$header.addClass('is-active')
				$logo.attr('src', logoUrl.replace('-white', ''))
				$menuMobileBox.addClass('is-active')

				if (isDark) {
					$header.removeClass('--dark')
				}
			}
		})

		var $accordionMenuToggle = $('.js-accordion-mobile-toggle')
		var $accordionMenuBox = $('.js-accordion-mobile-box')

		$accordionMenuToggle.on('click', function(e) {
			e.preventDefault()
			$(this).toggleClass('is-active')
			$(this)
				.parent()
				.find($accordionMenuBox)
				.toggleClass('is-active')
		})
	}

	function closeMobileMenuOnResize() {
		var w = $(window).width()

		if (w >= 1366 && $header.hasClass('is-active')) {
			$menuMobileToggle.click()
		}
	}

	var id
	$(window).resize(function() {
		clearTimeout(id)
		id = setTimeout(closeMobileMenuOnResize, 20)
	})

	init()
})
