(function(){function x(a,b){for(let d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);return a}function A(a){if("undefined"==typeof a||"undefined"==typeof a[0])return!1;var b=[];let d=a.length,g=a[0].length;for(var e=0;e<d;e++)b=b.concat(a[e]);a=b.length;for(var f;a;)f=Math.floor(Math.random()*a--),e=b[a],b[a]=b[f],b[f]=e;a=[];e=0;for(f=0;f<d;f++){let c=[];for(let l=0;l<g;l++)c.push(b[e]),e++;a.push(c)}return a}function h(a,b){this.el=a;this.inner=this.el.querySelector("div");this.allItems=[].slice.call(this.inner.children);
if(this.allItemsCount=this.allItems.length)this.items=[].slice.call(this.inner.querySelectorAll("figure:not([data-dummy])")),this.itemsCount=this.items.length,this.current=0,this.options=x({},this.options),x(this.options,b),this._init()}h.prototype.options={};h.prototype._init=function(){this.currentItem=this.items[this.current];this._addNavigation();this._getSizes();this._initEvents()};h.prototype._addNavigation=function(){this.nav=document.createElement("nav");let a="";for(let b=0;b<this.itemsCount;++b)a+=
"<span></span>";this.nav.innerHTML=a;this.el.appendChild(this.nav);this.navDots=[].slice.call(this.nav.children)};h.prototype._initEvents=function(){let a=this,b=this.el.classList.contains("photostack-start"),d=function(){let g=function(){a.el.classList.add("photostack-transition")};b?(this.removeEventListener("click",d),a.el.classList.remove("photostack-start"),g()):(a.openDefault=!0,setTimeout(g,25));a.started=!0;a._showPhoto(a.current)};b?(this._shuffle(),this.el.addEventListener("click",d)):d();
this.navDots.forEach(function(g,e){g.addEventListener("click",function(){if(e===a.current)a._rotateItem();else{let f=function(){a._showPhoto(e)};a.flipped?a._rotateItem(f):f()}})})};h.prototype._resizeHandler=function(){let a=this;this._resizeTimeout&&clearTimeout(this._resizeTimeout);this._resizeTimeout=setTimeout(function(){a._resize();a._resizeTimeout=null},100)};h.prototype._resize=function(){let a=this,b=function(){a._shuffle(!0)};this._getSizes();this.started&&this.flipped?this._rotateItem(b):
b()};h.prototype._showPhoto=function(a){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=a;this.currentItem=this.items[this.current];this.navDots[this.current].classList.add("current");this.currentItem.querySelector(".photostack-back")&&
this.navDots[a].classList.add("flippable");this._shuffle()};h.prototype._shuffle=function(a){let b=a?1:this.currentItem.getAttribute("data-shuffle-iteration")||1;if(0>=b||!this.started||this.openDefault)b=1;this.openDefault&&(this.currentItem.classList.add("photostack-flip"),this.isShuffling=this.openDefault=!1);let d=Math.ceil(this.sizes.inner.width/(.5*this.sizes.item.width)),g=Math.ceil(this.sizes.inner.height/(.5*this.sizes.item.height)),e=(d*this.sizes.item.width*.5+this.sizes.item.width/2-this.sizes.inner.width)/
2,f=(g*this.sizes.item.height*.5+this.sizes.item.height/2-this.sizes.inner.height)/2,c=this,l=function(){--b;let p=[];for(let k=0;k<g;++k){let m=p[k]=[];for(let n=0;n<d;++n){let r=.5*n*c.sizes.item.width-e,y=.5*k*c.sizes.item.height-f,u=0,v=0;if(c.started&&0===b){let w=c._isOverlapping({x:r,y});if(w.overlapping)switch(u=w.noOverlap.x,v=w.noOverlap.y,Math.floor(3*Math.random())){case 0:u=0;break;case 1:v=0}}m[n]={x:r+u,y:y+v}}}p=A(p);let q=0,t=0,z=0;c.allItems.forEach(function(k){q===d-1?(t=t===g-
1?0:t+1,q=1):++q;var m=p[t][q-1],n=m.x;m=m.y;let r=function(){++z;this.removeEventListener("transitionend",r);z===c.allItemsCount&&(0<b?l.call():(c.currentItem.classList.add("photostack-flip"),c.isShuffling=!1,"function"===typeof c.options.callback&&c.options.callback(c.currentItem)))};c.items.indexOf(k)===c.current&&c.started&&0===b?(c.currentItem.style.WebkitTransform="translate("+c.centerItem.x+"px,"+c.centerItem.y+"px) rotate(0deg)",c.currentItem.style.msTransform="translate("+c.centerItem.x+
"px,"+c.centerItem.y+"px) rotate(0deg)",c.currentItem.style.transform="translate("+c.centerItem.x+"px,"+c.centerItem.y+"px) rotate(0deg)",c.currentItem.querySelector(".photostack-back")&&c._addItemPerspective(),c.currentItem.classList.add("photostack-current")):(k.style.WebkitTransform="translate("+n+"px,"+m+"px) rotate("+Math.floor(71*Math.random()+-35)+"deg)",k.style.msTransform="translate("+n+"px,"+m+"px) rotate("+Math.floor(71*Math.random()+-35)+"deg)",k.style.transform="translate("+n+"px,"+m+
"px) rotate("+Math.floor(71*Math.random()+-35)+"deg)");c.started&&k.addEventListener("transitionend",r)})};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(a){let b=this.sizes.item.width+this.sizes.item.width/
3,d=this.sizes.item.height+this.sizes.item.height/3;var g=this.sizes.inner.width/2-b/2,e=this.sizes.inner.height/2-d/2;let f=this.sizes.item.width,c=this.sizes.item.height;if(!(a.x+f<g||a.x>g+b||a.y+c<e||a.y>e+d)){let l=.5>Math.random(),p=Math.floor(Math.random()*(f/4+1)),q=Math.floor(Math.random()*(c/4+1));return{overlapping:!0,noOverlap:{x:l?-1*(a.x-g+f)-p:g+b-(a.x+f)+f+p,y:l?-1*(a.y-e+c)-q:e+d-(a.y+c)+c+q}}}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(a){if(this.el.classList.contains("photostack-perspective")&&!this.isRotating&&!this.isShuffling){this.isRotating=!0;let b=this,d=function(){this.removeEventListener("transitionend",d);b.isRotating=!1;"function"===typeof a&&a()};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",d)}};window.Photostack=h})();
