document.addEventListener('DOMContentLoaded', function () { // [BTN] online-consultation const btn = document.getElementById("online-consultation"); if (btn) { setTimeout(() => btn.classList.remove("close"), 2000); } // SP menu const hamburger = document.getElementById('hamburger'); const spMenu = document.getElementById('spMenu'); const closeMenu = document.getElementById('closeMenu'); let scrollPos = 0; if (hamburger && spMenu && closeMenu) { hamburger.addEventListener('click', () => { scrollPos = window.scrollY; spMenu.classList.add('active'); document.body.style.position = 'fixed'; document.body.style.top = `-${scrollPos}px`; document.body.style.width = '100%'; }); closeMenu.addEventListener('click', () => { spMenu.classList.remove('active'); document.body.style.position = ''; document.body.style.top = ''; document.body.style.width = ''; window.scrollTo(0, scrollPos); }); } // side menu const accpanel = document.getElementsByClassName('menuTitle'); for (let i = 0; i < accpanel.length; i++) { const nexttxt = accpanel[i].nextElementSibling; if (!nexttxt || !nexttxt.textContent.trim()) { accpanel[i].classList.add('accnonactive'); } else { accpanel[i].classList.add('accactive'); } } const acc = document.querySelectorAll('.menuTitle.accactive'); acc.forEach(el => { el.addEventListener('click', function () { const panel = this.nextElementSibling; if (!panel) return; if (panel.classList.contains('open')) { panel.classList.remove('open'); this.classList.remove('active'); panel.style.maxHeight = null; } else { panel.classList.add('open'); this.classList.add('active'); panel.style.maxHeight = panel.scrollHeight + 'px'; } }); }); // faq toggle const headers = document.querySelectorAll('#faq h3'); headers.forEach(header => { header.addEventListener('click', () => { const nextDiv = header.nextElementSibling; if (!nextDiv) return; if (nextDiv.style.display === "none" || nextDiv.style.display === "") { nextDiv.style.display = "block"; const height = nextDiv.scrollHeight; nextDiv.style.height = "0px"; requestAnimationFrame(() => { nextDiv.style.height = height + "px"; }); nextDiv.addEventListener('transitionend', function handler() { nextDiv.style.height = ""; nextDiv.removeEventListener('transitionend', handler); }); header.classList.add('open'); } else { const height = nextDiv.scrollHeight; nextDiv.style.height = height + "px"; requestAnimationFrame(() => { nextDiv.style.height = "0px"; }); nextDiv.addEventListener('transitionend', function handler() { nextDiv.style.display = "none"; nextDiv.style.height = ""; nextDiv.removeEventListener('transitionend', handler); }); header.classList.remove('open'); } }); }); // smooth scroll const smoothScrollTrigger = document.querySelectorAll('a[href^="#"]'); const urlHash = window.location.hash; function getHeaderHeight() { return window.innerWidth >= 768 ? 210 : 25; } if (urlHash) { window.scrollTo(0, 0); const target = document.querySelector(urlHash); if (target) { const position = target.offsetTop - getHeaderHeight(); window.scrollTo(0, position); setTimeout(() => { const target = document.querySelector(urlHash); if (target) { const position = target.offsetTop - getHeaderHeight(); window.scrollTo(0, position); } }, 100); } } smoothScrollTrigger.forEach(trigger => { trigger.addEventListener('click', (e) => { e.preventDefault(); const href = trigger.getAttribute('href'); const targetElement = document.getElementById(href.replace('#', '')); if (!targetElement) return; const rect = targetElement.getBoundingClientRect().top; const offset = window.pageYOffset; const gap = getHeaderHeight(); const target = rect + offset - gap; window.scrollTo({ top: target, behavior: 'smooth', }); }); }); }); // popup function w_open(URL, winX, winY) { window.open(URL, "_blank", "width=" + winX + ",height=" + winY + ",location=no,menubar=no,scrollbars=yes,status=no,toolbar=no"); }