var discographypageAlbums = document.querySelectorAll('article .album'), discographypageCurrentAlbumIndex = 0, discographypageNewAlbumIndex = 0, discographypageMaxAlbumIndex = discographypageAlbums.length - 1, discographypageAnimating = false, discographypageThumbnails = document.querySelectorAll('article .thumbnails .thumbnail') ; function discographypageInit() { document.querySelector('article .previous').addEventListener('click', function(event) { discographypageNavigateAlbum(-1); event.preventDefault(); event.stopPropagation(); return false; }); document.querySelector('article .next').addEventListener('click', function(event) { discographypageNavigateAlbum(1); event.preventDefault(); event.stopPropagation(); return false; }); for(var i = 0, n = discographypageMaxAlbumIndex; i <= n; i++) { (function(i) { discographypageThumbnails[i].addEventListener('click', function(event) { discographypageNavigateAlbum(i - discographypageCurrentAlbumIndex); event.preventDefault(); event.stopPropagation(); return false; }); })(i) if(discographypageAlbums[i].querySelector('.info-button')) { discographypageAlbums[i].querySelector('.info-button').addEventListener('click', function(event) { if(this.innerHTML == 'Info') { this.innerHTML = 'Track Listing' this.parentNode.querySelector('.info').className = 'info visible'; this.parentNode.querySelector('.track-listing').className = 'track-listing hidden'; }else { this.innerHTML = 'Info' this.parentNode.querySelector('.info').className = 'info'; this.parentNode.querySelector('.track-listing').className = 'track-listing'; } event.preventDefault(); event.stopPropagation(); return false; }); } } } function discographypageNavigateAlbum(videpageAlbumOffset) { if(videpageAlbumOffset == 0) return; if(discographypageAnimating) return; discographypageAnimating = true; discographypageNewAlbumIndex = discographypageCurrentAlbumIndex + videpageAlbumOffset; if(discographypageNewAlbumIndex < 0) discographypageNewAlbumIndex = discographypageMaxAlbumIndex; if(discographypageNewAlbumIndex > discographypageMaxAlbumIndex) discographypageNewAlbumIndex = 0; if(videpageAlbumOffset > 0) { discographypageAlbums[discographypageNewAlbumIndex].className += ' right'; }else { discographypageAlbums[discographypageNewAlbumIndex].className += ' left'; } discographypageThumbnails[discographypageCurrentAlbumIndex].className = 'thumbnail'; discographypageThumbnails[discographypageNewAlbumIndex].className = 'thumbnail current'; setTimeout(function() { discographypageAlbums[discographypageNewAlbumIndex].className = discographypageAlbums[discographypageNewAlbumIndex].className.replace(/( ?right| ?left)/g, ''); discographypageAlbums[discographypageNewAlbumIndex].className += ' current animate'; discographypageAlbums[discographypageCurrentAlbumIndex].className = discographypageAlbums[discographypageCurrentAlbumIndex].className.replace(/ ?current/, ''); if(videpageAlbumOffset < 0) { discographypageAlbums[discographypageCurrentAlbumIndex].className += ' right animate'; }else { discographypageAlbums[discographypageCurrentAlbumIndex].className += ' left animate'; } setTimeout(function() { discographypageAlbums[discographypageCurrentAlbumIndex].className = discographypageAlbums[discographypageCurrentAlbumIndex].className.replace(/( ?right| ?left| ?animate)/g, ''); discographypageAlbums[discographypageNewAlbumIndex].className = discographypageAlbums[discographypageNewAlbumIndex].className.replace(/( ?right| ?left| ?animate)/g, ''); discographypageCurrentAlbumIndex = discographypageNewAlbumIndex; discographypageAnimating = false; }, 500); }, 50); } discographypageInit();