document.addEventListener('DOMContentLoaded', function () { // 네비게이션 메뉴 로직 const navItems = document.querySelectorAll('.nav-item'); const subMenus = document.querySelectorAll('.nav-sub-menu .sub-menu-inner'); const navSubMenu = document.getElementById('nav-sub-menu'); let leaveTimeout; if (navItems.length > 0 && subMenus.length > 0 && navSubMenu) { navItems.forEach(item => { item.addEventListener('mouseenter', function () { clearTimeout(leaveTimeout); const menu = this.getAttribute('data-menu'); // 모든 서브메뉴 숨기기 및 활성 클래스 제거 subMenus.forEach(submenu => { submenu.style.display = 'none'; }); navItems.forEach(navItem => { navItem.classList.remove('active'); }); // 해당 서브메뉴 보이기 및 활성 클래스 추가 const targetSubMenu = document.querySelector(`.sub-menu-inner[data-menu="${menu}"]`); if (targetSubMenu) { targetSubMenu.style.display = 'block'; this.classList.add('active'); navSubMenu.classList.add('active'); } }); }); navSubMenu.addEventListener('mouseleave', function () { this.classList.remove('active'); navItems.forEach(item => item.classList.remove('active')); }); navSubMenu.addEventListener('mouseenter', function () { clearTimeout(leaveTimeout); }); document.querySelector('.top-area').addEventListener('mouseleave', function () { navSubMenu.classList.remove('active'); navItems.forEach(item => item.classList.remove('active')); }); } // 전체메뉴 오버레이 로직 const menuToggle = document.getElementById('menuToggle'); const menuClose = document.getElementById('menuClose'); const fullMenuOverlay = document.getElementById('fullMenuOverlay'); if (menuToggle && menuClose && fullMenuOverlay) { menuToggle.addEventListener('click', () => { fullMenuOverlay.classList.add('active'); }); menuClose.addEventListener('click', () => { fullMenuOverlay.classList.remove('active'); }); } // 아래는 메인페이지 전용 영상 슬라이더 로직 const videos = document.querySelectorAll('.main-bg'); if (videos.length > 0) { // 영상이 있으면(메인페이지)만 영상 관련 코드 실행 const mainVisualPaging = document.querySelector('.main-visual-paging'); const mainVisualTitle = document.querySelector('.main-visual-title'); const progressFills = [ document.getElementById('progress-1'), document.getElementById('progress-2'), document.getElementById('progress-3') ]; let currentVideoIndex = 0; let isTransitioning = false; let autoplayAttempted = false; // Progress fill elements check removed const koreanSlogans = [ { eng: "AI Technology", line1: "AI 모델/데이터 기반, 시계열 및 영상 데이터 특화", line2: "멀티모달 AI와 MLOps 솔루션으로", line3: "미래를 엽니다." }, { eng: "Digital Twin Technology", line1: "현실과 가상을 완벽하게 연결하는", line2: "디지털 트윈 기술로 새로운", line3: "미래를 만들어갑니다." }, { eng: "Big Data Analytics", line1: "빅데이터 분석으로 인사이트를 발견하고", line2: "데이터 기반의 혁신적인", line3: "솔루션을 제공합니다." } ]; function attemptAutoplay() { if (autoplayAttempted) return; autoplayAttempted = true; videos.forEach((video, index) => { video.muted = true; video.playsInline = true; video.loop = false; video.autoplay = true; video.style.display = 'none'; video.pause(); video.currentTime = 0; }); const firstVideo = videos[0]; firstVideo.style.display = 'block'; const playAttempts = [ () => firstVideo.play(), () => new Promise(resolve => { firstVideo.play().then(resolve).catch(() => { document.body.click(); setTimeout(() => firstVideo.play().then(resolve), 100); }); }), () => new Promise(resolve => { setTimeout(() => firstVideo.play().then(resolve), 1000); }) ]; let attemptIndex = 0; const tryNextAttempt = () => { if (attemptIndex < playAttempts.length) { playAttempts[attemptIndex]() .then(() => { startVideoSequence(); }) .catch(error => { attemptIndex++; tryNextAttempt(); }); } else { showPlayButton(); } }; tryNextAttempt(); } function showPlayButton() { const playButton = document.createElement('button'); playButton.textContent = 'Play'; playButton.style.cssText = ` position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 1000; background: rgba(0, 0, 0, 0.8); color: white; border: none; padding: 20px 40px; border-radius: 8px; cursor: pointer; font-size: 18px; font-weight: bold; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); `; playButton.addEventListener('click', () => { playButton.remove(); startVideoSequence(); }); document.querySelector('.main-image').appendChild(playButton); } function initializeVideos() { videos.forEach((video, index) => { video.muted = true; video.playsInline = true; video.loop = false; video.style.display = 'none'; video.pause(); video.currentTime = 0; video.addEventListener('ended', function () { if (index === currentVideoIndex) { nextVideo(); } }); video.addEventListener('play', function () { // Video started playing }); video.addEventListener('error', function (e) { // Video error occurred }); }); } function startVideoSequence() { currentVideoIndex = 0; playCurrentVideo(); } function playCurrentVideo() { if (isTransitioning) return; isTransitioning = true; videos.forEach(video => { video.style.display = 'none'; video.pause(); }); const currentVideo = videos[currentVideoIndex]; currentVideo.style.display = 'block'; if (mainVisualPaging) { mainVisualPaging.textContent = `${String(currentVideoIndex + 1).padStart(2, '0')}/03`; } updateSlogan(currentVideoIndex); resetProgressBars(); const playPromise = currentVideo.play(); if (playPromise !== undefined) { playPromise.then(() => { startProgressBar(currentVideo, currentVideoIndex); isTransitioning = false; }).catch(error => { setTimeout(() => { isTransitioning = false; nextVideo(); }, 1000); }); } } function nextVideo() { currentVideoIndex = (currentVideoIndex + 1) % videos.length; playCurrentVideo(); } function updateSlogan(index) { if (!mainVisualTitle) return; const slogan = koreanSlogans[index]; const engSloganElement = mainVisualTitle.querySelector('.eng-slogan'); const koreanLines = mainVisualTitle.querySelectorAll('div:not(.eng-slogan)'); if (engSloganElement) { engSloganElement.textContent = slogan.eng; } if (koreanLines.length >= 3) { koreanLines[0].textContent = slogan.line1; koreanLines[1].textContent = slogan.line2; koreanLines[2].textContent = slogan.line3; } } function resetProgressBars() { progressFills.forEach(fill => { if (fill) { fill.style.width = '0%'; } }); } function startProgressBar(video, videoIndex) { const progressFill = progressFills[videoIndex]; if (!progressFill) return; const updateProgress = () => { if (video.duration && !isNaN(video.duration) && video.duration > 0) { const progress = (video.currentTime / video.duration) * 100; progressFill.style.width = progress + '%'; } }; video.removeEventListener('timeupdate', updateProgress); video.addEventListener('timeupdate', updateProgress); } if (videos.length > 0) { initializeVideos(); let loadedCount = 0; videos.forEach(video => { video.addEventListener('loadeddata', function () { loadedCount++; if (loadedCount === videos.length) { attemptAutoplay(); } }); }); setTimeout(() => { if (loadedCount < videos.length) { attemptAutoplay(); } }, 5000); } const userInteractionEvents = ['click', 'touchstart', 'keydown', 'scroll']; userInteractionEvents.forEach(eventType => { document.addEventListener(eventType, function () { const currentVideo = videos[currentVideoIndex]; if (currentVideo && currentVideo.paused && !autoplayAttempted) { currentVideo.play().catch(error => { // Failed to play video after user interaction }); } }, { once: true }); }); } // --- 아래부터는 모든 페이지에서 동작해야 하는 코드 --- const tabs = document.querySelectorAll('.headarea-tab'); tabs.forEach(tab => { tab.addEventListener('click', function (e) { if (e.target.closest('a')) return; const link = this.querySelector('a'); if (link && link.href) { window.location.href = link.href; } }); }); // 탭 네비게이션 드롭다운(.dropdown) 마우스 오버/아웃 이벤트 if (document.querySelectorAll('.headarea-tab.dropdown').length > 0) { document.querySelectorAll('.headarea-tab.dropdown').forEach(tab => { tab.addEventListener('mouseenter', function () { this.classList.add('hover'); }); tab.addEventListener('mouseleave', function () { this.classList.remove('hover'); }); }); } // 스크롤 이벤트 처리 const topArea = document.querySelector('.top-area'); if (topArea) { const handleScroll = () => { const scrollPosition = window.scrollY; if (scrollPosition >= 80) { topArea.classList.add('scrolled'); } else { topArea.classList.remove('scrolled'); } }; window.addEventListener('scroll', handleScroll); // 초기 로드 시 스크롤 위치 확인 handleScroll(); } // 스크롤 방향에 따라 .top-area 보이기/숨기기 let lastScrollY = window.scrollY; let ticking = false; function handleFloatingMenu() { const currentScrollY = window.scrollY; if (!topArea) return; if (currentScrollY < 10) { topArea.classList.add('show-on-scroll'); topArea.classList.remove('hide-on-scroll'); } else if (currentScrollY < lastScrollY) { // 위로 스크롤: 메뉴 보이기 topArea.classList.add('show-on-scroll'); topArea.classList.remove('hide-on-scroll'); } else if (currentScrollY > lastScrollY) { // 아래로 스크롤: 메뉴 숨기기 topArea.classList.remove('show-on-scroll'); topArea.classList.add('hide-on-scroll'); } lastScrollY = currentScrollY; ticking = false; } function onScroll() { if (!ticking) { window.requestAnimationFrame(handleFloatingMenu); ticking = true; } } window.addEventListener('scroll', onScroll); // 초기 상태 if (topArea) topArea.classList.add('show-on-scroll'); });