
var M={assets:{},options:{},mainIntId:0,mainBusy:false,controlsVisible:false,currentAlbum:0,lastInput:0,gallery:true,controlHideInt:0,covered:true,playing:false,playIntId:0,flipped:false,onStage:[],currentVideo:false,videoPlaying:false,videoSeeking:false,coverProgress:0,loadN:4,firstLoad:true,contentCache:{},dead:function(e){e.preventDefault();},devices:{'iPad':{apple:true,typeClass:'large',nativeVideo:false,thumbSize:73,albumSize:[203,91],delay:0,offset:{top:1,bottom:1}},'iPhone':{apple:true,typeClass:'small',nativeVideo:true,four:false,thumbSize:56,albumSize:[154,70],delay:0,offset:{top:1,bottom:1}},'Android':{apple:false,typeClass:'small',nativeVideo:true,thumbSize:56,albumSize:[154,70],delay:250,offset:{top:-1,bottom:4}}},spinner:function(elem,clear){clear=clear||false;var outer=document.createElement('div');var inner=document.createElement('div');if(clear){outer.className='spinnerTransparent';}else{outer.className='spinner';};inner.className='spinnerWrap';for(i=0;i<12;i++){var _b=document.createElement('div');_b.style.webkitTransform='rotate('+(i*30)+'deg) translate(0, -18px)';var o=i/12;o=Math.max(o,0.15);_b.style.opacity=o;inner.appendChild(_b);};outer.appendChild(inner);elem.appendChild(outer);return outer;},e:function(element,style,klass){if(typeof element=='string'){element=document.createElement(element);};for(var i in style){if((i=='webkitTransformStyle'||i=='webkitPerspective'||i=='webkitBackfaceVisibility')&&!this.device.apple){continue;};element.style[i]=style[i];};if(klass){element.className=klass;};return element;},setScreen:function(cb){this.scroll();var self=this;window.setTimeout(function(){var screenDims=[window.innerWidth,window.innerHeight];if(self.portrait&&!self.device.portrait){self.device.portrait=screenDims;}else if(!self.portrait&&!self.device.landscape){self.device.landscape=screenDims;};var dims=self.device[self.portrait?'portrait':'landscape'];self.options.width=dims[0];self.options.height=dims[1];var halfW=self.options.width/2;var halfH=self.options.height/2;self.videoBttnTarget={min:{x:halfW-42,y:halfH-42},max:{x:halfW+42,y:halfH+42}};cb.call(self);},this.device.delay);},monitorControls:function(){if(this.controlsVisible&&(+new Date-this.lastInput)>5000){this.toggleControls();};},setControlsOffScreen:function(){this.e(this.nextBttn,{webkitTransition:'',webkitTransform:'translate3d(2000px,0,0)'});this.e(this.thumbDrawer.container,{webkitTransition:'',webkitTransform:'translate3d(0,2000px,0)'});if(!this.flipped&&this.showInfoButton){this.e(this.infoBttn,{webkitTransition:'',webkitTransform:'translate3d(2000px,0,0)'});};},toggleControls:function(keepInfo){if(this.flipped){return;};keepInfo=keepInfo||false;window.clearTimeout(this.controlHideInt);var self=this;if(this.controlsVisible){this.e(this.nextBttn,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d(0px,0,0)'});this.e(this.prevBttn,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d(0px,0,0)'});this.e(this.playBttn,{webkitTransform:'translate3d(0px,0,0)'});if(this.showBackBttn){this.e(this.backBttn,{webkitTransform:'translate3d(0px,0,0)'});};if(!keepInfo&&this.showInfoButton){this.e(this.infoBttn,{webkitTransform:'translate3d(0px,0,0)'});};this.e(this.thumbDrawer.container,{webkitTransform:'translate3d(0,0px,0)'});window.setTimeout(function(){M.e(M.playBttn,{zIndex:14000});if(M.showInfoButton){M.e(M.infoBttn,{zIndex:15000});};if(M.showBackBttn){M.e(M.backBttn,{zIndex:15001});};},500);if(this.gallery){this.e(this.albumDrawer.container,{webkitTransform:'translate3d(0,0px,0)'});this.albumDrawer.visible=false;};this.thumbDrawer.visible=false;this.controlHideInt=window.setTimeout(function(){self.setControlsOffScreen();},1000);}else{this.e(this.nextBttn,{webkitTransition:'',webkitTransform:'translate3d(0px,0,0)'});if(!keepInfo&&this.showInfoButton){this.e(this.infoBttn,{webkitTransition:'',webkitTransform:'translate3d(0px,0,0)'});};this.e(this.thumbDrawer.container,{webkitTransition:'',webkitTransform:'translate3d(0,0px,0)'});var o=[74,70];if(this.agent=='iPad'){o=[97,91];};window.setTimeout(function(){self.e(self.nextBttn,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d(-'+o[0]+'px,0,0)'});self.e(self.prevBttn,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d('+o[0]+'px,0,0)'});self.e(self.playBttn,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d('+o[1]+'px,0,0)'});if(self.showBackBttn){self.e(self.backBttn,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d('+o[1]+'px,0,0)'});};if(self.showInfoButton){self.e(self.infoBttn,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d(-'+o[1]+'px,0,0)'});};self.e(self.thumbDrawer.container,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d(0,-'+(self.thumbDrawer.tabHeight-self.device.offset.bottom)+'px,0)'});if(self.gallery){self.e(self.albumDrawer.container,{webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransform:'translate3d(0,'+(self.albumDrawer.tabHeight-self.device.offset.top)+'px,0)'});};},0);this.up();};this.controlsVisible=!this.controlsVisible;},resetControls:function(){var offset=50;if(this.agent=='iPad'){offset=75;};this.e(this.nextBttn,{top:(this.options.height/2)-offset+'px'});this.e(this.prevBttn,{top:(this.options.height/2)-offset+'px'});if(this.gallery&&this.albumDrawer){this.albumDrawer.reset();};this.thumbDrawer.reset();},scroll:function(){if(this.device.apple){window.scrollTo(0,0);}else{window.scrollTo(0,1);};},toggleDisplayMode:function(){this.up();window.clearTimeout(this.playIntId);if(this.playing){if(this.device.apple){this.e(this.playBttnContain,{webkitTransition:'-webkit-transform 500ms ease-in-out',webkitTransform:'rotateY(0deg)'});}else{this.e(this.playBttn,{backgroundImage:this.graphics.playBttn,});};}else{if(this.device.apple){this.e(this.playBttnContain,{webkitTransition:'-webkit-transform 500ms ease-in-out',webkitTransform:'rotateY(180deg)'});}else{this.e(this.playBttn,{backgroundImage:this.graphics.pauseBttn,});};};this.playing=!this.playing;if(this.playing){var self=this;if(this.currentPosition==this.count){this.currentPosition--;var me=this.assets[this.album][0];var replaceTgt=this.currentPosition-1;this.mainPosition(me,this.currentPosition);this.unloadImage(this.assets[this.album][replaceTgt]);this.pushContainer.appendChild(me.container);window.setTimeout(function(){self.transition(600,1);self.toggleControls();},500);}else{window.setTimeout(function(){self.currentPosition++;self.transition();self.toggleControls();},500);};};},draw:function(){this.cover=document.getElementById('cover');this.e(this.cover,{width:this.options.width+'px',height:this.options.height+'px'});this.spinner(this.cover);this.video=document.getElementById('video');var parts=/^(album|gallery)=(.*)&?/.exec(location.search.substring(1));var contentType=parts[1];this.contentId=parts[2];if(navigator.standalone){this.showBackBttn=false;}else{parts=/back=(0|1)/.exec(location.search.substring(1));if(parts){this.showBackBttn=Boolean(Number(parts[1]));}else{this.showBackBttn=false;}}
parts=/info=(0|1)/.exec(location.search.substring(1));if(parts){this.showInfoButton=Boolean(Number(parts[1]));}else{this.showInfoButton=false;}
parts=/sharpening=(0|1)/.exec(location.search.substring(1));if(parts){this.sharpening=Boolean(Number(parts[1]));}else{this.sharpening=false;}
if(!isNaN(this.contentId)){alert('Content not found');return;};if(contentType=='album'){this.gallery=false;};var self=this;if(this.webview||!this.device.apple){window.setInterval(function(){if(self.options.width!=window.innerWidth){self.options.width=window.innerWidth;self.portrait=!self.portrait;self.redraw();}},100);}else{window.addEventListener('orientationchange',function(){self.portrait=!self.portrait;self.redraw();},true);};var tmp=document.createDocumentFragment();this.pushContainer=this.e('div',{height:'100%',position:'absolute',width:this.options.width*this.loadN+'px',top:'0px',left:'0px',zIndex:1,webkitTransformStyle:'preserve-3d'},'ssp-push-parent');tmp.appendChild(this.pushContainer);this.touchContain=this.e('div',{height:this.options.height+'px',width:'100%',position:'absolute',top:'0px',left:'0px',zIndex:11000});this.swipeTarget=this.e('div',{height:'100%',width:'100%',position:'absolute',top:'0px',left:'0px',zIndex:11001});this.nextBttn=this.e('div',{width:'100px',height:'100px',right:'-74px',position:'absolute',zIndex:11002,webkitTransform:'translate3d(2000px,0,0)',webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransformStyle:'preserve-3d'});if(this.agent=='iPad'){this.e(this.nextBttn,{width:'130px',height:'130px',right:'-97px'});};this.nextBttnBg=this.e('div',{width:'100%',height:'100%',backgroundImage:this.graphics.nextBttn,webkitBackgroundSize:'46% 46%',backgroundPosition:'center center',backgroundRepeat:'no-repeat'});this.nextBttn.appendChild(this.nextBttnBg);this.prevBttn=this.e('div',{width:'100px',height:'100px',left:'-73px',position:'absolute',opacity:0.6,zIndex:11003,webkitTransition:'-webkit-transform 400ms ease-in-out',webkitTransformStyle:'preserve-3d'});if(this.agent=='iPad'){this.e(this.prevBttn,{width:'130px',height:'130px',left:'-97px'});};this.prevBttnBg=this.e('div',{width:'100%',height:'100%',backgroundImage:this.graphics.prevBttn,webkitBackgroundSize:'37% 37%',backgroundPosition:'center center',backgroundRepeat:'no-repeat'});this.prevBttn.appendChild(this.prevBttnBg);if(this.showBackBttn){this.backBttn=this.e('div',{width:'100px',height:'100px',left:'-70px',bottom:'0px',position:'absolute',zIndex:14001,webkitTransition:'-webkit-transform 400ms ease-in-out',webkitPerspective:200});if(this.agent=='iPad'){this.e(this.backBttn,{width:'130px',height:'130px',left:'-91px'});};this.backBttnBg=this.e('div',{width:'100%',height:'100%',backgroundImage:this.graphics.backBttn,webkitBackgroundSize:'32%',backgroundPosition:'center 70%',backgroundRepeat:'no-repeat'});this.backBttn.appendChild(this.backBttnBg);};this.playBttn=this.e('div',{width:'100px',height:'100px',left:'-70px',top:'0px',position:'absolute',zIndex:14000,webkitTransition:'-webkit-transform 400ms ease-in-out',webkitPerspective:200});if(this.device.apple){if(this.agent=='iPad'){this.e(this.playBttn,{width:'130px',height:'130px',left:'-91px'});};this.playBttnContain=this.e('div',{position:'absolute',width:'100%',height:'100%',webkitTransformStyle:'preserve-3d'});var playBttnFront=this.e('div',{position:'absolute',width:'100%',height:'100%',backgroundImage:this.graphics.playBttn,backgroundPosition:'center 30%',backgroundRepeat:'no-repeat',webkitBackgroundSize:'32%',webkitBackfaceVisibility:'hidden'});var playBttnBack=this.e('div',{position:'absolute',width:'100%',height:'100%',backgroundImage:this.graphics.pauseBttn,backgroundPosition:'center 30%',webkitBackgroundSize:'32%',backgroundRepeat:'no-repeat',webkitBackfaceVisibility:'hidden',webkitTransform:'rotateY(180deg)'});this.playBttnContain.appendChild(playBttnFront);this.playBttnContain.appendChild(playBttnBack);this.playBttn.appendChild(this.playBttnContain);}else{this.e(this.playBttn,{backgroundImage:this.graphics.playBttn,backgroundPosition:'center 30%',backgroundRepeat:'no-repeat',webkitBackgroundSize:'32%'});};if(this.showInfoButton){this.infoBttn=this.e('div',{width:'100px',height:'100px',right:'-70px',top:'0px',position:'absolute',zIndex:15000,webkitTransform:'translate3d(2000px,0,0)',webkitTransition:'-webkit-transform 400ms ease-in-out',webkitPerspective:200});if(this.device.apple){if(this.agent=='iPad'){this.e(this.infoBttn,{width:'130px',height:'130px',right:'-91px'});};this.infoBttnContain=this.e('div',{position:'absolute',width:'100%',height:'100%',webkitTransformStyle:'preserve-3d'});var infoBttnFront=this.e('div',{position:'absolute',width:'100%',height:'100%',backgroundImage:this.graphics.infoBttn,backgroundPosition:'center 30%',webkitBackgroundSize:'32%',backgroundRepeat:'no-repeat',webkitBackfaceVisibility:'hidden'});var infoBttnBack=this.e('div',{position:'absolute',width:'100%',height:'100%',backgroundImage:this.graphics.closeBttn,backgroundPosition:'center 30%',webkitBackgroundSize:'32%',backgroundRepeat:'no-repeat',webkitTransform:'rotateY(180deg)',webkitBackfaceVisibility:'hidden'});this.infoBttnContain.appendChild(infoBttnFront);this.infoBttnContain.appendChild(infoBttnBack);this.infoBttn.appendChild(this.infoBttnContain);}else{this.e(this.infoBttn,{backgroundImage:this.graphics.infoBttn,backgroundPosition:'center 30%',backgroundRepeat:'no-repeat',webkitBackgroundSize:'32%'});};}
this.prevBttn.ontouchstart=function(e){e.preventDefault();self.up();if(self.currentPosition>1){self.currentPosition--;self.transition();};};this.nextBttn.ontouchstart=function(e){e.preventDefault();self.up();if(self.currentPosition<self.count){self.currentPosition++;self.transition();};};this.playBttn.ontouchstart=function(e){self.toggleDisplayMode();};if(this.showInfoButton){this.infoBttn.ontouchstart=function(e){self.flip();};this.infoBttn.ontouchmove=this.dead;};if(this.showBackBttn){this.backBttn.ontouchstart=function(e){history.go(-1);};this.backBttn.ontouchmove=this.dead;};this.prevBttn.ontouchmove=this.dead;this.nextBttn.ontouchmove=this.dead;this.playBttn.ontouchmove=this.dead;this.touchContain.appendChild(this.swipeTarget);this.touchContain.appendChild(this.nextBttn);this.touchContain.appendChild(this.prevBttn);this.touchContain.appendChild(this.playBttn);if(this.showInfoButton){this.touchContain.appendChild(this.infoBttn);}
if(this.showBackBttn){this.touchContain.appendChild(this.backBttn);};tmp.appendChild(this.touchContain);this.thumbDrawer=new Drawer({tab:this.graphics.thumbTab,height:this.device.thumbSize+10,top:false,zIndex:12000});this.resetControls();var touchcoords={start:{x:0,y:0},end:{x:0,y:0},move:false};this.swipeTarget.ontouchstart=function(e){if(e.targetTouches.length==1){e.preventDefault();if(self.flipped&&!self.flipScroll){return;};if(self.flipped){if(!self.inFlipScroll){touchcoords.current=0;touchcoords.max=self.options.height-self.flipScroll.offsetHeight-60;self.inFlipScroll=true;}}else{touchcoords.current=-((self.currentPosition-1)*self.options.width);}
touchcoords.start.x=e.targetTouches[0].pageX;touchcoords.start.y=e.targetTouches[0].pageY;touchcoords.start.time=+new Date;touchcoords.move=false;}};this.swipeTarget.ontouchmove=function(e){if(e.targetTouches.length==1){e.preventDefault();if(self.flipped&&!self.flipScroll){return;};touchcoords.move=true;touchcoords.end.x=e.targetTouches[0].pageX;touchcoords.end.y=e.targetTouches[0].pageY;if(self.flipped){var n=Math.min(touchcoords.current-(touchcoords.start.y-touchcoords.end.y),10);self.e(self.flipScroll,{webkitTransition:'',webkitTransform:'translate3d(0,'+n+'px,0)'});}else{self.e(self.pushContainer,{webkitTransition:'',webkitTransform:'translate3d( '+(touchcoords.current-(touchcoords.start.x-touchcoords.end.x))+'px,0,0)'});}}};this.swipeTarget.ontouchend=function(e){if(self.flipped&&!self.flipScroll){return;};if(self.flipped){touchcoords.current-=touchcoords.start.x-touchcoords.end.x;if(touchcoords.current>0){var n='0';}else if(touchcoords.current<touchcoords.max){var n=touchcoords.max;}else{var diff=touchcoords.start.y-touchcoords.end.y;var down=true;if(diff<0){down=false;};diff=Math.abs(diff);var end=+new Date;var total=end-touchcoords.start.time;var r1=diff/total;var r2=total/diff;var go=r1*(self.options.height*0.9);if(down){touchcoords.current-=go;}else{touchcoords.current+=go;};if(touchcoords.current>0){touchcoords.current=0;}else if(touchcoords.current<touchcoords.max){touchcoords.current=touchcoords.max;};var dur=go*(r2*3);self.e(self.flipScroll,{webkitTransition:'-webkit-transform '+dur+'ms cubic-bezier(0,0,.2,1)',webkitTransform:'translate3d(0,'+touchcoords.current+'px,0)'});};if(n){if(n==0){_n=-9;}else{_n=n+9;};var l=function(){self.e(self.flipScroll,{webkitTransition:'-webkit-transform 100ms ease-out',webkitTransform:'translate3d(0,'+n+'px,0)'});self.flipScroll.removeEventListener('webkitTransitionEnd',l);};self.flipScroll.addEventListener('webkitTransitionEnd',l);self.e(self.flipScroll,{webkitTransition:'-webkit-transform 100ms ease-out',webkitTransform:'translate3d(0,'+_n+'px,0)'});touchcoords.current=n;}}else{if(touchcoords.move){var diff=touchcoords.start.x-touchcoords.end.x;var dir=1;if(diff<0){dir=-1;};diff=Math.abs(diff);var end=+new Date;var total=end-touchcoords.start.time;var rate=total/diff;var remaining=self.options.width-diff;var threshold=false;if(diff>(self.options.width*0.25)||(diff>(self.options.width*0.07)&&rate<1)){threshold=true;};if(threshold&&self.currentPosition+dir>=1&&self.currentPosition+dir<=self.count){self.currentPosition+=dir;self.transition(remaining*rate);}else{var l=function(){self.e(self.pushContainer,{webkitTransition:'-webkit-transform 100ms ease-out',webkitTransform:'translate3d('+touchcoords.current+'px,0,0)'});self.pushContainer.removeEventListener('webkitTransitionEnd',l);};self.pushContainer.addEventListener('webkitTransitionEnd',l);self.e(self.pushContainer,{webkitTransition:'-webkit-transform 100ms',webkitTransform:'translate3d('+(touchcoords.current+(dir*10))+'px,0,0)'});};}else{var current=self.assets[self.album][self.currentPosition-1];if(current.data.is_video=='1'){if(self.videoBttnTarget.min.x<touchcoords.start.x&&touchcoords.start.x<self.videoBttnTarget.max.x&&self.videoBttnTarget.min.y<touchcoords.start.y&&touchcoords.start.y<self.videoBttnTarget.max.y){self.playVideo();return;};};self.scroll();self.toggleControls();};};};this.body.appendChild(tmp);if(!this.device.nativeVideo){this.videoContainer=this.e('div',{backgroundColor:'#000',position:'absolute',top:'0px',left:'0px',zIndex:1000000,opacity:0,webkitTransition:'opacity 500ms'});this.body.appendChild(this.videoContainer);this.videoClose=this.e('div',{position:'absolute',width:'130px',height:'130px',top:'0px',right:'0px',backgroundImage:this.graphics.videoClose,backgroundPosition:'center 30%',backgroundRepeat:'no-repeat',zIndex:1000000,opacity:0.3,webkitBackgroundSize:'30%'});this.videoContainer.addEventListener('webkitTransitionEnd',function(){if(!self.videoPlaying){self.e(self.videoContainer,{width:'0px',height:'0px'});self.videoContainer.innerHTML='';self.videoControlsDuration.innerHTML='';self.e(self.videoControls,{webkitTransform:'translate3d(0,0px,0)'});};});this.videoClose.ontouchstart=function(e){self.exitVideo();};this.videoClose.ontouchmove=this.dead;this.videoClose.ontouchend=this.dead;this.videoControls=this.e('div',{width:'100%',height:'40px',background:'-webkit-gradient(linear, left top, left bottom, from(#2d2f32), to(#030304))',position:'absolute',bottom:'-40px',webkitTransition:'-webkit-transform 500ms'});this.videoControlsPlayBttn=this.e('div',{position:'absolute',width:'80px',height:'40px',top:'0px',left:'0px'});this.videoControls.appendChild(this.videoControlsPlayBttn);this.videoControlsDuration=this.videoControlsPlayBttn.cloneNode(false);this.e(this.videoControlsPlayBttn,{backgroundImage:this.graphics.videoControlsPlay,backgroundRepeat:'no-repeat',backgroundPosition:'center center'});this.videoControlsPlayBttn.ontouchstart=function(e){if(self.videoPlaying){self.currentVideo.pause();self.e(self.videoControlsPlayBttn,{backgroundImage:self.graphics.videoControlsPlay});}else{self.currentVideo.play();self.e(self.videoControlsPlayBttn,{backgroundImage:self.graphics.videoControlsPause});};self.videoPlaying=!self.videoPlaying;};this.videoControlsPlayBttn.ontouchmove=this.dead;this.videoControlsPlayBttn.ontouchend=this.dead;this.e(this.videoControlsDuration,{left:'',right:'0px',width:'120px',paddingTop:'14px',fontSize:'12px',textAlign:'center',color:'#c9cbcd',fontFamily:'Helvetica Neue'});this.videoControlsScrubber=this.e('div',{position:'absolute',width:(this.options.width-200)+'px',height:'40px',top:'0px',left:'80px'});this.videoControlsTrack=this.e('div',{position:'absolute',width:'100%',height:'6px',top:'16px',left:'0px',backgroundColor:'#151517',borderTop:'1px solid #000',borderBottom:'1px solid #323436'});this.videoControlsBuffer=this.e('div',{position:'absolute',width:'0%',height:'100%',top:'0px',left:'0px',background:'-webkit-gradient(linear, left top, left bottom, from(#111213), to(#030304))'});this.videoControlsElapsed=this.videoControlsBuffer.cloneNode(false);this.e(this.videoControlsElapsed,{width:'0%',background:'-webkit-gradient(linear, left top, left bottom, from(#5e5f60), to(#69696a))'});this.videoControlsHandle=this.e('div',{position:'absolute',top:'12px',width:'20px',height:'14px',left:'70px',webkitBoxShadow:'#000 0 2px 1px',webkitBorderRadius:'2px',background:'-webkit-gradient(linear, left top, left bottom, from(#c0c2c4), to(#d5d7da))',borderTop:'1px solid #e4e4e5',borderBottom:'1px solid #edeeef'});this.videoControlsHandle.ontouchmove=function(e){self.videoSeeking=true;self.currentVideo.pause();var l=e.targetTouches[0].pageX-10;var p=((l-70)/(self.options.width-200))*100;if(p<0){p=0;l=70;}else if(p>100){p=100;l=70+(self.options.width-200);};self.e(self.videoControlsHandle,{left:l+'px'});self.e(self.videoControlsElapsed,{width:p+'%'});var t=self.currentVideo.duration*(p/100);self.videoControlsDuration.innerHTML=self.videoString(t)+' / '+self.videoString(self.currentVideo.duration);};this.videoControlsHandle.ontouchend=function(e){self.videoSeeking=false;var l=(parseInt(self.videoControlsHandle.style.left,10)-70)/(self.options.width-200);var seekTo=self.currentVideo.duration*l;self.currentVideo.play();self.currentVideo.pause();self.currentVideo.currentTime=seekTo;self.currentVideo.play();self.e(self.videoControlsPlayBttn,{backgroundImage:self.graphics.videoControlsPause});self.videoPlaying=true;};this.videoControlsScrubber.appendChild(this.videoControlsTrack);this.videoControlsTrack.appendChild(this.videoControlsBuffer);this.videoControlsTrack.appendChild(this.videoControlsElapsed);this.videoControls.appendChild(this.videoControlsPlayBttn);this.videoControls.appendChild(this.videoControlsDuration);this.videoControls.appendChild(this.videoControlsScrubber);this.videoControls.appendChild(this.videoControlsHandle);};this.body.ontouchstart=this.dead;this.body.ontouchmove=this.dead;this.body.ontouchend=this.dead;this.spin=this.spinner(this.touchContain,true);this.spinOn=true;this.toggleSpin();if(this.gallery){this.loadData();}else{this.loadData(this.contentId);}
this.up();window.setInterval(function(){self.monitorControls();},100);},loadData:function(album){album=album||false;DirectorJS.Format.clear();if(album){DirectorJS.Format.add({name:'main',width:this.device.max,height:this.device.max,quality:90});var w=this.device.thumbSize;if(this.device.four){w*=2;};DirectorJS.Format.add({name:'thumb',width:w,height:w,quality:85,square:1});}else{var w=this.device.albumSize[0];var h=this.device.albumSize[1];if(this.device.four){w*=2;h*=2;};DirectorJS.Format.preview({width:w,height:h,quality:85,square:1});};if(!this.gallery||(this.gallery&&!album)){DirectorJS.Format.user({name:'icon',width:114,height:114,quality:85,square:1});};var self=this;if(this.gallery&&!album){DirectorJS.Gallery.get(this.contentId,function(data){document.title=data.name;self.setAvatar(data);if(data.albums.length==1){self.gallery=false;}else{self.loadAlbums(data.albums);};self.loadAlbum(data.albums[0]);},{include_metadata:false,with_content:false});}else{var cId=this.contentId;if(album){cId=album;};DirectorJS.Album.get(cId,function(data){self.contentCache[data.id]=data.contents;if(!self.gallery){document.title=data.name;self.setAvatar(data);};self.loadAlbum(data);},{include_metadata:false});};},setAvatar:function(data){if(data.public.photos){if(data.public.photos.icon){var url=data.public.photos.icon.url;}else{var url=data.public.photos.url;}}else{var url='../app/webroot/img/default_avatar.jpg';};var link=document.createElement('link');link.rel='apple-touch-icon';link.href=url;document.getElementsByTagName('head')[0].appendChild(link);},load:function(){this.body=document.getElementsByTagName('body')[0];var agent=navigator.userAgent;if(agent.indexOf('iPad')!==-1){this.agent='iPad';}else if(agent.indexOf('iPhone')!==-1){this.agent='iPhone';}else{this.agent='Android';this.e(this.body,{background:'#181818'});};this.device=this.devices[this.agent];if(this.device.apple&&agent.indexOf('Safari')===-1){this.webview=true;this.portrait=true;if(this.options.width>this.options.height){this.portrait=false;}}else{this.webview=false;this.portrait=true;if(Math.abs(window.orientation)==90){this.portrait=false;};}
this.device.max=window.screen.height;if(this.agent=='iPhone'){var d=this.e('div',{},'deviceTest');this.body.appendChild(d);var w=window.getComputedStyle(d,null).getPropertyValue("width");if(w=='2px'){this.device.four=true;this.device.max*=2;};this.body.removeChild(d);};if(!this.device.apple){window.onscroll=function(){if(document.body.scrollTop>1||document.body.scrollLeft>0){M.scroll();};};};var self=this;window.setTimeout(function(){self.setScreen(self.draw);},this.device.delay);},up:function(){this.lastInput=+new Date;},getSizeInfo:function(_img){if(!_img.main){return['100% 55%',this.options.width,this.options.height*.55];};var dims=this.device[this.portrait?'portrait':'landscape'];var toAspect=dims[0]/dims[1];var fromAspect=_img.main.width/_img.main.height;var w,h;var bgSize='auto 100%';if(fromAspect>=toAspect){w=dims[0];h=(dims[0]*_img.main.height)/_img.main.width;bgSize='100% auto';}else{w=(dims[1]*_img.main.width)/_img.main.height;h=dims[1];};return[bgSize,w,h];},loadAlbum:function(a){if(this.gallery){this.highlightCurrentAlbum(true);};if(this.contentCache[a.id]){var assets=this.contentCache[a.id];}else{this.loadData(a.id);return;};if(assets.length==1){this.e(this.prevBttn,{display:'none'});this.e(this.nextBttn,{display:'none'});this.e(this.playBttn,{display:'none'});this.e(this.thumbDrawer.container,{display:'none'});}else{this.e(this.prevBttn,{display:'block'});this.e(this.nextBttn,{display:'block'});this.e(this.playBttn,{display:'block'});this.e(this.thumbDrawer.container,{display:'block'});};this.album=a.id;if(this.playing){this.toggleDisplayMode();};if(this.gallery){this.highlightCurrentAlbum();};this.currentAlbum=this.album;this.count=assets.length;this.loadPosition=0;this.thumbLoadPosition=0;this.currentPosition=1;this.e(this.prevBttn,{webkitTransition:'opacity 400ms',opacity:0.6});this.e(this.prevBttnBg,{webkitBackgroundSize:'37% 37%'});if(assets.length==1){this.e(this.nextBttn,{webkitTransition:'opacity 400ms',opacity:0.6});this.e(this.nextBttnBg,{webkitBackgroundSize:'37% 37%'});}else{this.e(this.nextBttn,{webkitTransition:'opacity 400ms',opacity:1});this.e(this.nextBttnBg,{webkitBackgroundSize:'46% 46%'});};this.e(this.pushContainer,{webkitTransition:'',webkitTransform:'translate3d(0px,0,0)'});if(!this.assets[this.album]){this.assets[this.album]=[];var self=this;for(var i=0;i<this.count;i++){var _img=assets[i];if(_img.main&&_img.main.watermarked_url){_img.main.url=_img.main.watermarked_url;};var sizeInfo=this.getSizeInfo(_img);var bgSize=sizeInfo[0];var css={width:this.options.width+'px',height:this.options.height+'px',position:'absolute',left:(i*this.options.width)+'px',overflow:'hidden'};var contain=this.e('div',css,'ssp-image-container');var innerContain=this.e('div',{width:'100%',height:'100%',position:'relative',webkitTransformStyle:'preserve-3d'});var front=innerContain.cloneNode(false);this.e(front,{position:'absolute',left:'0px',top:'0px',width:'100%',height:'100%',webkitBackfaceVisibility:'hidden',webkitBackgroundSize:bgSize,backgroundRepeat:'no-repeat',backgroundPosition:'center center'});var back=front.cloneNode(false);var css={};var backBgCss={width:'100%',height:'100%'};if(this.device.apple){css.webkitTransform='rotateY(180deg)';backBgCss.webkitTransform='scaleX(-1)';backBgCss.backgroundRepeat='no-repeat';backBgCss.backgroundPosition='center center';backBgCss.opacity=0.1;}else{backBgCss.backgroundColor='rgba(0, 0, 0, 0.7)';css.display='none';}
this.e(back,css);var backBg=this.e('div',backBgCss);var backContent=this.e('div',{position:'absolute',marginRight:'20px',overflow:'hidden'},'back');backContent.innerHTML='<h2>'+(i+1)+' / '+this.count+'</h2>'+'<h1>'+(_img.title!=''?_img.title:_img.src)+'</h1><p>'+_img.caption.toString().replace(/\n/g,'<br>')+'</p>';var play,video;if(_img.is_video=='1'){play=this.e('div',{width:'100%',height:'100%',backgroundImage:this.graphics.playBttn,webkitBackgroundSize:'85px',backgroundPosition:'center center',backgroundRepeat:'no-repeat'});if(this.agent=='iPad'){this.e(play,{webkitBackgroundSize:'110px'});};front.appendChild(play);video=this.e('video',{});if(this.device.nativeVideo){this.e(video,{position:'absolute',top:'-1000px'});};video.ontouchstart=this.dead;video.ontouchmove=this.dead;video.ontouchend=this.dead;video.src=_img.original.url;if(this.device.nativeVideo){var ev='ended';if(this.device.apple){ev='pause';}
video.addEventListener(ev,function(){self.exitVideo();});this.body.appendChild(video);}}else{play=false;video=false;};back.appendChild(backBg);back.appendChild(backContent);innerContain.appendChild(front);innerContain.appendChild(back);contain.appendChild(innerContain);var tnContain=this.e('div',{position:'absolute',top:'5px',left:(i*(this.device.thumbSize+5))+5+'px',webkitBoxShadow:'#000 0px 1px 1px',width:this.device.thumbSize+'px',height:this.device.thumbSize+'px',overflow:'hidden'});var tnInside=this.e('div',{width:'100%',height:'100%',webkitBackgroundSize:'100%',position:'absolute'});var tnBgImg='none';if(_img.thumb){tnBgImg=_img.thumb.url;};var css={width:this.device.thumbSize-4+'px',height:this.device.thumbSize-4+'px',border:'2px solid #646a70',webkitTransform:'scale(1.2)',position:'absolute'};if(this.agent=='Android'){css.border='2px solid #ffffff';};var tnBg=this.e('div',css);tnBg.pos=i+1;tnBg.react=function(){if(this.pos==self.currentPosition){return;};if(this.pos==self.currentPosition+1||this.pos==self.currentPosition-1){self.currentPosition=this.pos;self.transition();}else{var me=self.assets[self.album][this.pos-1];if(this.pos>self.currentPosition){self.currentPosition++;}else{self.currentPosition--;};var replaceTgt=self.currentPosition-1;self.mainPosition(me,self.currentPosition);self.unloadImage(self.assets[self.album][replaceTgt]);self.pushContainer.appendChild(me.container);self.transition(null,this.pos);};};tnContain.appendChild(tnInside);tnContain.appendChild(tnBg);var w=500,h=500;if(_img.main){w=_img.main.width;h=_img.main.height;};var obj={data:assets[i],container:contain,innerContain:innerContain,tnContainer:tnContain,tnBg:tnBg,tnBgImg:tnBgImg,tnInside:tnInside,front:front,back:back,backBg:backBg,backContent:backContent,width:w,height:h,loaded:false,videoPlay:play,video:video,portrait:this.portrait};this.assets[this.album].push(obj);};};this.tnPos=0;this.resetMain(true);this.resetThumbs();this.highlightCurrentImage();},toggleCover:function(quick){quick=quick||false;if(quick){this.e(this.cover,{webkitTransition:''});}else{this.e(this.cover,{webkitTransition:'-webkit-transform 500ms'});};if(this.covered){this.e(this.cover,{webkitTransform:'translate3d(0,-'+this.options.height+'px,0)'});}else{this.e(this.cover,{webkitTransform:'translate3d(0,0px,0)'});};this.covered=!this.covered;},redraw2:function(current){var current=this.assets[this.album][this.currentPosition-1];this.resetControls();if(this.gallery){this.albumDrawer.setupSwipe();};this.thumbDrawer.setupSwipe();this.e(this.pushContainer,{width:this.options.width*this.loadN+'px',height:this.options.height+'px',webkitTransformStyle:'preserve-3d',webkitTransition:'',webkitTransform:'translate3d('+-(this.options.width*(this.currentPosition-1))+'px,0,0)'});this.e(this.touchContain,{height:this.options.height+'px'});if(this.currentVideo){if(this.device.nativeVideo){this.e(this.currentVideo,{top:'0px',left:'0px',width:this.options.width+'px',height:this.options.height+'px'});}else{this.e(this.videoContainer,{width:this.options.width+'px',height:this.options.height+'px'});};};if(this.videoContainer){this.e(this.videoControlsScrubber,{width:(this.options.width-200)+'px'});};this.resetMain();if(this.flipped){this.flipPosition(current);};var self=this;window.setTimeout(function(){self.scroll();},50);this.e(this.cover,{webkitTransition:'',webkitTransform:'translate3d(0,-'+this.options.height+'px,0)',width:this.options.width+'px',height:this.options.height+'px'});},redraw:function(){var current=this.assets[this.album][this.currentPosition-1];for(i in this.onStage){if(this.onStage[i]!=current){this.unloadImage(this.onStage[i]);};};var self=this;window.setTimeout(function(){self.setScreen(self.redraw2);},1)},unloadImage:function(asset){asset.front.style.backgroundImage='none';if(asset.loaded){asset.loaded=false;this.pushContainer.removeChild(asset.container);};},resetThumbs:function(){var tnCss={width:((this.device.thumbSize+5)*this.count)+5+'px',webkitTransform:'translate3d(0px,0,0)'};this.e(this.thumbDrawer.content,tnCss);var assets=this.assets[this.album];var frag=document.createDocumentFragment();for(var i in assets){frag.appendChild(assets[i].tnContainer);};this.thumbDrawer.content.innerHTML='';this.thumbDrawer.content.appendChild(frag);this.thumbDrawer.setupSwipe();this.tnLoaderStart();},mainPosition:function(asset,index){index=index||this.currentPosition-1;var css={left:(index-1)*this.options.width+'px',zIndex:1000-index};var info=this.getSizeInfo(asset.data);var bg=info[0];if(asset.portrait!=this.portrait){css.width=this.options.width+'px';css.height=this.options.height+'px';asset.portrait=this.portrait;this.e(asset.front,{webkitBackgroundSize:bg,});};var append=false;if(asset.loaded){this.mainLoaded();this.hideActivity();}else if(asset.data.main){append=true;var img=new Image();var self=this;img.onload=function(){self.mainLoaded();asset.loaded=true;self.e(asset.front,{backgroundImage:'url('+asset.data.main.url+')'});img.src='';self.hideActivity();delete(img);};img.src=asset.data.main.url;}else{if(!asset.loaded){append=true;this.e(asset.front,{backgroundImage:'-webkit-gradient(linear, left top, left bottom, from(#111), to(#111))'});};asset.loaded=true;this.mainLoaded();this.hideActivity();};this.e(asset.container,css);return append;},hideActivity:function(){if(this.spinOn){this.toggleSpin();};if(this.covered){this.toggleCover();if(this.firstLoad){this.firstLoad=false;var self=this;window.setTimeout(function(){self.toggleControls();},750);}};},tnLoaderStart:function(){this.tnLoaderStop();var self=this;this.tnInterval=window.setInterval(function(){if(self.tnPos==self.count){self.tnLoaderStop();return;}
if(!self.mainLoading){var loadMe=self.assets[self.album][self.tnPos];self.e(loadMe.tnInside,{backgroundImage:'url('+loadMe.tnBgImg+')'});self.tnPos++;};},500);},tnLoaderStop:function(){window.clearInterval(this.tnInterval);},previewLoaderStart:function(){var self=this;this.previewInterval=window.setInterval(function(){if(self.previewsToLoad.length){if(!self.mainLoading){var id=self.previewsToLoad.shift();var a=self.albums[id];if(a.preview){self.e(a.element,{backgroundImage:'url('+a.preview.url+')'});};};}else{window.clearInterval(self.previewInterval);};},500);},mainLoaded:function(){this.mainLoadedCount++;if(this.mainLoadedCount==this.mainLoadedDone){this.mainLoading=false;};},resetMain:function(){var noobs=[];var appendMe=document.createDocumentFragment();var assets=this.assets[this.album];var start=this.currentPosition-1;if(start<=2){start=1;}else if(start==(this.count-1)){start-=1;};var max=start+this.loadN;if(max>(this.count)){max=(this.count+1);};this.mainLoadedCount=0;this.mainLoading=true;this.mainLoadedDone=max-start;for(var i=start;i<max;i++){var c=assets[i-1];var append=this.mainPosition(c,i);if(append){appendMe.appendChild(c.container);};noobs.push(c);};if(appendMe.childNodes.length){for(var i in this.onStage){var leave=false;var c=this.onStage[i];if(c.loaded){for(var j in noobs){if(c==noobs[j]){leave=true;break;};};if(!leave){this.unloadImage(c);};};};this.pushContainer.appendChild(appendMe);this.onStage=noobs;}
var left=-((this.currentPosition-1)*this.options.width);this.e(this.pushContainer,{webkitTransition:'',webkitTransform:'translate3d('+left+'px,0,0)'});},highlightCurrentImage:function(){var css={webkitTransformStyle:'preserve-3d'};if(this.thumbDrawer.visible&&this.device.apple){css.webkitTransition='-webkit-transform 400ms';}else{css.webkitTransition='';};if(this.currentImage){css.webkitTransform='scale(1.2)';this.e(this.currentImage.tnBg,css);};var me=this.assets[this.album][this.currentPosition-1];css.webkitTransform='scale(1)';this.e(me.tnBg,css);this.currentImage=me;},highlightCurrentAlbum:function(undo){if(!this.album){return;};undo=undo||false;var c;if(this.agent=='Android'){c='#333333';if(undo){c='#555555';};}else{c='#646a70';if(undo){c='#1c1e1f';};};var a=document.getElementById(this.album);this.e(a,{backgroundColor:c})},flipPosition:function(me){var size=this.getSizeInfo(me.data);if(this.device.apple){var bg;if(me.data.main){bg='url('+me.data.main.url+')';}else{bg='-webkit-gradient(linear, left top, left bottom, from(#000), to(#000))'};this.e(me.backBg,{backgroundImage:bg,webkitBackgroundSize:size[0]});};var niceTop=((this.options.height)/2)-((size[2])/2)+40;this.e(me.backContent,{left:((this.options.width)/2)-((size[1])/2)+20+'px',width:size[1]-40+'px'});var topLimit=this.options.height-40;var h=me.backContent.offsetHeight
var top=topLimit-h;top=(top/2)-(h/2);if(top<0){top=40;};top=Math.min(top,niceTop);this.flipScroll=false;this.e(me.backContent,{top:top+'px'});},flip:function(){if(this.playing){window.clearTimeout(this.playIntId);};this.toggleControls(true);this.flipped=!this.flipped;this.toggleControls(true);if(this.flipped){if(this.device.apple){this.e(this.infoBttnContain,{webkitTransition:'-webkit-transform 500ms ease-in-out',webkitTransform:'rotateY(180deg)'});}else{this.e(this.infoBttn,{backgroundImage:this.graphics.closeBttn});};}else{if(this.device.apple){this.e(this.infoBttnContain,{webkitTransition:'-webkit-transform 500ms ease-in-out',webkitTransform:'rotateY(0deg)'});}else{this.e(this.infoBttn,{backgroundImage:this.graphics.infoBttn});};};var me=this.assets[this.album][this.currentPosition-1];this.e(me.container,{webkitPerspective:this.options.width*2});this.flipPosition(me);if(this.device.apple){var self=this;var d='0';if(!this.flipped){var cb=function(){self.e(me.backBg,{backgroundImage:'none'});me.innerContain.removeEventListener('webkitTransitionEnd',cb);if(self.playing){self.playIntId=window.setTimeout(function(){self.currentPosition++;self.transition();self.toggleControls();},1000);};};me.innerContain.addEventListener('webkitTransitionEnd',cb);}else{d='180';};self.e(me.innerContain,{webkitTransition:'-webkit-transform 500ms ease-in-out',webkitTransform:'rotateY('+d+'deg)'});}else{var d='none';if(this.flipped){d='block';};this.e(me.back,{display:d});};},exitVideo:function(){if(this.device.nativeVideo){if(this.device.apple){this.toggleCover(true);this.scroll();}else{this.redraw();};}else{this.currentVideo.pause();this.e(this.videoContainer,{opacity:0});};this.currentVideo=false;this.videoPlaying=false;},playVideo:function(){if(this.playing){this.toggleDisplayMode();};var me=this.assets[this.album][this.currentPosition-1];if(this.device.apple){var mime=me.data.mime_type;var test=document.createElement('video').canPlayType(mime);if(test==''&&mime!=''){alert('This video cannot be played on this device.');return;};};if(this.device.nativeVideo){if(this.device.apple){this.toggleCover();};this.e(me.video,{display:'block',width:this.options.width+'px',height:this.options.height+'px'});me.video.load();me.video.play();this.currentVideo=me.video;}else{var self=this;this.e(this.videoContainer,{width:this.options.width+'px',height:this.options.height+'px',opacity:1});var clone=me.video.cloneNode(true);this.e(clone,{width:'100%',height:'100%'});this.videoContainer.appendChild(clone);this.videoContainer.appendChild(this.videoClose);this.videoContainer.appendChild(this.videoControls);clone.addEventListener('ended',function(){self.exitVideo();});clone.play();this.currentVideo=clone;clone.addEventListener('timeupdate',function(e){self.monitorVideo(e.target.currentTime);});this.videoPlaying=true;this.e(this.videoControlsPlayBttn,{backgroundImage:this.graphics.videoControlsPause});};},videoString:function(t){var m=Math.floor(t/60);var s=Math.floor(t%60);if(s<10){s='0'+s;};return m+':'+s;},monitorVideo:function(t){if(!isNaN(this.currentVideo.duration)){var d=this.currentVideo.duration;if(this.videoControlsDuration.innerHTML==''){this.e(this.videoControls,{webkitTransform:'translate3d(0,-40px,0)'});};this.videoControlsDuration.innerHTML=this.videoString(t)+' / '+this.videoString(d);var bufferedPercent=parseInt(((this.currentVideo.buffered.end(0)/d)*100),10);this.e(this.videoControlsBuffer,{width:bufferedPercent+'%'});var ct=t/d;var left=((this.options.width-200)*ct)+70;this.e(this.videoControlsElapsed,{width:ct*100+'%'});this.e(this.videoControlsHandle,{left:left+'px'});};},loadAlbums:function(albums){this.albumDrawer=new Drawer({tab:this.graphics.albumTab,height:this.device.albumSize[1]+40,top:true,zIndex:13000});this.resetControls();var w=this.device.albumSize[0];this.albums={};this.previewsToLoad=[];this.e(this.albumDrawer.content,{width:(albums.length*(w+5))+5+'px'});var frag=document.createDocumentFragment();for(var i in albums){var a=albums[i];this.albums[a.id]=a;this.previewsToLoad.push(a.id);var l=(i*(w+5))+5;var css={position:'absolute',top:'5px',left:l+'px',webkitBoxShadow:'#000 0px 1px 1px',backgroundColor:'#1c1e1f',backgroundRepeat:'no-repeat',webkitBackgroundSize:'100% '+this.device.albumSize[1]+'px',width:(w-10)+'px',height:'22px',fontSize:'10px',padding:(this.device.albumSize[1]+3)+'px 5px 6px',textAlign:'left',color:'#fff',fontFamily:'Helvetica Neue',fontWeight:'bold'};if(this.agent=='Android'){css.backgroundColor='#555555';css.color='#ffffff';};var div=this.e('div',css);if(a.name.length>78){a.name=a.name.substring(0,75)+'...'};div.innerHTML=a.name;div.id=a.id;var self=this;div.react=function(){if(self.currentAlbum!=this.id){self.toggleSpin();var _a=self.albums[this.id];self.loadAlbum(_a);window.setTimeout(function(){self.toggleControls();},400);}};this.albums[a.id].left=l;this.albums[a.id].element=div;frag.appendChild(div);};this.albumDrawer.content.appendChild(frag);this.previewLoaderStart();this.albumDrawer.setupSwipe();},toggleSpin:function(){var css;if(this.spinOn){css={top:'-50%'};}else{css={top:'50%'};};this.e(this.spin,css);this.spinOn=!this.spinOn;},transition:function(dur,skip){if(isNaN(skip)){skip=false;};var c=this.pushContainer.style.webkitTransform.match(/(-?\d+)px/)[1];window.clearTimeout(this.playIntId);dur=dur||500;var candidate=this.assets[this.album][this.currentPosition-1];var left=-((this.currentPosition-1)*this.options.width);var self=this;var diff=Math.abs(c-left);var bounce=false;if(skip){this.currentPosition=skip;};if(!candidate.loaded||skip){this.toggleSpin();};var finalCallback=function(){self.resetMain();if(self.playing){if(self.currentPosition==self.count){self.toggleDisplayMode();}else{self.playIntId=window.setTimeout(function(){self.currentPosition++;self.transition();},4000);};};self.pushContainer.removeEventListener('webkitTransitionEnd');if(self.currentPosition==1){self.e(self.prevBttn,{webkitTransition:'opacity 400ms',opacity:0.6});self.e(self.prevBttnBg,{webkitBackgroundSize:'37% 37%'});self.e(self.nextBttn,{webkitTransition:'opacity 400ms',opacity:1});self.e(self.nextBttnBg,{webkitBackgroundSize:'46% 46%'});}else if(self.currentPosition==self.count){self.e(self.nextBttn,{webkitTransition:'opacity 400ms',opacity:0.6});self.e(self.nextBttnBg,{webkitBackgroundSize:'37% 37%'});self.e(self.prevBttn,{webkitTransition:'opacity 400ms',opacity:1});self.e(self.prevBttnBg,{webkitBackgroundSize:'46% 46%'});}else{self.e(self.nextBttn,{webkitTransition:'opacity 400ms',opacity:1});self.e(self.nextBttnBg,{webkitBackgroundSize:'46% 46%'});self.e(self.prevBttn,{webkitTransition:'opacity 400ms',opacity:1});self.e(self.prevBttnBg,{webkitBackgroundSize:'46% 46%'});};};var l=function(){if(bounce){self.pushContainer.addEventListener('webkitTransitionEnd',finalCallback);self.e(self.pushContainer,{webkitTransition:'-webkit-transform '+Math.round(dur*0.3)+'ms',webkitTransform:'translate3d('+left+'px,0,0)'});}else{finalCallback.call(this);};self.pushContainer.removeEventListener('webkitTransitionEnd',l);};this.pushContainer.addEventListener('webkitTransitionEnd',l);var left2,dur2;if(bounce){dur2=Math.round(dur*0.7);left2=left;if(c>left2){left2-=5;}else{left2+=5;};}else{dur2=dur;left2=left;};self.e(self.pushContainer,{webkitTransition:'-webkit-transform '+Math.round(dur2)+'ms',webkitTransform:'translate3d('+left2+'px,0,0)'});self.highlightCurrentImage();}};var Drawer=function(opts){this.opts=opts;this.visible=false;this.lastSwipe=+new Date;this.tabHeight=60;this.tabWidth=100;if(M.agent=='iPad'){this.tabHeight=72;this.tabWidth=120;};this.totalHeight=this.tabHeight+this.opts.height;this.draw();};Drawer.prototype.draw=function(){var css={width:'100%',height:this.totalHeight+'px',position:'absolute',left:'0px',zIndex:this.opts.zIndex,background:'transparent',webkitTransformStyle:'preserve-3d'};if(!this.opts.top){css.webkitTransform='translate3d(0,2000px,0)';};css.webkitTransition='-webkit-transform 400ms ease-in-out';this.container=M.e('div',css);this.container.ontouchstart=M.dead;this.container.ontouchmove=M.dead;this.container.ontouchend=M.dead;var css={width:this.tabWidth+'px',height:this.tabHeight+'px',backgroundImage:this.opts.tab,backgroundRepeat:'no-repeat',position:'absolute',left:(M.options.width/2)-(this.tabWidth/2)+'px',zIndex:this.opts.zIndex+1};if(M.agent=='iPad'){css.webkitBackgroundSize='100% auto';};if(this.opts.top){css.top=this.opts.height+'px';css.backgroundPosition='top center';}else{css.top='0px';css.backgroundPosition='bottom center';};this.tab=M.e('div',css);var css={width:'100%',height:this.opts.height+'px',position:'absolute',left:'0px'};if(M.agent=='Android'){css.background='-webkit-gradient(linear, left top, left bottom, from(#cccccc), to(#f8f8f8))';}else{css.background='-webkit-gradient(linear, left top, left bottom, from(#030304), to(#42464a))';};if(this.opts.top){css.top='0px';css.borderBottom='1px solid #585b5e';}else{css.bottom='0px';css.borderTop='1px solid #585b5e';};this.bg=M.e('div',css);this.bg.ontouchstart=M.dead;this.bg.ontouchmove=M.dead;this.bg.ontouchend=M.dead;var css={height:this.opts.height+'px',position:'absolute',left:'0px',webkitTransformStyle:'preserve-3d'};if(this.opts.top){css.top='0px';}else{css.bottom='0px';};this.content=M.e('div',css);this.container.appendChild(this.bg);this.container.appendChild(this.content);this.container.appendChild(this.tab);M.touchContain.appendChild(this.container);var tabcoords={start:{x:0,y:0},end:{x:0,y:0},move:false,n:0};var self=this;this.tab.ontouchstart=function(e){if(self.opts.top){M.e(M.playBttn,{zIndex:0});if(M.showInfoButton){M.e(M.infoBttn,{zIndex:0});};}else if(M.showBackBttn){M.e(M.backBttn,{zIndex:0});}
tabcoords.move=false;tabcoords.start.x=e.targetTouches[0].pageX;tabcoords.start.y=e.targetTouches[0].pageY;tabcoords.start.time=+new Date;if(self.opts.top){tabcoords.closed=self.tabHeight-M.device.offset.top;tabcoords.open=self.totalHeight;}else{tabcoords.closed=-(self.tabHeight-M.device.offset.bottom);tabcoords.open=-self.totalHeight;};M.e(self.container,{webkitTransition:''});};this.tab.ontouchmove=function(e){e.preventDefault();M.up();tabcoords.move=true;tabcoords.end.x=e.targetTouches[0].pageX;tabcoords.end.y=e.targetTouches[0].pageY;var base=tabcoords.closed;if(self.visible){base=tabcoords.open;};var diff=tabcoords.start.y-tabcoords.end.y;tabcoords.n=Math.abs(diff);if(self.opts.top){diff=base-diff;}else{base=-base;diff=base+diff;};if(diff>self.totalHeight){diff=self.totalHeight;}else if(diff<(self.tabHeight-1)){diff=self.tabHeight-1;};if(!self.opts.top){diff='-'+diff;};M.e(self.container,{webkitTransform:'translate3d(0,'+diff+'px,0)'});};this.tab.ontouchend=function(e){e.preventDefault();M.up();var f=0.3;if(self.visible){f=0.3;};var style;if(tabcoords.move){if(tabcoords.n>self.opts.height*f){style=self.visible?tabcoords.closed:tabcoords.open;self.visible=!self.visible;}else{style=self.visible?tabcoords.open:tabcoords.closed;};M.e(self.container,{webkitTransition:'-webkit-transform 200ms ease-in-out'});}else{style=self.visible?tabcoords.closed:tabcoords.open;self.visible=!self.visible;M.e(self.container,{webkitTransition:'-webkit-transform 400ms ease-in-out'});};M.e(self.container,{webkitTransform:'translate3d(0,'+style+'px,0)'});if(!self.visible){window.setTimeout(function(){M.e(M.playBttn,{zIndex:14000});if(M.showBackBttn){M.e(M.backBttn,{zIndex:14001});};if(M.showInfoButton){M.e(M.infoBttn,{zIndex:15000});};},500);};};};Drawer.prototype.reset=function(){var reset;if(this.opts.top){reset=-this.totalHeight;}else{reset=M.options.height;};M.e(this.container,{top:reset+'px'});M.e(this.tab,{left:(M.options.width/2)-(this.tabWidth/2)+'px'});};Drawer.prototype.setupSwipe=function(){var w=parseInt(this.content.style.width,10);if(this.content.style.webkitTransform){var c=this.content.style.webkitTransform.match(/(-?\d+)px/)[1];var max=-(w-M.options.width);if(c<max){this.content.style.webkitTransform='translate3d('+max+'px,0,0)';};};if(w<M.options.width){var dead=function(e){e.preventDefault();};this.content.ontouchstart=dead;this.content.ontouchmove=dead;this.content.ontouchend=function(e){if(e.target&&e.target.react){e.target.react();};M.up();};M.e(this.content,{left:(M.options.width/2)-w/2+'px',webkitTransform:'translate3d(0px,0,0)'});}else{M.e(this.content,{left:'0px'});var coords={start:{x:0,y:0},end:{x:0,y:0},move:false,base:0,blockEnd:false,intId:0};var self=this;var check=function(){return(+new Date-self.lastSwipe)>750;};this.content.ontouchstart=function(e){e.preventDefault();if(check()){coords.move=false;coords.blockEnd=false;coords.start.x=e.targetTouches[0].pageX;coords.start.y=e.targetTouches[0].pageY;coords.start.time=+new Date;coords.max=-(w-M.options.width);};M.e(self.content,{webkitTransition:''})};this.content.ontouchmove=function(e){e.preventDefault();if(check()){window.clearTimeout(coords.intId);M.up();coords.move=true;coords.end.x=e.targetTouches[0].pageX;coords.end.y=e.targetTouches[0].pageY;var n=coords.base-(coords.start.x-coords.end.x);if(n>50){n=50;}else if(n<(coords.max-50)){n=coords.max-50;};M.e(self.content,{webkitTransform:'translate3d('+n+'px,0,0)'});var _self=this;coords.intId=window.setTimeout(function(){if(coords.move){_self.ontouchend();};},100);};};this.content.ontouchend=function(e){if(e){e.preventDefault();}else{coords.blockEnd=true;};if(coords.move&&check()){coords.move=false;self.lastSwipe=+new Date;coords.base-=coords.start.x-coords.end.x;if(coords.base>0){var n='0';}else if(coords.base<coords.max){var n=coords.max;}else{var diff=coords.start.x-coords.end.x;var right=true;if(diff<0){right=false;};diff=Math.abs(diff);var end=+new Date;var total=end-coords.start.time;var r1=diff/total;var r2=total/diff;var go=r1*(M.options.width*0.7);if(right){coords.base-=go;}else{coords.base+=go;};if(coords.base>0){coords.base=0;}else if(coords.base<coords.max){coords.base=coords.max;};var dur=go*(r2*3);M.e(self.content,{webkitTransition:'-webkit-transform '+dur+'ms cubic-bezier(0,0,.2,1)',webkitTransform:'translate3d('+coords.base+'px,0,0)'});};if(n){if(n==0){_n=-9;}else{_n=n+9;};var l=function(){M.e(self.content,{webkitTransition:'-webkit-transform 100ms ease-out',webkitTransform:'translate3d('+n+'px,0,0)'});self.content.removeEventListener('webkitTransitionEnd',l);};self.content.addEventListener('webkitTransitionEnd',l);M.e(self.content,{webkitTransition:'-webkit-transform 100ms ease-out',webkitTransform:'translate3d('+_n+'px,0,0)'});coords.base=n;}}else if(!coords.blockEnd){M.up();if(e&&e.target&&e.target.react){e.target.react();};};};};};DirectorJS={req:[],userScope:{},formats:{},userFormats:{},selfHosted:true,previewFormat:null,initReq:function(salt){var key=salt+Math.floor(Math.random()*1000);this.req[key]=new Object;this.req[key].params=[];return this.req[key];},conn:function(req){if(req){var handler=req.apiMethod+Math.floor(Math.random()*10000);req.params.push('callback='+handler);for(var i in this.formats){var f=this.formats[i];req.params.push('size['+i+']='+f);};for(var i in this.userFormats){var f=this.userFormats[i];req.params.push('user_size['+i+']='+f);};if(this.previewFormat){req.params.push('preview='+this.previewFormat);};req.params=req.params.join('&');var qs='?'+req.params;var host=location.href.split('/m/')[0];if(this.selfHosted){host+='/index.php?';};var url=host+'/api/'+req.apiMethod+qs;var head=document.getElementsByTagName('head')[0];window[handler]=function(response){req.callback.apply(this,[response.data]);window[handler]=null;head.removeChild(script);};var script=document.createElement('script');script.src=url;script.charset='utf-8';head.appendChild(script);};},Format:{clear:function(){DirectorJS.formats={};DirectorJS.userFormats={};DirectorJS.previewFormat=null;},add:function(options){var defaults={square:0,quality:85,sharpening:M.sharpening?1:0};for(var i in options){defaults[i]=options[i];};DirectorJS.formats[options.name]=[defaults.name,defaults.width,defaults.height,defaults.square,defaults.quality,defaults.sharpening].join(',');},user:function(options){var defaults={square:0,quality:85,sharpening:M.sharpening?1:0};for(var i in options){defaults[i]=options[i];};DirectorJS.userFormats[options.name]=[defaults.name,defaults.width,defaults.height,defaults.square,defaults.quality,defaults.sharpening].join(',');},preview:function(options){var defaults={square:0,quality:85,sharpening:M.sharpening?1:0};for(var i in options){defaults[i]=options[i];};DirectorJS.previewFormat=[defaults.width,defaults.height,defaults.square,defaults.quality,defaults.sharpening].join(',');}},Album:{get:function(id,callback,options){var req=DirectorJS.initReq('album.get.');var defaults={only_active:1};DirectorJS.prepAndSendObjs(defaults,options,req);req.apiMethod='get_album';req.callback=callback;req.params.push("album_id="+id);DirectorJS.conn(req);}},Gallery:{get:function(id,callback,options){var req=DirectorJS.initReq('gallery.get.');var defaults={limit:null,order:'display',with_content:true};DirectorJS.prepAndSendObjs(defaults,options,req);req.apiMethod='get_gallery';req.callback=callback;req.params.push("gallery_id="+id);DirectorJS.conn(req);},},prepAndSendObjs:function(obj1,obj2,req){if(typeof obj2=='object'){if(typeof obj2.tags=='object'){var tmp={};var tags=obj2.tags[0];var all;if(obj2.tags[1]=='all'){all=1;}else{all=0;};obj2.tags=tags;obj2.tags_exclusive=all;};if(typeof obj2.scope=='object'){var tmp={};var scope=obj2.scope[0];var scope_id=obj2.scope[1];obj2.scope=scope;obj2.scope_id=scope_id;};for(var i in obj2){obj1[i]=obj2[i];};};for(var i in obj1){if(i=='sort_on'&&obj1[i]=='random'){req.params.push('buster='+String(Math.round(Math.random()*10)));};if(String(obj1[i])=='true'||String(obj1[i])=='false'){obj1[i]=Number(obj1[i]);};req.params.push(i+'='+obj1[i]);};}};
