(function(){
var slideshowState = {
activeSeason: "hiver",
timer: null,
currentIndex: 0
};
function getActiveSlides() {
return document.querySelectorAll(".cml-home-slide[data-season=\"" + slideshowState.activeSeason + "\"]");
}
function showSlide(i) {
var slides = getActiveSlides();
var dots = document.querySelectorAll(".cml-home-dot");
if (!slides.length) return;
// Cacher TOUS les slides (hiver + été)
document.querySelectorAll(".cml-home-slide").forEach(function(s){
s.classList.remove("cml-active");
});
dots.forEach(function(d){ d.classList.remove("cml-active"); });
// Activer seulement le i-ième de la saison active
if (slides[i]) slides[i].classList.add("cml-active");
if (dots[i]) dots[i].classList.add("cml-active");
slideshowState.currentIndex = i;
}
function nextSlide() {
var slides = getActiveSlides();
if (!slides.length) return;
var next = (slideshowState.currentIndex + 1) % slides.length;
showSlide(next);
}
function startSlideshow() {
stopSlideshow();
slideshowState.timer = setInterval(nextSlide, 5000);
}
function stopSlideshow() {
if (slideshowState.timer) clearInterval(slideshowState.timer);
}
function changeSeasonSlides(season) {
slideshowState.activeSeason = season;
slideshowState.currentIndex = 0;
// Mettre à jour l'attribut data-active-season sur le wrap
var slidesWrap = document.querySelector(".cml-home-slides");
if (slidesWrap) slidesWrap.setAttribute("data-active-season", season);
// Reset et démarrer avec la 1ère photo de la nouvelle saison
showSlide(0);
startSlideshow();
}
function initSlideshow() {
var slides = document.querySelectorAll(".cml-home-slide");
var dots = document.querySelectorAll(".cml-home-dot");
if (slides.length < 2) return;
// Initialiser : afficher la 1ère slide de la saison active
showSlide(0);
// Click sur dots
dots.forEach(function(dot, i) {
dot.addEventListener("click", function() {
showSlide(i);
startSlideshow();
});
});
startSlideshow();
}
function getCurrentSeason() {
var month = new Date().getMonth() + 1;
if (month >= 12 || month <= 3) return "hiver";
if (month >= 4 && month <= 6) return "printemps";
if (month >= 7 && month <= 9) return "ete";
return "automne";
}
function applySeason(season) {
// Normaliser : printemps→ete, automne→hiver pour le slideshow
var slideSeasonKey = (season === "printemps" || season === "ete") ? "ete" : "hiver";
document.querySelectorAll(".cml-season-btn").forEach(function(btn){
btn.classList.remove("cml-active");
var btnSeason = btn.getAttribute("data-season");
if (btnSeason === slideSeasonKey) {
btn.classList.add("cml-active");
}
});
document.querySelectorAll(".cml-earlybird, .cml-seasonal").forEach(function(s){
s.classList.remove("cml-season-show");
var when = s.getAttribute("data-show-when");
if (when && when.split(",").indexOf(season) >= 0) {
s.classList.add("cml-season-show");
}
});
// Changer le slideshow hero
changeSeasonSlides(slideSeasonKey);
}
function initSeasonToggle() {
document.querySelectorAll(".cml-season-btn").forEach(function(btn){
btn.addEventListener("click", function(){
applySeason(this.getAttribute("data-season"));
});
});
}
function initDateSync() {
var checkin = document.getElementById("cml_checkin");
var checkout = document.getElementById("cml_checkout");
var hiddenIn = document.getElementById("check_in_date_cml_home");
var hiddenOut = document.getElementById("check_out_date_cml_home");
if (!checkin || !checkout || !hiddenIn || !hiddenOut) return;
var monthsEn = ["January","February","March","April","May","June","July","August","September","October","November","December"];
function isoToUS(iso) {
if (!iso) return "";
var p = iso.split("-");
if (p.length !== 3) return iso;
return monthsEn[parseInt(p[1],10)-1] + " " + parseInt(p[2],10) + ", " + p[0];
}
function syncDates() {
hiddenIn.value = isoToUS(checkin.value);
hiddenOut.value = isoToUS(checkout.value);
}
function ensureCheckoutAfterCheckin() {
if (!checkin.value || !checkout.value) return;
var inDate = new Date(checkin.value);
var outDate = new Date(checkout.value);
if (outDate <= inDate) {
var nextDay = new Date(inDate);
nextDay.setDate(inDate.getDate() + 1);
var y = nextDay.getFullYear();
var m = String(nextDay.getMonth() + 1).padStart(2, "0");
var d = String(nextDay.getDate()).padStart(2, "0");
checkout.value = y + "-" + m + "-" + d;
}
var minCheckout = new Date(inDate);
minCheckout.setDate(inDate.getDate() + 1);
var y2 = minCheckout.getFullYear();
var m2 = String(minCheckout.getMonth() + 1).padStart(2, "0");
var d2 = String(minCheckout.getDate()).padStart(2, "0");
checkout.min = y2 + "-" + m2 + "-" + d2;
}
checkin.addEventListener("change", function() {
ensureCheckoutAfterCheckin();
syncDates();
});
checkout.addEventListener("change", syncDates);
syncDates();
}
function init() {
initSlideshow();
initSeasonToggle();
initDateSync();
applySeason("hiver"); // Forcé hiver par défaut
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();
// ============================================================================
// V13 — Animation apparition cards Atouts (IntersectionObserver)
// ============================================================================
(function() {
if (!('IntersectionObserver' in window)) {
// Fallback : tout visible
document.querySelectorAll('.cml-why-card').forEach(function(c){ c.classList.add('cml-visible'); });
return;
}
function initWhyCardsAnimation() {
var cards = document.querySelectorAll('.cml-why-card');
if (!cards.length) return;
var observer = new IntersectionObserver(function(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
entry.target.classList.add('cml-visible');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.15,
rootMargin: '0px 0px -40px 0px'
});
cards.forEach(function(card){ observer.observe(card); });
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initWhyCardsAnimation);
} else {
initWhyCardsAnimation();
}
})();
// ============================================================================
// V14 — Timeline Saisons : toggle Hiver/Été
// ============================================================================
(function() {
function initSeasonToggle() {
var section = document.querySelector('.cml-why-timeline');
if (!section) return;
var btns = section.querySelectorAll('.cml-why-tl-btn');
btns.forEach(function(btn) {
btn.addEventListener('click', function() {
var season = this.dataset.season;
// Activer le bouton
btns.forEach(function(b) { b.classList.remove('cml-why-tl-btn-active'); });
this.classList.add('cml-why-tl-btn-active');
// Afficher la bonne photo
section.querySelectorAll('.cml-why-tl-photo').forEach(function(p) {
p.style.display = p.dataset.season === season ? 'block' : 'none';
});
// Afficher le bon contenu
section.querySelectorAll('.cml-why-tl-content').forEach(function(c) {
c.style.display = c.dataset.season === season ? 'flex' : 'none';
});
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initSeasonToggle);
} else {
initSeasonToggle();
}
})();