(function(){ "use strict"; /* ========================================================= HEADER ========================================================= */ function initHeaderScroll(){ var body=document.body; if(!body)return; function update(){ var y=window.scrollY||window.pageYOffset||0; body.classList.toggle("has-scrolled",y>32); } update(); window.addEventListener("scroll",update,{passive:true}); window.addEventListener("resize",update); } /* ========================================================= 01 HERO VIDEO ========================================================= */ function initHeroVideo(){ var hero=document.getElementById("imsHero"); if(!hero)return; var videos=[].slice.call(hero.querySelectorAll(".ims-hero-video")); if(!videos.length)return; var current=0; function play(index){ videos.forEach(function(video,i){ var active=i===index; video.classList.toggle("is-active",active); if(!active){ try{video.pause();video.currentTime=0;}catch(e){} } }); var video=videos[index]; if(!video)return; try{ video.currentTime=0; var promise=video.play(); if(promise&&typeof promise.catch==="function"){ promise.catch(function(){}); } }catch(e){} } videos.forEach(function(video,index){ video.loop=false; video.addEventListener("ended",function(){ current=(index+1)%videos.length; play(current); }); }); play(0); } /* ========================================================= 03 PERFORMANCE — AUTO ROLL ========================================================= */ function initPerformance(){ var section=document.getElementById("imsPerformance"); if(!section)return; var accordion=section.querySelector(".ims-performance-accordion"); var items=[].slice.call(section.querySelectorAll(".ims-performance-item")); if(!accordion||!items.length)return; var current=0,timer=null,delay=3000,visible=true; function activate(index){ if(index<0||index>=items.length)return; current=index; items.forEach(function(item,i){ var active=i===index; item.classList.toggle("is-active",active); item.setAttribute("aria-expanded",active?"true":"false"); }); } function next(){activate((current+1)%items.length);} function stop(){ if(!timer)return; window.clearInterval(timer); timer=null; } function start(){ stop(); if(document.hidden||!visible||items.length<2)return; timer=window.setInterval(next,delay); } items.forEach(function(item,index){ item.addEventListener("mouseenter",function(){stop();activate(index);}); item.addEventListener("focus",function(){stop();activate(index);}); item.addEventListener("click",function(){stop();activate(index);}); }); accordion.addEventListener("mouseenter",stop); accordion.addEventListener("mouseleave",start); accordion.addEventListener("focusout",function(e){ if(!accordion.contains(e.relatedTarget))start(); }); document.addEventListener("visibilitychange",function(){ if(document.hidden)stop();else start(); }); if("IntersectionObserver" in window){ var observer=new IntersectionObserver(function(entries){ entries.forEach(function(entry){ visible=entry.isIntersecting; if(visible)start();else stop(); }); },{threshold:.2}); observer.observe(section); } activate(0); start(); } /* ========================================================= 04 PROJECT FILTER UI ========================================================= */ function initProjectFilterUI(){ var buttons=[].slice.call(document.querySelectorAll(".ims-project-filter button")); if(!buttons.length)return; buttons.forEach(function(button){ button.addEventListener("click",function(){ buttons.forEach(function(el){el.classList.remove("is-active");}); button.classList.add("is-active"); }); }); } /* ========================================================= FOOTER FAMILY SITE ========================================================= */ function initFamilySite(){ var selects=[].slice.call(document.querySelectorAll(".ims-footer-family select")); if(!selects.length)return; selects.forEach(function(select){ select.addEventListener("change",function(){ var url=select.value; if(!url)return; window.open(url,"_blank"); select.selectedIndex=0; }); }); } /* ========================================================= PRODUCT LANDING — SELECT PRODUCT ========================================================= */ function initProductChooser(){ var wrapper=document.getElementById("imsProductChoose"); if(!wrapper)return; var nav=wrapper.querySelector(".ims-pl-tabs"); var tabs=[].slice.call(wrapper.querySelectorAll("[data-pl-tab]")); var panels=[].slice.call(wrapper.querySelectorAll(".ims-pl-panel")); if(!nav||!tabs.length||tabs.length!==panels.length)return; var current=0; var timer=null; var delay=4500; var navHover=false; var keyboardFocus=false; var reducedMotion=window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches; function activate(index){ current=(index+tabs.length)%tabs.length; tabs.forEach(function(tab,i){ var active=i===current; tab.classList.toggle("is-active",active); tab.setAttribute("aria-selected",active?"true":"false"); tab.tabIndex=active?0:-1; }); panels.forEach(function(panel,i){panel.hidden=i!==current;}); } function resetProgress(){ nav.classList.remove("is-rolling"); void nav.offsetWidth; nav.classList.add("is-rolling"); } function stop(){ if(timer!==null){window.clearInterval(timer);timer=null;} nav.classList.add("is-paused"); } function start(){ stop(); if(document.hidden||navHover||keyboardFocus||reducedMotion||tabs.length<2)return; nav.classList.remove("is-paused"); resetProgress(); timer=window.setInterval(function(){activate(current+1);resetProgress();},delay); } tabs.forEach(function(tab,index){ tab.addEventListener("click",function(){ activate(index); keyboardFocus=false; start(); }); tab.addEventListener("keydown",function(e){ if(["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"].indexOf(e.key)<0)return; e.preventDefault(); keyboardFocus=true; stop(); var next=e.key==="Home"?0:e.key==="End"?tabs.length-1: (index+(["ArrowDown","ArrowRight"].indexOf(e.key)>=0?1:-1)+tabs.length)%tabs.length; activate(next); resetProgress(); tabs[next].focus(); }); }); nav.addEventListener("mouseenter",function(){navHover=true;stop();}); nav.addEventListener("mouseleave",function(){navHover=false;keyboardFocus=false;start();}); nav.addEventListener("focusin",function(e){ if(e.detail===0&&!navHover){keyboardFocus=true;stop();} }); nav.addEventListener("focusout",function(e){ if(!nav.contains(e.relatedTarget)){keyboardFocus=false;start();} }); document.addEventListener("visibilitychange",start); activate(0); start(); } /* ========================================================= IMS-01 PRODUCT DETAIL — CONSTRUCTION GALLERY ========================================================= */ function initProductDetailGallery(){ var galleries=[].slice.call(document.querySelectorAll("[data-product-gallery]")); galleries.forEach(function(gallery){ var main=gallery.querySelector("[data-gallery-main]"); var prev=gallery.querySelector("[data-gallery-prev]"); var next=gallery.querySelector("[data-gallery-next]"); var currentLabel=gallery.querySelector("[data-gallery-current]"); var totalLabel=gallery.querySelector(".ims-pd-gallery-count em"); var thumbs=[].slice.call(gallery.querySelectorAll("[data-gallery-thumb]")); if(!main||!thumbs.length)return; var current=0; var mainAlt=main.getAttribute("alt")||"시공사례"; function show(index){ current=(index+thumbs.length)%thumbs.length; var thumb=thumbs[current]; var src=thumb.getAttribute("data-src"); if(src)main.setAttribute("src",src); main.setAttribute("alt",mainAlt+" "+(current+1)); thumbs.forEach(function(button,i){ var selected=i===current; button.classList.toggle("is-active",selected); button.setAttribute("aria-pressed",selected?"true":"false"); }); if(currentLabel)currentLabel.textContent=String(current+1).padStart(2,"0"); if(totalLabel)totalLabel.textContent=String(thumbs.length).padStart(2,"0"); } var autoTimer=null; function restartAuto(){ if(autoTimer!==null)window.clearInterval(autoTimer); if(thumbs.length<2)return; autoTimer=window.setInterval(function(){ if(!document.hidden)show(current+1); },4500); } thumbs.forEach(function(button,index){ button.addEventListener("click",function(){show(index);restartAuto();}); }); if(prev)prev.addEventListener("click",function(){show(current-1);restartAuto();}); if(next)next.addEventListener("click",function(){show(current+1);restartAuto();}); show(0); restartAuto(); }); } /* ========================================================= INIT ========================================================= */ function init(){ initHeaderScroll(); initHeroVideo(); initPerformance(); initProjectFilterUI(); initFamilySite(); initProductChooser(); initProductDetailGallery(); } if(document.readyState==="loading"){ document.addEventListener("DOMContentLoaded",init); }else{ init(); } })();