var pageSideImage = document.querySelector('.image-right'), pageHasSideImage = false, pageSiteImageImg, pageSideImageWidth = 0, pageSideImageHeight = 0, pageSideImageDisplayHeight = 0, windowScrollTop = 0, windowWidth = 0, windowHeight = 0, documentHeight = 0 ; function init() { if(navigator.appVersion.indexOf("Mac") > -1) document.body.className += ' mac'; pageHasSideImage = (pageSideImage != null); if(pageHasSideImage) { pageSiteImageImg = pageSideImage.querySelector('img'); pageHasSideImage = (pageSiteImageImg != null); } if(pageHasSideImage) { pageSideImageWidth = pageSiteImageImg.width; pageSideImageHeight = pageSiteImageImg.height; } document.querySelector('header nav .mobile-button').addEventListener('click', function(event) { if(document.querySelector('header nav').className.indexOf('visible') > -1) document.querySelector('header nav').className = ''; else document.querySelector('header nav').className = 'visible'; event.preventDefault(); event.stopPropagation(); return false; }); document.querySelector('header .newsletter').addEventListener('click', function(event) { document.getElementById('newsletter-lightbox').className = 'open'; event.preventDefault(); event.stopPropagation(); return false; }); document.querySelector('#newsletter-lightbox .cancel').addEventListener('click', function(event) { document.getElementById('newsletter-lightbox').className = ''; event.preventDefault(); event.stopPropagation(); return false; }); document.querySelector('#newsletter-lightbox .close').addEventListener('click', function(event) { document.getElementById('newsletter-lightbox').className = 'thanks'; document.location.hash = ''; event.preventDefault(); event.stopPropagation(); return false; }); if(document.location.hash == '#thanks') { document.getElementById('newsletter-lightbox').className = 'open thanks'; } window.addEventListener('resize', handleWindowResize); handleWindowResize(); window.addEventListener('scroll', handleWindowScroll); handleWindowScroll(); setTimeout(function() { document.body.className += ' loaded'; }, 500); } function handleWindowResize() { windowWidth = Math.max(document.documentElement.clientWidth || document.body.clientWidth); windowHeight = Math.max(document.documentElement.clientHeight || document.body.clientHeight); documentHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight, windowHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight); if(pageHasSideImage) { pageSideImageDisplayHeight = (windowWidth * 0.48) * pageSideImageHeight / pageSideImageWidth; } } function handleWindowScroll() { windowScrollTop = document.body.scrollTop || document.documentElement.scrollTop; if(windowWidth > 700) { if(pageHasSideImage) { pageSideImage.style.backgroundPosition = 'right ' + ((windowScrollTop / (documentHeight - windowHeight)) * (pageSideImageDisplayHeight - windowHeight) * -1) + 'px'; } } } init();