/**
* Luxury Concept
*
* Javascript scripts 
*
*
*/

/* MENU HAMBURGER - OPEN MENU */
let luxuryconceptfree_menu = document.querySelector('.icon-hamburger');
if(luxuryconceptfree_menu){
	luxuryconceptfree_menu.addEventListener("click", function() {
		document.body.classList.toggle('menu-open');
	});
}


/* Add Body class on scroll */
window.addEventListener('scroll', function() {
	if(window.scrollY > 100){
		document.body.classList.add('scroll-down');
	} else {
		document.body.classList.remove('scroll-down');
	}
});


/* Dropdown menu mobile */
if (window.innerWidth < 991) {
	let luxuryconceptfree_items = document.querySelectorAll('.menu > .menu-item-has-children > a');
	luxuryconceptfree_items.forEach((luxuryconceptfree_item) => {
		luxuryconceptfree_item.addEventListener("click", function(e) {
			e.preventDefault();
			luxuryconceptfree_items.forEach((luxuryconceptfree_item_open) => {
				if (luxuryconceptfree_item_open !== this) luxuryconceptfree_item_open.parentNode.classList.remove('open-dropdown');
			});

			luxuryconceptfree_item.parentNode.classList.toggle('open-dropdown');
		});	
	});
}
if (window.innerWidth < 991) {
	let luxuryconceptfree_items = document.querySelectorAll('.sub-menu > .menu-item-has-children > a');
	luxuryconceptfree_items.forEach((luxuryconceptfree_item) => {
		luxuryconceptfree_item.addEventListener("click", function(e) {
			e.preventDefault();
			luxuryconceptfree_items.forEach((luxuryconceptfree_item_open) => {
				//if (luxuryconceptfree_item_open !== this) luxuryconceptfree_item_open.parentNode.classList.remove('open-dropdown');
			});

			luxuryconceptfree_item.parentNode.classList.toggle('open-dropdown');
		});	
	});
}

/* Dropdown menu desktop (fix accessibility) */
if (window.innerWidth > 991) {
	let luxuryconceptfree_items = document.querySelectorAll('.menu > .menu-item-has-children > a');
	luxuryconceptfree_items.forEach((luxuryconceptfree_item) => {
		luxuryconceptfree_item.addEventListener("click", function(e) {
			e.preventDefault();			
			luxuryconceptfree_items.forEach((luxuryconceptfree_item_open) => {
				if (luxuryconceptfree_item_open !== this) luxuryconceptfree_item_open.parentNode.classList.remove('open-dropdown');
			});

			luxuryconceptfree_item.parentNode.classList.toggle('open-dropdown');
		});	
	});
}
if (window.innerWidth > 991) {
	let luxuryconceptfree_items = document.querySelectorAll('.sub-menu > .menu-item-has-children > a');
	luxuryconceptfree_items.forEach((luxuryconceptfree_item) => {
		luxuryconceptfree_item.addEventListener("click", function(e) {
			e.preventDefault();
			luxuryconceptfree_items.forEach((luxuryconceptfree_item_open) => {
				//if (item_open !== this) item_open.parentNode.classList.remove('open-dropdown-sub');
			});

			luxuryconceptfree_item.parentNode.classList.toggle('open-dropdown-sub');
		});	
	});
}


/* Accordion */
let luxuryconceptfree_items = document.querySelectorAll('.accordion .wp-block-column > h3');
luxuryconceptfree_items.forEach((luxuryconceptfree_item) => {
	luxuryconceptfree_item.addEventListener("click", function(e) {
		e.preventDefault();
		luxuryconceptfree_item.nextElementSibling.classList.toggle('open-accordion');
	});	
});


// INTERSECTION OBSERVER API

const luxuryconceptfree_observerOptions = {
  root: null, // Null = based on viewport
  rootMargin: "0px", // Margin for root if desired
  threshold: 0.3 // Percentage of visibility needed to execute function
};

function luxuryconceptfree_observerCallback(entries, observer) {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      // Fade in observed elements that are in view
      entry.target.classList.add('fadeIn');
    }
    else {
      // Fade out observed elements that are not in view
      //entry.target.classList.replace('fadeIn', 'fadeOut');
    }
  });
}

// Grab all relevant elements from DOM
const luxuryconceptfree_fadeElms = document.querySelectorAll('.fade');

// Call function for each element
const luxuryconceptfree_observer = new IntersectionObserver(luxuryconceptfree_observerCallback, luxuryconceptfree_observerOptions);
luxuryconceptfree_fadeElms.forEach(el => luxuryconceptfree_observer.observe(el));