/*!
    photobox v1.9.9
    (c) 2013 Yair Even Or <http://dropthebit.com>

    MIT-style license.
*/

/* MouseWheel plugin
    * ! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)
    * Licensed under the MIT License (LICENSE.txt).
    *
    * Version: 3.1.11
    *
    * Requires: jQuery 1.2.2+
*/

!function(c,s,a){"use strict";var n,r,l,h,u,d,p,f,m,v,g,b,i,w,y,A,C,x,o,T,k,t,L,M,H,D,O,E,z,P,S,F,X,B,I=[],N=-1,R=!("placeholder"in s.createElement("input")),Y=((le=c("<p>")[0]).style.cssText="pointer-events:auto",!le.style.pointerEvents),j=!1,q=c(),W="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",_=te("transformOrigin"),e=te("transition"),U="transitionend webkitTransitionEnd oTransitionEnd otransitionend",Q=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(e){return window.setTimeout(e,1e3/60)},K={},G=new Image,Z=new Image,J={single:!1,beforeShow:null,afterClose:null,loop:!0,thumb:null,thumbs:!0,thumbAttr:"data-src",counter:"(A/B)",title:!0,autoplay:!1,time:3e3,history:!1,hideFlash:!0,zoomable:!0,wheelNextPrev:!0,keys:{close:[27,88,67],prev:[37,80],next:[39,78]}},V=c('<div id="pbOverlay">').append(x=c('<input type="checkbox" id="pbThumbsToggler" checked hidden>'),k=c('<div class="pbLoader"><b></b><b></b><b></b></div>'),A=c('<div id="pbPrevBtn" class="prevNext"><b></b></div>').on("click",ne),C=c('<div id="pbNextBtn" class="prevNext"><b></b></div>').on("click",ne),M=c('<div class="pbWrapper">').append(w=c("<img>"),y=c("<div>")),c('<div id="pbCloseBtn">').on("click",ge)[0],t=c('<div id="pbAutoplayBtn">').append(c('<div class="pbProgress">')),o=c('<div id="pbCaption">').append('<label for="pbThumbsToggler" title="thumbnails on/off"></label>',T=c('<div class="pbCaptionText">').append('<div class="title"></div><div class="counter">'),L=c("<div>").addClass("pbThumbs")));function $(){Y&&V.hide(),c(s).on("touchstart.testMouse",function(){c(s).off("touchstart.testMouse"),j=!0,V.addClass("mobile")}),t.off().on("click",b.toggle),L.off().on("click","a",v.click),R&&V.addClass("msie"),V.off().on("click","img",function(e){e.stopPropagation()}),c(s.body).append(V),g=s.documentElement}function ee(e,t,o){1==t?(w.css({transform:"translateX(25%)",transition:".2s",opacity:0}),setTimeout(function(){i(f)},200)):-1==t&&(w.css({transform:"translateX(-25%)",transition:".2s",opacity:0}),setTimeout(function(){i(m)},200)),1==o?x.prop("checked",!0):-1==o&&x.prop("checked",!1)}function te(e){var t,o=s.createElement("p").style,i=["ms","O","Moz","Webkit"];if(""==o[e])return e;for(e=e.charAt(0).toUpperCase()+e.slice(1),t=i.length;t--;)if(""==o[i[t]+e])return i[t]+e}function oe(e){var t=e.keyCode,e=l.keys;return 0<=c.inArray(t,e.close)&&ge()||0<=c.inArray(t,e.next)&&!l.single&&se(m)||0<=c.inArray(t,e.prev)&&!l.single&&se(f)||!0}function ie(e,t,o){1==o?se(m):-1==o&&se(f)}function ne(){return se("pbPrevBtn"==this.id?f:m),!1}function se(e){if(!l.loop&&(N==I.length-1&&e==m||0==N&&e==f))return;i(e)}function ae(){if(T.off(U).removeClass("change"),l.counter){try{var e=l.counter.replace("A",N+1).replace("B",I.length)}catch(e){l.counter="(A/B)",ae()}o.find(".counter").text(e)}l.title&&o.find(".title").html("<span>"+I[N][1]+"</span>")}c.fn.photobox=function(t,o,i){return this.each(function(){var e=c(this).data("_photobox");return e?("destroy"===t&&e.destroy(),this):("string"!=typeof t&&(t="a"),"prepareDOM"===t?($(),this):(e=c.extend({},J,o||{}),r=new n(e,this,t),c(this).data("_photobox",r),void(r.callback=i)))})},(n=function(e,t,o){this.options=c.extend({},e),this.target=o,this.selector=c(t||s),this.thumbsList=null;o=this.imageLinksFilter(this.selector.find(o));this.imageLinks=o[0],this.images=o[1],this.init()}).prototype={init:function(){var t=this;this.selector.one("mouseenter.photobox",this.target,function(e){t.thumbsList=v.generate.apply(t)}),this.selector.on("click.photobox",this.target,function(e){e.preventDefault(),t.open(this)}),this.observerTimeout=null,R||1!=this.selector[0].nodeType||this.observeDOM(this.selector[0],this.onDOMchanges.bind(this))},onDOMchanges:function(){var i=this;clearTimeout(this.observerTimeout),i.observerTimeout=setTimeout(function(){var e,t=i.imageLinksFilter(i.selector.find(i.target)),o=0;if(i.imageLinks.length!=t[0].length){if(i.imageLinks=t[0],i.images=t[1],r&&i.selector==r.selector)for(I=i.images,h=i.imageLinks,e=I.length;e--;)I[e][0];i.thumbsList=v.generate.apply(i),L.html(i.thumbsList),i.images.length&&u&&i.options.thumbs&&(-1==(o=i.thumbsList.find('a[href="'+u+'"]').eq(0).parent().index())&&(o=0),v.changeActive(o,0))}},50)},open:function(e){var t=c.inArray(e,this.imageLinks);return-1==t||(l=this.options,I=this.images,h=this.imageLinks,(r=this).setup(1),V.on(U,function(){V.off(U).addClass("on"),i(t,!0)}).addClass("show"),R&&V.trigger("MSTransitionEnd")),!1},imageLinksFilter:function(e){var n,s=this,a=[],r={};return[e.filter(function(e){var t,o=c(this),i="";return r.content=o[0].getAttribute("title")||"",s.options.thumb&&(t=o.find(s.options.thumb)[0]),s.options.thumb&&t||(t=o.find("img")[0]),t&&(n=t.getAttribute("data-pb-captionlink"),i=t.getAttribute(s.options.thumbAttr)||t.getAttribute("src"),r.content=t.getAttribute("alt")||t.getAttribute("title")||""),n&&(2==(n=n.split("[")).length?(r.linkText=n[0],r.linkHref=n[1].slice(0,-1)):(r.linkText=n,r.linkHref=n),r.content+=' <a href="'+r.linkHref+'">'+r.linkText+"</a>"),a.push([o[0].href,r.content,i]),!0}),a]},observeDOM:(H=a.MutationObserver||a.WebKitMutationObserver,D=a.addEventListener,function(e,o){var i;H?(i=this,new H(function(e,t){(e[0].addedNodes.length||e[0].removedNodes.length)&&o(i)}).observe(e,{childList:!0,subtree:!0})):D&&(e.addEventListener("DOMNodeInserted",o.bind(i),!1),e.addEventListener("DOMNodeRemoved",o.bind(i),!1))}),setup:function(e){var t,o,i,n=e?"on":"off";l.thumbs&&(j||L[n]("mouseenter.photobox",v.calc)[n]("mousemove.photobox",v.move)),e?(w.css({transition:"0s"}).removeAttr("style"),V.show(),L.html(this.thumbsList).trigger("mouseenter.photobox"),l.thumbs?V.addClass("thumbs"):(x.prop("checked",!1),V.removeClass("thumbs")),this.images.length<2||l.single?V.removeClass("thumbs hasArrows hasCounter hasAutoplay"):(V.addClass("hasArrows hasCounter"),1e3<l.time?(V.addClass("hasAutoplay"),l.autoplay?b.progress.start():b.pause()):V.removeClass("hasAutoplay")),l.hideFlash&&c("iframe, object, embed").css("visibility","hidden")):c(a).off("resize.photobox"),c(s).off("keydown.photobox")[n]({"keydown.photobox":oe}),j&&(V.removeClass("hasArrows"),M[n]("swipe",ee)),l.zoomable&&(V[n]({"mousewheel.photobox":pe}),R||L[n]({"mousewheel.photobox":fe})),!l.single&&l.wheelNextPrev&&V[n]({"mousewheel.photobox":(t=ie,i=!(o=1e3),function(){i||(t.call(),i=!0,setTimeout(function(){i=!1},o))})})},destroy:function(){l=this.options,this.selector.off("click.photobox",this.target).removeData("_photobox"),ge()}},F=S=P=0,b={autoPlayTimer:!(v={generate:function(){for(var e,t,o,i,n=c("<ul>"),s=[],a=this.imageLinks.length,r=!1,l=0;l<a;l++)r=!!c(this.imageLinks[l]).parent().hasClass("bx-clone"),o=this.imageLinks[l],(t=this.images[l][2])&&(e=this.images[l][1],i=o.rel?" class='"+o.rel+"'":"",s.push("<li "+(r?'style="display:none;"':"")+" "+i+'><a href="'+o.href+'"><img src="'+t+'" alt="" title="'+e+'" /></a></li>'));return n.html(s.join("")),n},click:function(e){e.preventDefault(),q.removeClass("active"),q=c(this).parent().addClass("active");e=c(this.parentNode).index();return i(e,0,1)},changeActiveTimeout:X=null,changeActive:function(e,t,o){l.thumbs&&(q.index(),q.removeClass("active"),q=L.find("li").eq(e).addClass("active"),!o&&q[0]&&(clearTimeout(this.changeActiveTimeout),this.changeActiveTimeout=setTimeout(function(){var e=q[0].offsetLeft+q[0].clientWidth/2-g.clientWidth/2;t?L.delay(800):L.stop(),L.animate({scrollLeft:e},500,"swing")},200)))},calc:function(e){return E=L[0],P=E.clientWidth,S=E.scrollWidth,O=.15*P,F=L.offset().left,z=e.pageX-O-F,z=(S-P)*(z/(P-2*O)),L.animate({scrollLeft:z},200),clearTimeout(X),X=setTimeout(function(){X=null},200),this},move:function(e){var t;X||((e=e.pageX-O-F)<0&&(e=0),t=(S-P)*(e/(P-2*O)),Q(function(){E.scrollLeft=t}))}}),play:function(){b.autoPlayTimer=setTimeout(function(){i(m)},l.time),b.progress.start(),t.removeClass("play"),b.setTitle("Click to stop autoplay"),l.autoplay=!0},pause:function(){clearTimeout(b.autoPlayTimer),b.progress.reset(),t.addClass("play"),b.setTitle("Click to resume autoplay"),l.autoplay=!1},progress:{reset:function(){t.find("div").removeAttr("style"),setTimeout(function(){t.removeClass("playing")},200)},start:function(){R||t.find("div").css(e,l.time+"ms"),t.addClass("playing")}},setTitle:function(e){e&&t.prop("title",e+" (every "+l.time/1e3+" seconds)")},toggle:function(e){e.stopPropagation(),b[l.autoplay?"pause":"play"]()}},i=function(e,t,o){var i,n,s;B||(B=setTimeout(function(){B=null},150),(!e||e<0)&&(e=0),l.loop||(C.toggleClass("pbHide",e==I.length-1),A.toggleClass("pbHide",0==e)),"function"==typeof l.beforeShow&&l.beforeShow(h[e]),V.removeClass("error"),0<=N&&V.addClass(N<e?"next":"prev"),d=N,u=I[N=e][0],f=(N||(l.loop?I.length:0))-1,m=(N+1)%I.length||(l.loop?0:-1),ve(),y.empty(),K.onerror=null,w.add(y).data("zoom",1),"video"==(p="video"==h[e].rel?"video":"image")?(y.html((n=I[N][0],s=c("<a>").prop("href",I[N][0])[0].search?"&":"?",n+=s+"vq=hd720&wmode=opaque",c("<iframe>").prop({scrolling:"no",frameborder:0,allowTransparency:!0,src:n}).attr({webkitAllowFullScreen:!0,mozallowfullscreen:!0,allowFullScreen:!0}))).addClass("pbHide"),ue(t)):(i=setTimeout(function(){V.addClass("pbLoading")},50),R&&V.addClass("pbHide"),l.autoplay&&b.progress.reset(),(K=new Image).onload=function(){K.onload=null,0<=f&&(G.src=I[f][0]),0<=m&&(Z.src=I[m][0]),clearTimeout(i),ue(t)},K.onerror=ce,K.src=u),T.on(U,ae).addClass("change"),(t||R)&&ae(),v.changeActive(e,t,o),he.save())};var re,le,he={save:function(){"pushState"in window.history&&decodeURIComponent(window.location.hash.slice(1))!=u&&l.history&&window.history.pushState("photobox",s.title+"-"+I[N][1],window.location.pathname+window.location.search+"#"+encodeURIComponent(u))},load:function(){if(l&&!l.history)return!1;var e=decodeURIComponent(window.location.hash.slice(1));!e&&V.hasClass("show")&&ge(),c('a[href="'+e+'"]').trigger("click.photobox")},clear:function(){l.history&&"pushState"in window.history&&window.history.pushState("photobox",s.title,window.location.pathname+window.location.search)}};function ce(){V.addClass("error"),w[0].src=W,K.onerror=null}function ue(e){var t,o;function i(){clearTimeout(o),t.off(U).css({transition:"none"}),V.removeClass("video"),"video"==p?(w[0].src=W,y.addClass("prepare"),V.addClass("video")):w.prop({src:u,class:"prepare"}),setTimeout(function(){w.add(y).removeAttr("style").removeClass("prepare"),V.removeClass("pbHide next prev"),setTimeout(function(){w.add(y).on(U,de),R&&de()},0)},50)}o=setTimeout(i,2e3),k.fadeOut(300,function(){V.removeClass("pbLoading"),k.removeAttr("style")}),V.addClass("pbHide"),w.add(y).removeAttr("style").removeClass("zoomable"),null==h[d]||e||"video"!=h[d].rel?t=w:(t=y,w.addClass("prepare")),e||R?i():t.on(U,i)}function de(){w.add(y).off(U).addClass("zoomable"),"video"==p?y.removeClass("pbHide"):t&&l.autoplay&&b.play(),r&&"function"==typeof r.callback&&r.callback.apply(h[N])}function pe(e,t,o){if(o)return!1;if("video"==p){var i=y.data("zoom")||1;if((i+=t/10)<.5)return!1;y.data("zoom",i).css({width:624*i,height:351*i})}else{i=w.data("zoom")||1,o=w[0].getBoundingClientRect();(i+=t/10)<.1&&(i=.1),Q(function(){w.data("zoom",i).css({transform:"scale("+i+")"})}),o.height>g.clientHeight||o.width>g.clientWidth?c(s).on("mousemove.photobox",me):(c(s).off("mousemove.photobox"),w[0].style[_]="50% 50%")}return!1}function fe(e,t){e.preventDefault(),e.stopPropagation();e=r.thumbsList;e.css("height",e[0].clientHeight+10*t),t=o[0].clientHeight/2,M[0].style.cssText="margin-top: -"+t+"px; padding: "+t+"px 0;",L.hide().show(0)}function me(e){var t=(e.clientY/g.clientHeight*(g.clientHeight+200)-100)/g.clientHeight*100,o=(e.clientX/g.clientWidth*100).toFixed(2)+"% "+t.toFixed(2)+"%";Q(function(){w[0].style[_]=o})}function ve(){clearTimeout(b.autoPlayTimer),c(s).off("mousemove.photobox"),K.onload=function(){},K.src=G.src=Z.src=u}function ge(){if(!V.hasClass("show"))return!1;function e(){""!=V[0].className&&(V.removeClass("show pbHide error pbLoading"),w.removeAttr("class").removeAttr("style").off().data("zoom",1),w[0].src=W,o.find(".title").empty(),Y&&setTimeout(function(){V.hide()},200),l.hideFlash&&c("iframe, object, embed").css("visibility","visible"))}ve(),y.find("iframe").prop("src","").empty(),n.prototype.setup(),he.clear(),V.removeClass("on video").addClass("pbHide"),N=-1,w.on(U,e),R&&e(),setTimeout(function(){r=null},1e3),setTimeout(e,500),"function"==typeof l.afterClose&&l.afterClose(V)}window.onpopstate=(re=window.onpopstate,function(e){re&&re.apply(this,arguments),"photobox"==e.state&&he.load()}),c.event.special.swipe={setup:function(){c(this).bind("touchstart",c.event.special.swipe.handler)},teardown:function(){c(this).unbind("touchstart",c.event.special.swipe.handler)},handler:function(o){var i,n,s=[].slice.call(arguments,1),e=o.originalEvent.touches,a=0,r=0,l=this;function h(){l.removeEventListener("touchmove",t),i=n=null}function t(e){e.preventDefault();var t=i-e.touches[0].pageX,e=n-e.touches[0].pageY;return 20<=Math.abs(t)?(h(),a=0<t?-1:1):20<=Math.abs(e)&&(h(),r=0<e?1:-1),o.type="swipe",s.unshift(o,a,r),(c.event.dispatch||c.event.handle).apply(l,s)}o=c.event.fix(o),1==e.length&&(i=e[0].pageX,n=e[0].pageY,this.addEventListener("touchmove",t,!1))}},le=function(c){function t(e){var t,o=e||window.event,i=m.call(arguments,1),n=0,s=0,a=0,r=0,l=0,h=0;if((e=c.event.fix(o)).type="mousewheel","detail"in o&&(a=-1*o.detail),"wheelDelta"in o&&(a=o.wheelDelta),"wheelDeltaY"in o&&(a=o.wheelDeltaY),"wheelDeltaX"in o&&(s=-1*o.wheelDeltaX),"axis"in o&&o.axis===o.HORIZONTAL_AXIS&&(s=-1*a,a=0),n=0===a?s:a,"deltaY"in o&&(n=a=-1*o.deltaY),"deltaX"in o&&(s=o.deltaX,0===a&&(n=-1*s)),0!==a||0!==s){1===o.deltaMode?(n*=t=c.data(this,"mousewheel-line-height"),a*=t,s*=t):2===o.deltaMode&&(n*=t=c.data(this,"mousewheel-page-height"),a*=t,s*=t);var r=Math.max(Math.abs(a),Math.abs(s));return f&&!(r<f)||d(o,f=r)&&(f/=40),d(o,r)&&(n/=40,s/=40,a/=40),n=Math[1<=n?"floor":"ceil"](n/f),s=Math[1<=s?"floor":"ceil"](s/f),a=Math[1<=a?"floor":"ceil"](a/f),v.settings.normalizeOffset&&this.getBoundingClientRect&&(r=this.getBoundingClientRect(),l=e.clientX-r.left,h=e.clientY-r.top),e.deltaX=s,e.deltaY=a,e.deltaFactor=f,e.offsetX=l,e.offsetY=h,e.deltaMode=0,i.unshift(e,n,s,a),p&&clearTimeout(p),p=setTimeout(u,200),(c.event.dispatch||c.event.handle).apply(this,i)}}function u(){f=null}function d(e,t){return v.settings.adjustOldDeltas&&"mousewheel"===e.type&&t%120==0}var p,f,e=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],o="onwheel"in document||9<=document.documentMode?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],m=Array.prototype.slice;if(c.event.fixHooks)for(var i=e.length;i;)c.event.fixHooks[e[--i]]=c.event.mouseHooks;var v=c.event.special.mousewheel={version:"3.1.11",setup:function(){if(this.addEventListener)for(var e=o.length;e;)this.addEventListener(o[--e],t,!1);else this.onmousewheel=t;c.data(this,"mousewheel-line-height",v.getLineHeight(this)),c.data(this,"mousewheel-page-height",v.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var e=o.length;e;)this.removeEventListener(o[--e],t,!1);else this.onmousewheel=null;c.removeData(this,"mousewheel-line-height"),c.removeData(this,"mousewheel-page-height")},getLineHeight:function(e){e=c(e)["offsetParent"in c.fn?"offsetParent":"parent"]();return e.length||(e=c("body")),parseInt(e.css("fontSize"),10)},getPageHeight:function(e){return c(e).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};c.fn.extend({mousewheel:function(e){return e?this.bind("mousewheel",e):this.trigger("mousewheel")},unmousewheel:function(e){return this.unbind("mousewheel",e)}})},"function"==typeof define&&define.amd?define(["jquery"],le):"object"==typeof exports?module.exports=le:le(jQuery),c(s).ready($),window._photobox={DOM:{overlay:V},close:ge,history:he,defaults:J}}(jQuery,document,window);