(function(){"use strict";function _(t,e){for(let i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);return t}function E(t){if(typeof t>"u"||typeof t[0]>"u")return!1;let e=[],i=t.length,n=t[0].length;for(let a=0;a";this.nav.innerHTML=t,this.el.appendChild(this.nav),this.navDots=[].slice.call(this.nav.children)},h.prototype._initEvents=function(){let t=this,e=this.el.classList.contains("photostack-start"),i=function(){let n=function(){t.el.classList.add("photostack-transition")};e?(this.removeEventListener("click",i),t.el.classList.remove("photostack-start"),n()):(t.openDefault=!0,setTimeout(n,25)),t.started=!0,t._showPhoto(t.current)};e?(this._shuffle(),this.el.addEventListener("click",i)):i(),this.navDots.forEach(function(n,r){n.addEventListener("click",function(){if(r===t.current)t._rotateItem();else{let o=function(){t._showPhoto(r)};t.flipped?t._rotateItem(o):o()}})})},h.prototype._resizeHandler=function(){let t=this;function e(){t._resize(),t._resizeTimeout=null}this._resizeTimeout&&clearTimeout(this._resizeTimeout),this._resizeTimeout=setTimeout(e,100)},h.prototype._resize=function(){let t=this,e=function(){t._shuffle(!0)};this._getSizes(),this.started&&this.flipped?this._rotateItem(e):e()},h.prototype._showPhoto=function(t){if(this.isShuffling)return!1;this.isShuffling=!0,this.currentItem.classList.contains("photostack-flip")&&(this._removeItemPerspective(),this.navDots[this.current].classList.remove("flippable")),this.navDots[this.current].classList.remove("current"),this.currentItem.classList.remove("photostack-current"),this.current=t,this.currentItem=this.items[this.current],this.navDots[this.current].classList.add("current"),this.currentItem.querySelector(".photostack-back")&&this.navDots[t].classList.add("flippable"),this._shuffle()},h.prototype._shuffle=function(t){let e=t?1:this.currentItem.getAttribute("data-shuffle-iteration")||1;(e<=0||!this.started||this.openDefault)&&(e=1),this.openDefault&&(this.currentItem.classList.add("photostack-flip"),this.openDefault=!1,this.isShuffling=!1);let i=.5,n=Math.ceil(this.sizes.inner.width/(this.sizes.item.width*i)),r=Math.ceil(this.sizes.inner.height/(this.sizes.item.height*i)),o=n*this.sizes.item.width*i+this.sizes.item.width/2-this.sizes.inner.width,a=r*this.sizes.item.height*i+this.sizes.item.height/2-this.sizes.inner.height,f=o/2,u=a/2,m=35,p=-35,s=this,L=function(){--e;let v=[];for(let c=0;c0?L.call():(s.currentItem.classList.add("photostack-flip"),s.isShuffling=!1,typeof s.options.callback=="function"&&s.options.callback(s.currentItem)))};s.items.indexOf(c)===s.current&&s.started&&e===0?(s.currentItem.style.WebkitTransform="translate("+s.centerItem.x+"px,"+s.centerItem.y+"px) rotate(0deg)",s.currentItem.style.msTransform="translate("+s.centerItem.x+"px,"+s.centerItem.y+"px) rotate(0deg)",s.currentItem.style.transform="translate("+s.centerItem.x+"px,"+s.centerItem.y+"px) rotate(0deg)",s.currentItem.querySelector(".photostack-back")&&s._addItemPerspective(),s.currentItem.classList.add("photostack-current")):(c.style.WebkitTransform="translate("+l.x+"px,"+l.y+"px) rotate("+Math.floor(Math.random()*(m-p+1)+p)+"deg)",c.style.msTransform="translate("+l.x+"px,"+l.y+"px) rotate("+Math.floor(Math.random()*(m-p+1)+p)+"deg)",c.style.transform="translate("+l.x+"px,"+l.y+"px) rotate("+Math.floor(Math.random()*(m-p+1)+p)+"deg)"),s.started&&c.addEventListener("transitionend",d)})};L.call()},h.prototype._getSizes=function(){this.sizes={inner:{width:this.inner.offsetWidth,height:this.inner.offsetHeight},item:{width:this.currentItem.offsetWidth,height:this.currentItem.offsetHeight}},this.centerItem={x:this.sizes.inner.width/2-this.sizes.item.width/2,y:this.sizes.inner.height/2-this.sizes.item.height/2}},h.prototype._isOverlapping=function(t){let e=this.sizes.item.width+this.sizes.item.width/3,i=this.sizes.item.height+this.sizes.item.height/3,n={x:this.sizes.inner.width/2-e/2,y:this.sizes.inner.height/2-i/2},r=this.sizes.item.width,o=this.sizes.item.height;if(!(t.x+rn.x+e||t.y+on.y+i)){let a=Math.random()<.5,f=Math.floor(Math.random()*(r/4+1)),u=Math.floor(Math.random()*(o/4+1)),m=a?(t.x-n.x+r)*-1-f:n.x+e-(t.x+r)+r+f,p=a?(t.y-n.y+o)*-1-u:n.y+i-(t.y+o)+o+u;return{overlapping:!0,noOverlap:{x:m,y:p}}}return{overlapping:!1}},h.prototype._addItemPerspective=function(){this.el.classList.add("photostack-perspective")},h.prototype._removeItemPerspective=function(){this.el.classList.remove("photostack-perspective"),this.currentItem.classList.remove("photostack-flip")},h.prototype._rotateItem=function(t){if(this.el.classList.contains("photostack-perspective")&&!this.isRotating&&!this.isShuffling){this.isRotating=!0;let e=this,i=function(){this.removeEventListener("transitionend",i),e.isRotating=!1,typeof t=="function"&&t()};this.flipped?(this.navDots[this.current].classList.remove("flip"),this.currentItem.style.WebkitTransform="translate("+this.centerItem.x+"px,"+this.centerItem.y+"px) rotateY(0deg)",this.currentItem.style.transform="translate("+this.centerItem.x+"px,"+this.centerItem.y+"px) rotateY(0deg)"):(this.navDots[this.current].classList.add("flip"),this.currentItem.style.WebkitTransform="translate("+this.centerItem.x+"px,"+this.centerItem.y+"px) translate("+this.sizes.item.width+"px) rotateY(-179.9deg)",this.currentItem.style.transform="translate("+this.centerItem.x+"px,"+this.centerItem.y+"px) translate("+this.sizes.item.width+"px) rotateY(-179.9deg)"),this.flipped=!this.flipped,this.currentItem.addEventListener("transitionend",i),this.currentItem.addEventListener("transitionstart",function n(r){const o=getComputedStyle(e.currentItem),f=parseFloat(o.transitionDuration)*1e3/2;setTimeout(()=>{e.flipped?e.currentItem.classList.add("photostack-flipped"):e.currentItem.classList.remove("photostack-flipped")},f),e.currentItem.removeEventListener("transitionstart",n)})}},window.Photostack=h})();