-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathseadragon-pivot-standalone-min.js
22 lines (21 loc) · 101 KB
/
seadragon-pivot-standalone-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Copyright (c) Microsoft Corporation
// All rights reserved.
// BSD License
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
// following conditions are met:
//
// Redistributions of source code must retain the above copyright notice, this list of conditions and the following
// disclaimer.
//
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
(function(n,t,i,r){function go(n){var r=null,i=null,u=null,t=null,c=/MSIE ([^\s;)]+)/.exec(n),h=/Firefox\/(\S+)/.exec(n),a=/Safari\/(\S+)/.exec(n),l=/Chrome\/(\S+)/.exec(n),e=/Version\/(\S+)/.exec(n),f=/; Trident\/([^\s;)]+)/.exec(n),s=/rv\:([^\s)]+)\) Gecko\//.exec(n),o=/WebKit\/(\S+)/.exec(n);return c?(r=bu,i=c[1],u=se,f&&(t=f[1])):s?(u=ce,t=s[1],h&&(r=wu,i=h[1])):o&&(u=fe,t=o[1],l?(r=ku,i=l[1]):a&&e&&(r=eu,i=e[1],t=a[1])),{name:r,version:i,engine:u,engineVersion:t}}function ys(){var t=new e,r=n.documentElement||{},i=n.body||{};return typeof window.pageXOffset=="number"?(t.x=pageXOffset,t.y=pageYOffset):i.scrollLeft||i.scrollTop?(t.x=i.scrollLeft,t.y=i.scrollTop):(r.scrollLeft||r.scrollTop)&&(t.x=r.scrollLeft,t.y=r.scrollTop),t}function bi(n){this.capacity=n>1?n:2,this.oldest=null,this.newest=null}function nf(n,t){return function(i,r,u){var e,f=n[i];if(f)return typeof r=="function"&&f.seadragon.callbacks.push(r),!0;e=hs(i);if(!tf(e)&&!u)return!1;return f=t(i),f?(lh(e),n[i]=f,f.seadragon={url:i,hostname:e,callbacks:typeof r=="function"?[r]:[]},!0):!1}}function sh(n,t,i,r){for(var f=n.length,u=0;u<f;u++)try{n[u](t,i,r)}catch(e){w("Seadragon2.Network callback {0} for {1} threw an error:\n{2}",u,t,e)}}function gi(n,t){function i(){var i=this.seadragon,r=i.url;ch(i.hostname),delete n[r];try{delete this.seadragon}catch(u){this.seadragon=null}sh(i.callbacks,r,t,this)}return window.ActiveXObject?te(i,0):i}function bt(n,t,i,r,u){var f=cs(r.getTileInfo(n,t,i));this.level=n,this.col=t,this.row=i,this.tileBelow=u,this.url=f.url,this.crop=f.crop,this.bounds=r.getTileBounds(n,t,i),this.drawnOpaque=!1,this.tilesAbove=r.getNumTilesAbove(n,t,i),this.covered=0,this.loading=!1,this.area=0,this.distance=0,this.opacity=1,this.inBounds=!0,this.view=null}function gs(n,t){this.bounds=kr,this.tiles={},this.num=n,this.visible=!1,this.fading=!1,this.tilesVisible=0,this.opacity=1,this.dimensions=t.getLevelDimensions(n),this.view=null}function bs(n,t){var u=nt[n],r=nt[t],f=r.area-u.area,i;if(f)return f;return i=u.distance-r.distance,i?i:u.level-r.level}function uh(n,t,i){var r=ci[n],f,s,h,u,o,e;r||c("Seadragon2.TileLoader: [internal] no img info for "+n),e=vu.insert(r),e&&delete ci[e.url],r.loading=!1,r.loaded=t,r.failed=!t,r.img=i,f=r.tiles,s=r.callbacks,h=r.args;try{delete r.tiles,delete r.callbacks,delete r.args}catch(l){r.tiles=null,r.callbacks=null,r.args=null}for(o=f.length,u=0;u<o;u++)f[u]&&s[u](h[u],f[u],r);or()}function rh(){var r,f,n,i=[],u=tf(),t;lr=!1;for(n in nt)nt.hasOwnProperty(n)&&nt[n]&&i.push(n);for(i.sort(bs),f=i.length,r=0;r<f&&u>0;r++){n=i[r];if(gu(n,uh)){u--,t=nt[n],ci[n]={loading:!0,loaded:!1,failed:!1,img:null,tiles:t.tiles,callbacks:t.callbacks,args:t.args,url:n};try{delete nt[n]}catch(e){nt[n]=null}}}}function fh(n,t,i){var u=n.url,r=ci[u];if(r){r.tiles?(r.tiles.push(n),r.callbacks.push(t),r.args.push(i),r.nominators++):w("Nomination dropped: "+u);return}return r=nt[u],r?(r.tiles.push(n),r.callbacks.push(t),r.args.push(i),r.area+=n.area,r.distance=gt(r.distance,n.distance),r.nominators++):nt[u]={tiles:[n],callbacks:[t],args:[i],nominators:1,area:n.area,distance:n.distance,level:n.level},or(),nt[u].tiles.length-1}function oh(n){var t=ci[n];return t&&!t.loading&&vu.refresh(t),t||ps}function ee(){for(var e=n.getElementsByTagName("sdimg"),o=e.length,t,i,f,u,r=0;r<o;r++){t=e[r];if(!t.update){f=t.nextSibling,u=t.parentNode;while(t.hasChildNodes()){i=t.firstChild,t.removeChild(i);if(i.className==="sdimgcontainerdiv")continue;f?u.insertBefore(i,f):u.appendChild(i)}new ki(null,e[r])}}return!0}function ne(n,t){var u=n.levelData,r=n.tile,i,e=n.startTime,f=n.state,o=n.last||e;if(!u.visible||!r.inBounds||r.isCovered()||u.fading||r.drawnOpaque)return!1;i=(t-e)/f.blendInTime,(i>1||t-o>67)&&(i=1),f.drawer.updateBlend(r,u.view,i),r.opacity=i;if(i===1){if(!u.fading)f.onDrawn(r);return!1}return n.last=t,!0}function io(n,t){var u=n.state,i=n.levelData,e=n.level,o=u.levels,f=n.startTime,r,s=n.last||f;return o[e]!==i?!1:(r=1-(t-f)/u.fadeOutTime,t-s>67&&(r=0),r>0?(i.visible&&(i.opacity=r,u.drawer.updateFade(i.view,r)),n.last=t,!0):(i.visible&&u.drawer.removeLevel(i.view),delete o[e],!1))}function ro(n,t,i){var r=n.levelData,f=r.bounds,u=n.state;t.loading=!1;if(i.failed||!f||!t.inBounds||!r.visible||r.fading)return;if(t.isCovered())return;u.blendTile(i.img,t)}function uu(n){n.state&&n.state.destroy(),n.state=null}function sr(n,t){n.immediateMode&&n.parentNode?n.immediateMode=!1:n.skippedParentCheck=yi(i.random()*30);var u=n.immediateMode?yu:le(n.container,t.normHeight);n.state=new rf(t,u,n.blendTime,n.fadeTime),us(n,"load",!1)}function co(n,t){hu(t,function(i){i instanceof ot?sr(n,i):w("SDImage: failed to fetch tile source at "+t)})}function iu(n){var i=n.src,t=typeof i;t==="string"?co(n,i):t==="object"?sr(n,yo(i)):c("Unsupported src type: "+t)}function to(n){uu(n),iu(n)}function pe(){}function we(n,t,i){if(!n.state)return;n.immediateMode&&(n.skippedParentCheck>30?(n.parentNode&&(n.immediateMode=!1,sr(n,n.state.source)),n.skippedParentCheck=0):n.skippedParentCheck++);var o=n.container,u=t||dr(o),s=u.width,h=u.height,r,e;t||i?e=i:(r=wt(),n.clipParent&&(r=r.intersect(dr(n.clipParent)),r||(r=new f(0,0,0,0))),e=es(o,u,r));if(!s||!h)return;t||(u.x-=r.width/2,u.y-=r.height/2),n.state.update(u,e,n.blur-ru)}function lu(n,t,i,r){var f=n.lastSrc,u=n.src;return!f&&u?iu(n):f&&!u?uu(n):u!==f?to(n):u?u?we(n,i,r):w("SDImage_onTick: unknown state! src={0}, lastSrc={1}",u,f):pe(n),n.lastSrc=u,!0}function b(n){if(!n)return"0";var u=i.floor(i.log(i.abs(n))/i.LN10),r=n/i.pow(10,u),t=0;while(t<10&&i.abs(r)>ve)t++,r=(r-i.round(r))*10;return u>=t&&u<t+5?n.toFixed(0):n.toPrecision(t)}function oo(t,f,e,o){function et(n){return Seadragon2.Math.round(n,r,g)}function yt(){ct.innerHTML=l===-Infinity?v===Infinity?"":"Under "+b(v):v===Infinity?"Over "+b(l):l===v?"Exactly "+b(l):b(l)+" – "+b(v)}function ot(n){var f=i.floor(y/a*c),r=n+"px",u=i.floor(n/a*c),t;for(y=n,vt.style.left=r,rt.style.left=r,l=n?et(s+(h-s)*n/a):-Infinity,yt(),t=f;t>u;t--)k.childNodes[t-1].className="pivot_filtergraphbar";for(t=f;t<u;t++)k.childNodes[t].className="pivot_filtergraphbar pivot_deselected"}function st(n){var f=i.floor(p/a*c),r=n+"px",u=i.floor(n/a*c),t;for(p=n,lt.style.right=r,rt.style.right=r,v=n?et(h-(h-s)*n/a):Infinity,yt(),t=f;t>u;t--)k.childNodes[c-t].className="pivot_filtergraphbar";for(t=f;t<u;t++)k.childNodes[c-t-1].className="pivot_filtergraphbar pivot_deselected"}function at(){var t=n.documentElement;t.className=t.className.replace(dt,""),l===-Infinity&&v===Infinity?tt.trigger("unfilter",e):tt.trigger("filter",e,l,v,!0)}function pt(t){return t=" "+t,function(i,r,u){d=u.x,dt=t,n.documentElement.className+=t}}var g,ni,s=Infinity,h=-Infinity,rt,vt,lt,c,w,it,gt,ct,k,tt=this,ht,bt,wt,y=0,p=0,l=-Infinity,v=Infinity,a,kt,d,nt,ft,ut,dt;ct=u("div","pivot_numberlabel",t),Seadragon2.EventManager.call(tt),f.forEach(function(n){var i=n.facets[e],t;i&&(t=i[0],t<s&&(s=t),t>h&&(h=t))}),c=11,w=(h-s)/c,it=[],w===0&&(w=0,c=1);if(w<0)return ct.innerHTML="Not Currently Applicable",tt;for(kt=0;kt<c;kt++)it.push(0);f.forEach(function(n){var r=n.facets[e],t;r&&(t=w?i.floor((r[0]-s)/w):0,t>c-1&&(t=c-1),it[t]++)}),gt=it.reduce(function(n,t){return n>t?n:t},1),k=u("div","pivot_filtergraph",t),it.forEach(function(n,t){var i=u("div","pivot_filtergraphbar",k);i.style.width=100/c*.7+"%",i.style.left=100/c*(t+.15)+"%",i.style.height=100*n/gt+"%"}),ht=u("div","pivot_sliderouter",t),rt=u("div","pivot_slider",ht),vt=u("div","pivot_sliderhandle pivot_sliderleft",ht),lt=u("div","pivot_sliderhandle pivot_sliderright",ht),bt=u("div","pivot_left",t),wt=u("div","pivot_right",t);if(!w)return bt.innerHTML=s.toPrecision(4),wt.innerHTML=h.toPrecision(4),tt;a=parseFloat(Seadragon2.Element.getStyle(rt).width)-1,ni=i.floor(i.log((h-s)/a)/i.LN10),g=i.pow(10,ni),h=i.ceil(h/g)*g,s=i.floor(s/g)*g,bt.innerHTML=b(et(s)),wt.innerHTML=b(et(h)),o&&(o=o[0],l=o.lowerBound,v=o.upperBound,l===r?(ct.innerHTML="(no info)",l=-Infinity,v=Infinity):(l>s&&(ot(i.min(i.round((l-s)/(h-s)*a),a)),l=o.lowerBound),v<h&&(st(i.min(i.round((h-v)/(h-s)*a),a-y)),v=o.upperBound),yt())),nt=new Seadragon2.MouseTracker(rt),ft=new Seadragon2.MouseTracker(vt),ut=new Seadragon2.MouseTracker(lt),nt.addListener("release",at),ft.addListener("release",at),ut.addListener("release",at),ft.addListener("press",pt("pivot_wresize")),ut.addListener("press",pt("pivot_eresize")),nt.addListener("press",pt("pivot_pointer")),ft.addListener("drag",function(n,t,r){var u=i.min(i.max(y+r.x-d,0),a-p);u!==y&&ot(u)}),ut.addListener("drag",function(n,t,r){var u=i.min(i.max(p-r.x+d,0),a-y);u!==p&&st(u)}),nt.addListener("drag",function(n,t,r){var e=r.x-d>0,f,u;e?(f=i.max(p-r.x+d,0),f!==p&&(u=y-f+p,st(f),ot(u))):(u=i.max(y+r.x-d,0),u!==y&&(f=p-u+y,ot(u),st(f)))}),nt.setTracking(!0),ft.setTracking(!0),ut.setTracking(!0)}function uo(t,f,e,o,s,c){var v=this,a,l,w,b,y,k,g,rt=(e-f)/16,p,d,it,nt,tt;Seadragon2.EventManager.call(v),f<e||(f=0,e=1),typeof o!="number"&&(o=f+(e-f)/2),a=u("div","pivot_zoomout pivot_hoverable",t),a.innerHTML="−",a.title=s,y=u("div","pivot_zoomline",t),k=u("div","pivot_zoomhandle",y),nt=y.offsetWidth,tt=k.offsetWidth,g=(e-f)/(nt-tt),l=u("div","pivot_zoomin pivot_hoverable",t),h(l,"+"),l.title=c,a.onclick=function(){w||v.setValue(o-rt,!0)},l.onclick=function(){b||v.setValue(o+rt,!0)},p=new Seadragon2.MouseTracker(k),p.addListener("press",function(t,i,r){d=r.x,n.documentElement.className+=" pivot_eresize"}),p.addListener("release",function(){var t=n.documentElement;d=r,t.className=t.className.replace(" pivot_eresize","")}),p.addListener("drag",function(n,t,i){v.setValue((it+i.x-d)*g+f,!0)}),p.setTracking(!0),t.onclick=function(n){var r=n.target,i;(r===t||r===y)&&(i=Seadragon2.Mouse.getPosition(n).minus(Seadragon2.Element.getPosition(y)).x,i>=0&&i<nt&&v.setValue((i-tt/2)*g+f,!0))},v.setValue=function(n,t){if(d===r||t){var u=o;o=n,o>f?w&&(w=!1,a.title=s,a.className="pivot_zoomout pivot_hoverable"):(o=f,w||(w=!0,a.title="",a.className="pivot_zoomout pivot_hoverable pivot_disabled")),o<e?b&&(b=!1,l.title=c,l.className="pivot_zoomin pivot_hoverable"):(o=e,b||(b=!0,l.title="",l.className="pivot_zoomin pivot_hoverable pivot_disabled")),it=i.round((o-f)/g),k.style.left=it+"px",t&&u!==o&&v.trigger("change",o)}},v.setValue(o)}function ue(n){function a(n){1<<e>h||e++,o=o<<e|n,i+=e;while(i>=6)i-=6,f.push(v[o>>i&63])}n=unescape(encodeURIComponent(n));for(var u={},l,r=n[0],h=255,y=n.length,c,e=8,v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,i=0,f=[],p=65535,t=0;t<256;t++)u[String.fromCharCode(t)]=t;for(t=1;t<y;t++)l=n[t],c=r+l,s.call(u,c)?r=c:(a(u[r]),h<p&&(h++,u[c]=h),r=l);a(u[r]),i&&f.push(v[o<<6-i&63]);while(f.length%4)f.push("A");return f.join("")}var o,wf,gu,ff,cr,ft,ir,yt;typeof Seadragon2=="undefined"&&(window.Seadragon2={}),o=Seadragon2,wf=o.VERSION="2.0.pre",o.toString=function(){return"Seadragon Ajax v"+wf+"\nCopyright (c) Microsoft Corp.\nMore info: http://seadragon.com/ajax/"};var e=o.Point=function(n,t){this.x=n||0,this.y=t||0},ie=e.$=function(n){return n instanceof e?n:(n=n||{},new e(n.x,n.y))},ut=e.prototype,gf=new e(0,0);ut.plus=function(n){return new e(this.x+n.x,this.y+n.y)},ut.minus=function(n){return new e(this.x-n.x,this.y-n.y)},ut.times=function(n){return new e(this.x*n,this.y*n)},ut.divide=function(n){return new e(this.x/n,this.y/n)},ut.negate=function(){return new e(-this.x,-this.y)},ut.apply=function(n){return new e(n(this.x),n(this.y))},ut.distanceTo=function(n){var r=this.x-n.x,t=this.y-n.y;return i.sqrt(r*r+t*t)},ut.asSize=function(){return new l(this.x,this.y)},ut.equals=function(n){return this.x===(n.x||0)&&this.y===(n.y||0)},ut.toString=function(){return["(",this.x,",",this.y,")"].join("")};var l=o.Size=function(n,t){this.width=n||0,this.height=t||0},ph=l.$=function(n){return n instanceof l?n:(n=n||{},new l(n.width,n.height))},st=l.prototype;st.plus=function(n){return new l(this.width+n.width,this.height+n.height)},st.minus=function(n){return new l(this.width-n.width,this.height-n.height)},st.times=function(n){return new l(this.width*n,this.height*n)},st.divide=function(n){return new l(this.width/n,this.height/n)},st.negate=function(){return new l(-this.width,-this.height)},st.apply=function(n){return new l(n(this.width),n(this.height))},st.asPoint=function(){return new e(this.width,this.height)},st.equals=function(n){return this.width===(n.width||0)&&this.height===(n.height||0)},st.toString=function(){return["(",this.width,"x",this.height,")"].join("")};var f=o.Rect=function(n,t,i,u){n&&i===r&&n.x!==r&&(i=t.width,u=t.height,t=n.y,n=n.x),this.x=n||0,this.y=t||0,this.width=i||0,this.height=u||0},so=f.$=function(n){return n instanceof f?n:new f(n.x,n.y,n.width,n.height)},p=f.prototype,uc=new f(0,0,1,1),kr=new f(-1,-1,-1,-1);p.getArea=function(){return this.width*this.height},p.getAspectRatio=function(){return this.width/this.height},p.getNormHeight=function(){return this.height/this.width},p.getTopLeft=function(){return new e(this.x,this.y)},p.getBottomRight=function(){return new e(this.x+this.width,this.y+this.height)},p.getCenter=function(){return new e(this.x+this.width/2,this.y+this.height/2)},p.getSize=function(){return new l(this.width,this.height)},p.contains=function(n){var r=this.x+this.width,u=this.y+this.height,t=n.x+(n.width||0),i=n.y+(n.height||0);return this.x<=n.x&&this.y<=n.y&&r>=t&&u>=i},p.union=function(n){var r=i.min(this.x,n.x),t=i.min(this.y,n.y),e=i.max(this.x+this.width,n.x+(n.width||0)),u=i.max(this.y+this.height,n.y+(n.height||0));return new f(r,t,e-r,u-t)},p.intersect=function(n){var u=i.max(this.x,n.x),o=i.max(this.y,n.y),t=-u+i.min(this.x+this.width,n.x+(n.width||0)),r=-o+i.min(this.y+this.height,n.y+(n.height||0));return!t&&!r&&!(n instanceof f)?new e(u,o):t<0||r<0?null:new f(u,o,t,r)},p.scale=function(n,t){var r=t?t.x:this.x,i=t?t.y:this.y;return new f(r-n*(r-this.x),i-n*(i-this.y),this.width*n,this.height*n)},p.translate=function(n){return new f(this.x+(n.x||0),this.y+(n.y||0),this.width,this.height)},p.equals=function(n){return this.x===(n.x||0)&&this.y===(n.y||0)&&this.width===(n.width||0)&&this.height===(n.height||0)},p.toString=function(){return["[",this.x,",",this.y,"|",this.width,"x",this.height,"]"].join("")};var ge=o.String={},yf=ge.format=function(n,t){var r,i;if(arguments.length===2&&t&&t.constructor&&(t.constructor===Array||t.constructor===Object))r=t;else for(r=new Array(arguments.length-1),i=0;i<r.length;i++)r[i]=arguments[i+1];return n.replace(/\{[\d\w]+\}/g,function(n){var t=n.match(/[\d\w]+/);return r[t]||""})},et=o.Debug={alert:0,enabled:3},kh=et.log=function(n){if(et.enabled<3)return;arguments.length>1&&(n=yf.apply(this,arguments)),typeof console!="undefined"&&console.log?console.log(n):et.alert<3||alert(n)},w=et.warn=function(n){if(et.enabled<2)return;arguments.length>1&&(n=yf.apply(this,arguments)),typeof console!="undefined"&&console.warn?console.warn(n):et.alert<2||alert(n)},c=et.error=function(n,t){if(et.enabled<1)return;typeof console!="undefined"&&console.error?console.error(n):et.alert<1||alert(n);throw t||new Error(n);},fu=o.Object={},vi=fu.extend=function(n,t,i){for(var r in t)(i||t.hasOwnProperty(r))&&(n[r]=t[r]);return n},gh=fu.clone=function(n,t){return vi({},n,t)},ui=o.Function={},dt=ui.EMPTY=function(){},tu=ui.bind=function(n,t){for(var u=new Array(arguments.length-2),f=u.length,r=0;r<f;r++)u[r]=arguments[r+2];return typeof t=="string"&&(t=n[t]),function(){for(var r=arguments.length,i=0;i<r;i++)u.push(arguments[i]);t.apply(n,u)}},tc=ui.callback=function(){var u=arguments.length,r=new Array(u+1),i;for(r[0]=null,i=0;i<u;i++)r[i+1]=arguments[i];return tu.apply(ui,r)},te=ui.delay=function(n,t){return function(){setTimeout(tu(this,n),t)}},d=o.Browser={},se=d.TRIDENT="Trident",ce=d.GECKO="Gecko",fe=d.WEBKIT="Webkit",yh=d.PRESTO="Presto",bu=d.IE="IE",wu=d.FIREFOX="Firefox",eu=d.SAFARI="Safari",ku=d.CHROME="Chrome",ah=d.OPERA="Opera",ds,pu,eh,hh,wh,nc,dh;(function(){var n=go(navigator.userAgent),f=n.name,i=n.version,t=parseInt(i),o=parseFloat(i),u=n.engine,r=n.engineVersion,e=parseFloat(r);d.name=f,d.version=i,d.engine=u,d.engineVersion=r,n.name===bu?ds=t:n.name===wu?pu=t:n.name===eu?eh=t:n.name===ku&&(hh=t)})();var pt=o.Math={},g=i.max,gt=i.min,ti=pt.clamp=function(n,t,i){return g(t,gt(i,n))},ii=i.log,is=i.LN2,ts=i.LN10,gr=i.exp,fc=pt.log=function(n,t){return t?ii(n)/ii(t):ii(n)},tt=pt.log2=function(n){return ii(n)/is},ec=pt.log10=function(n){return ii(n)/ts},oc=pt.morton=function(){var e,f,r=arguments[0],u,i,t;typeof r=="object"?(e=r.x,f=r.y):(e=r,f=arguments[1]),u=0,i=0,t=1;while(t<=e||t<=f)t&e&&(u|=1<<2*i+1),t&f&&(u|=1<<2*i),i++,t=1<<i;return u},po=pt.reverseMorton=function(n){var r=[],i=[],u=0,f=0,t;while(n>0)i.push(n%2),n=n>>1,r.push(n%2),n=n>>1;for(t=0;t<r.length;t++)u+=(1<<t)*r[t];for(t=0;t<i.length;t++)f+=(1<<t)*i[t];return new e(u,f)},pi=i.ceil,yi=i.floor,kf=pt.round=function(n,t,i){return typeof i=="undefined"&&(i=1),typeof t=="undefined"&&(t=.5),n/=i,(n%1+1)%1<t?yi(n)*i:pi(n)*i},sf=o.Uri={},hf=sf.FILE_HOSTNAME="localhost",ls=location.hostname||hf,hs=sf.getHostname=function(n){var t=/^http[s]?:\/\/([\w-.]+)/i.exec(n),i;return t?t[1].toLowerCase():(i=/^file:\/\//i.exec(n))?hf:ls},lf=o.Xml={},as=lf.fetch=function(){function f(n,t){return function(){if(this.readyState!==4)return;this.status===0||this.status>=200&&this.status<300?n.call(this):t.call(this)}}var r=["Msxml2.XMLHTTP","Microsoft.XMLHTTP","Msxml3.XMLHTTP"],i,n,t,u,e=typeof XDomainRequest!="undefined";if(typeof XMLHttpRequest!="undefined")t=XMLHttpRequest;else if(typeof ActiveXObject!="undefined"){for(n=0;n<r.length;n++){i=r[n];try{new ActiveXObject(i),t=ActiveXObject,u=i;break}catch(o){w("Seadragon2.Xml: {0} ActiveX failed.",i)}}n<r.length||c("Seadragon2.Xml: no ActiveX worked.")}else c("Seadragon2.Xml: no fetching ability.");return t?function(n,i,r,o,s){var h=new t(u),l=o?"POST":"GET",c=!1;h.onreadystatechange=f(i,r),n=n.replace(/#.*/,"");try{h.open(l,n,!0)}catch(a){if(e)h=new XDomainRequest,h.onload=i,h.onerror=r,h.timeout=3e4,h.ontimeout=function(){},h.onprogress=function(){},h.open(l,n),c=!0;else throw a;}return o&&h.setRequestHeader&&h.setRequestHeader("Content-Type",s||"text/plain"),c?setTimeout(function(){h.send(o||null)},0):h.send(o||null),h}:dt}(),fs=lf.parse=function(){return typeof DOMParser!="undefined"?function(n){var r=new DOMParser,t=r.parseFromString(n,"text/xml"),i=t&&t.documentElement;return!i||i.nodeName==="parsererror"?null:t}:typeof ActiveXObject!="undefined"?function(n){var t=new ActiveXObject("Microsoft.XMLDOM");return t.async=!1,t.loadXML(n)&&t}:(c("Seadragon2.Xml: no parsing ability."),dt)}(),k=o.Element={},vh=k.$=function(t){return typeof t=="string"?n.getElementById(t):t},wt=k.getWindowDimensions=function(){return wt=typeof innerWidth!="undefined"?k.getWindowDimensions=function(){return new f(0,0,innerWidth,innerHeight)}:n.documentElement&&n.documentElement.clientHeight?k.getWindowDimensions=function(){var t=n.documentElement;return new f(0,0,t.clientWidth,t.clientHeight)}:n.body.clientHeight?k.getWindowDimensions=function(){var t=n.body;return new f(0,0,t.clientWidth,t.clientHeight)}:k.getWindowDimensions=function(){return new f(0,0,Infinity,Infinity)},wt()},dr=k.getBoundingClientRect=function(n){var t=n.getBoundingClientRect();return new f(t.left,t.top,t.right-t.left,t.bottom-t.top)},nu=k.getStyle=function(n){if(window.getComputedStyle)return getComputedStyle(n,null);if(n.currentStyle)return n.currentStyle;c("Unknown element style, no known technique.")},af=k.getOffsetParent=function(t,i){return i&&t!==n.body?n.body:t.offsetParent},os=k.getPosition=function(n){var t=new e,i=nu(n).position==="fixed",r=af(n,i);while(r)t.x+=n.offsetLeft,t.y+=n.offsetTop,i&&(t=t.plus(ys())),n=r,i=nu(n).position==="fixed",r=af(n,i);return t},es=k.getClippingBounds=function(n,t,i){t=t||dr(n),i=i||wt();var h=t.y,y=t.width+t.x,p=t.height+t.y,c=t.x,r,u,l,e,o=i.x,s=i.y,a=o+i.width,v=s+i.height;return r=g(0,s-h),u=g(0,o-c),l=gt(y,a)-c-u,e=gt(p,v)-h-r,new f(u,r,l,e)},fi=k.setOpacity=function(){var t=n.createElement("div");return typeof t.style.opacity!="undefined"?function(n,t){n.style.opacity=t}:typeof t.style.filter!="undefined"?function(n,t){var f="progid:DXImageTransform.Microsoft.Alpha(Opacity="+t*100+")",r,i,u;for(n.style.filter=f,r=n.children,u=r.length,i=0;i<u;i++)try{fi(r[i],t)}catch(e){}}:function(){}}(),pf={},rr=n.createElement,ss=function(t,i){pf["sd_"+t]=i,rr.call(n,t)},rs=k.transform=function(){for(var t,e,f=["MozTransform","msTransform","OTransform","WebkitTransform","transform"],o=n.documentElement.style,r="",u,i=f.length-1;i>=0;i--)if(typeof o[f[i]]!="undefined"){t=f[i],e=t+"Origin";break}return t==="MozTransform"&&(r="px"),u=t?function(n,i,u,f){var o=n.sdStyle;o||(o=n.sdStyle=n.style,o[e]="0 0"),i=i+r,u=u+r,f=f+",",o[t]="matrix("+f+"0,0,"+f+i+","+u+")"}:function(n,t,i,r){var u=n.style;u.left=t+"px",u.top=i+"px",u.fontSize=r+"em",u.width=r*100+"%",u.height=r*100+"%"}}();n.createElement=function(n){var t=pf["sd_"+n];return t?new t:rr.apply(this,arguments)};var di=o.Event={},cf=di.$=function(n){return n?n:typeof event!="undefined"?event:null},us=di.raise=function(){return n.createEvent?function(t,i,r){r=r||!1;var u=n.createEvent("HTMLEvents");return u.initEvent(i,r,!0),t.dispatchEvent(u)}:n.createEventObject?function(t,i){var r=n.createEventObject();try{return t.fireEvent("on"+i,r)}catch(u){w("Event not fired: "+i+". "+u.message)}}:(c("Seadragon2.Event: no raise ability."),dt)}(),tr=function(n){n=cf(n),n.preventDefault&&n.preventDefault(),n.cancel=!0,n.returnValue=!1},df=function(n){n=cf(n),n.stopPropagation&&n.stopPropagation(),n.cancelBubble=!0},a=di.add=function(){return typeof addEventListener=="function"?function(n,t,i,r){r=r||!1,n.addEventListener(t,i,r),t==="mousewheel"?n.addEventListener("DOMMouseScroll",i,r):t==="DOMMouseScroll"&&n.addEventListener("mousewheel",i,r)}:typeof attachEvent!="undefined"?function(n,t,i,r){n.attachEvent("on"+t,i),t==="DOMMouseScroll"&&n.attachEvent("onmousewheel",i),r&&n.setCapture&&n.setCapture()}:(c("Seadragon2.Event: no add ability."),dt)}(),rt=di.remove=function(){return typeof removeEventListener=="function"?function(n,t,i,r){r=r||!1,n.removeEventListener(t,i,r),t==="mousewheel"?n.removeEventListener("DOMMouseScroll",i,r):t==="DOMMouseScroll"&&n.removeEventListener("mousewheel",i,r)}:typeof detachEvent!="undefined"?function(n,t,i,r){n.detachEvent("on"+t,i),t==="DOMMouseScroll"&&n.detachEvent("onmousewheel",i),r&&n.releaseCapture&&n.releaseCapture()}:(c("Seadragon2.Event: no remove ability."),dt)}(),at=o.Timer=new function(){function s(){for(var u=(new t).getTime(),r,n=i;n;n=n.next){try{r=n.callback(n.arg,u)}catch(f){w("Exception caught in timer: "+f.message)}r||h.unregister(n)}}var h=this,i=null,c=16,n=null,o,e,f,r,u;this.register=function(n,t){var r={callback:n,arg:t};return r.next=i,i&&(i.prev=r),r.prev=null,i=r,e(),r},this.unregister=function(n){if(n.dead)return;n.next&&(n.next.prev=n.prev),n.prev?n.prev.next=n.next:i=n.next,i||f(),n.dead=!0},typeof mozRequestAnimationFrame=="function"?r=mozRequestAnimationFrame:typeof webkitRequestAnimationFrame=="function"?r=webkitRequestAnimationFrame:typeof msRequestAnimationFrame=="function"&&(r=msRequestAnimationFrame),r?(o=function(){if(u){u=!1,n=null;return}s(),r(o)},e=function(){u=!1,n||(n=!0,r(o))},f=function(){n&&(u=!0)}):(e=function(){n===null&&(n=setInterval(s,c))},f=function(){n!==null&&(clearInterval(n),n=null)})},ur=o.EventManager=function(){var n={};this.addListener=function(t,i){if(typeof i!="function")return;n.hasOwnProperty(t)||(n[t]=[]),n[t].push(i)},this.removeListener=function(t,i){var u=n[t],r,f;if(typeof i!="function"||!u)return;for(f=u.length,r=0;r<f;r++)if(i===u[r]){u.splice(r,1);return}},this.clearListeners=function(t){n.hasOwnProperty(t)&&delete n[t]},this.listListeners=function(t){if(n.hasOwnProperty(t)){var i=n[t];if(i&&i.length)return i.slice(0)}},this.trigger=function(t){var i=n[t],f=[].slice.call(arguments,1),r,u;if(!i)return;for(i=i.slice(0),u=i.length,r=0;r<u;r++)try{i[r].apply(window,f)}catch(e){w(e.name+" while executing "+t+" handler: "+e.message,e)}}},ef=o.Mouse={},of=ef.getPosition=function(t){var i=new e;return t.type==="DOMMouseScroll"&&pu<3?(i.x=t.screenX,i.y=t.screenY):typeof t.pageX=="number"?(i.x=t.pageX,i.y=t.pageY):typeof t.clientX=="number"?(i.x=t.clientX+n.body.scrollLeft+n.documentElement.scrollLeft,i.y=t.clientY+n.body.scrollTop+n.documentElement.scrollTop):c("Unknown event mouse position, no known technique."),i},vs=ef.getScroll=function(n){var t=0;return typeof n.wheelDelta=="number"?t=n.wheelDelta:typeof n.detail=="number"?t=n.detail*-1:Seadragon2.Debug.fail("Unknown event mouse scroll, no known technique."),t?t/i.abs(t):0};bi.prototype.insert=function(n){var t=null;return this.capacity>0||(t=this.oldest,this.remove(t)),this.capacity--,n.cacheOlder=this.newest,this.newest?this.newest.cacheNewer=n:this.oldest=n,this.newest=n,n.cacheNewer=null,t},bi.prototype.remove=function(n){this.capacity++,n.cacheOlder?n.cacheOlder.cacheNewer=n.cacheNewer:this.oldest=n.cacheNewer,n.cacheNewer?n.cacheNewer.cacheOlder=n.cacheOlder:this.newest=n.cacheOlder},bi.prototype.refresh=function(n){this.remove(n),this.insert(n)};var ei=o.TileInfo=function(n,t){this.url=n,this.crop=t?so(t):null},cs=ei.$=function(n){return n instanceof ei?n:typeof n=="string"?new ei(n,null):new ei(n.url,n.crop)},ot=o.TileSource=function(n,t,r,u,f,e,o){arguments.length===3&&typeof r=="object"&&(u=r.height,r=r.width);var h=tt(i.max(n,t)),s=pi(h),c=tt(r);this.width=n,this.height=t,this.tileWidth=r||u,this.tileHeight=u||r,this.tileOverlap=f||0,this.minLevel=ti(e||0,0,s),this.overviewLevel=ti(typeof o=="number"?o:c,this.minLevel,s),this.dimensions=new l(n,t),this.aspectRatio=n/t,this.normHeight=t/n,this.tileSize=new l(this.tileWidth,this.tileHeight),this.maxLevel=s,this.sharpen=s-h},yo=ot.$=function(n){var u,t,r,i;if(n instanceof ot)return n;typeof n.tileSize=="object"?(r=n.tileSize.width,i=n.tileSize.height):typeof n.tileSize=="number"&&(r=i=n.tileSize),u=new ot(n.width,n.height,n.tileWidth||r,n.tileHeight||i,n.tileOverlap,n.minLevel,n.maxLevel);for(t in n)n.hasOwnProperty(t)&&t!=="tileSize"&&(u[t]=n[t]);return u},y=ot.prototype;y.getLevelScale=function(n){var t=this.maxLevel-n;return t<31?1/(1<<t):i.pow(.5,t)},y.getNumTiles=function(n){var t=this.getLevelScale(n);return new l(i.ceil(t*this.width/this.tileWidth),i.ceil(t*this.height/this.tileHeight))},y.getPixelRatio=function(n){var t=this.getLevelDimensions(n);return new l(1/t.width,1/t.height)},y.getTileAtPoint=function(n,t,r){var u=ie(t).times(this.getLevelDimensions(n).width);return r&&(u.x%1==0&&u.x--,u.y%1==0&&u.y--),new e(i.floor(u.x/this.tileWidth),i.floor(u.y/this.tileHeight))},y.getTilesInRect=function(n,t){var o=this.getTileAtPoint(n,t.getTopLeft()),s=this.getTileAtPoint(n,t.getBottomRight(),!0),h=this.getNumTiles(n),r,e,i,u;return r=g(o.x,0),i=g(o.y,0),e=gt(s.x,h.width-1),u=gt(s.y,h.height-1),new f(r,i,e-r,u-i)},y.getTileBounds=function(n,t,r){var u=this.getLevelDimensions(n),s=1/u.width,h=this.normHeight/u.height,e,o;return e=t===0?0:this.tileWidth*t-this.tileOverlap,o=r===0?0:this.tileHeight*r-this.tileOverlap,new f(s*e,h*o,s*i.min(this.tileWidth+(t===0?1:2)*this.tileOverlap,u.width-e),h*i.min(this.tileHeight+(r===0?1:2)*this.tileOverlap,u.height-o))},y.getTileInfo=function(){return null},y.levelExists=function(){return!0},y.tileExists=function(){return!0},y.getLevelDimensions=function(n){return this.dimensions.times(this.getLevelScale(n)).apply(pi)},y.getTileBelow=function(n,t,i,r){var f,o,u;return typeof r=="undefined"&&(r=n-1),r<this.minLevel||!this.levelExists(r)?null:(f=this.getLevelScale(n),o=this.getLevelScale(r),u=o/f,new e(yi(t*u),yi(i*u)))},y.getTilesAbove=function(n,t,i,r){var s,h,e,u,o;return typeof r=="undefined"&&(r=n+1),r>this.maxLevel||!this.levelExists(r)?null:(o=this.getNumTiles(r),s=this.getLevelScale(n),h=this.getLevelScale(r),e=h/s,u=new f(t*e,i*e,e-1,e-1),u.x+u.width<o.width||(u.width=o.width-u.x-1),u.y+u.height<o.height||(u.height=o.height-u.y-1),u)},y.getNumTilesAbove=function(n,t,i,r){var u=this.getTilesAbove(n,t,i,r);return u?(u.width+1)*(u.height+1):Infinity};var oi=o.DisplayRect=function(n,t,i,r,u,f){this.base(n,t,i,r),this.base=this.base.prototype,this.minLevel=u||0,this.maxLevel=f||Number.POSITIVE_INFINITY},rc=oi.$=function(n){return n instanceof oi?n:new oi(n.x,n.y,n.width,n.height,n.minLevel,n.maxLevel)},yr=oi.prototype=new f;yr.base=f,yr.equals=function(n){return this.base.equals.call(this,n)&&(this.minLevel===n.minLevel||0)&&(this.maxLevel===n.maxLevel||0)},yr.toString=function(){return this.base.toString.call(this).replace("]",["|",this.minLevel,"-",this.maxLevel,"]"].join(""))};var wi=o.DziTileSource=function(n,t,r,u,f,e,o){this.base(n,t,r,r,u),this.base=this.base.prototype,this.tilesUrl=f,this.imageFormat=e,this.displayRects=o,this.isSparse=!!(o&&o.length>1),this.displayRectsByLevel=function(){var u,t,f=this.displayRects,n,o,e,r={};if(!this.isSparse)return null;for(u=0;u<f.length;u++)for(t=f[u],o=i.max(t.minLevel,this.minLevel),e=i.min(t.maxLevel,this.maxLevel),n=o;n<=e;n++)r[n]?r[n].push(t):r[n]=[t];return r}.call(this)},wo=wi.$=function(n){var t;return n instanceof wi?n:(t=n.tileSize,typeof t=="object"&&(t=t.width||t.height),new wi(n.width,n.height,t||n.tileWidth||n.tileHeight,n.tileOverlap,n.tilesUrl,n.imageFormat,n.displayRects))},li=wi.prototype=new ot;li.base=ot,li.getTileInfo=function(n,t,i){return[this.tilesUrl,n,"/",t,"_",i,".",this.imageFormat].join("")},li.tileExists=function(n,t,r){var o,f,u,e,h,v,s,y,p,c,l,a;if(!this.isSparse)return!0;u=this.displayRectsByLevel[n];if(!u||!u.length)return!1;for(o=0;o<u.length;o++){f=u[o],e=this.getLevelScale(n),h=f.x*e,s=f.y*e,v=h+f.width*e,y=s+f.height*e,p=i.floor(h/this.tileWidth),l=i.floor(s/this.tileHeight),c=i.ceil(v/this.tileWidth),a=i.ceil(y/this.tileHeight);if(p<=t&&t<c&&l<=r&&r<a)return!0}return!1},li.getTileBelow=function(n,t,i,u){return u===r&&(u=n-1),u<=this.dzcMaxLevel?u<this.minLevel||!this.levelExists(u)?null:gf:y.getTileBelow.call(this,n,t,i,u)};var ai=o.DzcTileSource=function(n,t,i,r,u,f,e,o,s){this.base(n,t,i),this.base=this.base.prototype,this.dzcTileSize=i,this.dzcMaxLevel=r,this.dzcItemId=u,this.dzcTilesUrl=f,this.dzcImageFormat=e,this.dzcExpansionUrl=s,this.dziSource=null,this.dziSourceRequested=!1,this.dzcItemCoords=po(o)},su=ai.$=function(n){return n instanceof ai?n:new ai(n.width,n.height,n.dzcTileSize,n.dzcMaxLevel,n.dzcItemId,n.dzcTilesUrl,n.dzcImageFormat,n.dzcItemN,n.dzcExpansionUrl)},it=ai.prototype=new ot;it.base=ot,it.isDzc=!0,it.getTileInfo=function(n){var e=1<<n,t=this.dzcTileSize/(1<<n),o=this.getLevelScale(n),r=this.dzcItemCoords.y,u=this.dzcItemCoords.x,h=i.floor(r/t),s=i.floor(u/t);return new ei([this.dzcTilesUrl,n,"/",h,"_",s,".",this.dzcImageFormat].join(""),new f(r%t*e,u%t*e,i.max(1,i.floor(o*this.width)),i.max(1,i.floor(o*this.height))))},it.levelExists=function(n){return n<=this.dzcMaxLevel},it.getTilesAbove=function(n,t,i,u){u===r&&(u=n+1);if(u>this.dzcMaxLevel){var o=this.dziSource,e;if(o){e=this.getNumTiles(u);if(e)return new f(0,0,e.width-1,e.height-1)}return null}return new f(0,0,0,0)},(function(){var n;for(n in it)(function(){var t=n,i=it[t];t!=="base"&&typeof i=="function"&&(it[t]=function(n,r,u,f){var e=this.dziSource;return n>this.dzcMaxLevel&&e?e[t](n,r,u,f):i.call(this,n,r,u,f)})})()})(),it.expand=function(){var n;if(this.dziSource||this.dziSourceRequested||!this.dzcExpansionUrl)return;this.dziSourceRequested=!0,n=this,hu(this.dzcExpansionUrl,function(t){n.dziSource=t,t.dzcMaxLevel=n.dzcMaxLevel})},it.contract=function(){this.dziSource=null,this.dziSourceRequested=!1};var ou=o.DeepZoom={},vr={},lo=function(n){for(var f=n.getElementsByTagName("Size")[0],e=n.getElementsByTagName("DisplayRect"),o={width:parseInt(f.getAttribute("Width"),10),height:parseInt(f.getAttribute("Height"),10),tileSize:parseInt(n.getAttribute("TileSize"),10),tileOverlap:parseInt(n.getAttribute("Overlap"),10),imageFormat:n.getAttribute("Format"),dispRects:[]},r,t,u,i=0;i<e.length;i++)r=e[i],t=r.getElementsByTagName("Rect")[0],u=new oi(parseInt(t.getAttribute("X"),10),parseInt(t.getAttribute("Y"),10),parseInt(t.getAttribute("Width"),10),parseInt(t.getAttribute("Height"),10),0,parseInt(r.getAttribute("MaxLevel"),10)),o.dispRects.push(u);return o},ao=function(n){for(var l=n.getAttribute("Format"),y=parseInt(n.getAttribute("MaxLevel"),10),a=parseInt(n.getAttribute("TileSize"),10),s=n.getElementsByTagName("I"),v=s.length,c=new Array(v),t,o,e,r,u,h,i=0;i<s.length;i++)t=s[i],o=t.getElementsByTagName("Size")[0],e=t.getElementsByTagName("Viewport"),r={id:parseInt(t.getAttribute("Id"),10),n:parseInt(t.getAttribute("N"),10),width:parseInt(o.getAttribute("Width"),10),height:parseInt(o.getAttribute("Height"),10),source:t.getAttribute("Source"),viewport:null,dzcTileSize:a,dzcMaxLevel:y,dzcImageFormat:l},e.length<1||(u=e[0],h=parseFloat(u.getAttribute("Width")),r.viewport=new f(parseFloat(u.getAttribute("X")),parseFloat(u.getAttribute("Y")),h,h*r.height/r.width)),c[i]=r;return c},bf=function(n){var t,i;typeof n=="string"&&(n=fs(n));if(!n||!n.documentElement)return null;return t=n.documentElement,i=t.tagName,i==="Image"?lo(t):i==="Collection"?ao(t):null},vo=ou.getTilesUrl=function(n){var t=n.split("/"),u=t.length-1,r=t[u],i=r.lastIndexOf(".");return i>-1&&(t[u]=r.slice(0,i)),t.join("/")+"_files/"},cu=function(n,t){return t?n.substr(0,n.lastIndexOf("/"))+"/"+t:null},ns=function(n,t,i){for(var f=n.length,e=new Array(f),r,u=0;u<f;u++)r=n[u],r.dzcItemId=r.id,r.dzcItemN=r.n,r.dzcTilesUrl=i,r.dzcExpansionUrl=cu(t,r.source),e[u]=su(r);return e},ar=function(n,t){var r=vo(t),i;return n instanceof Array?(i=parseInt(t.substring(t.lastIndexOf("#")+1),10),isNaN(i)?ns(n,t,r):(n=n[i],n.dzcItemId=n.id,n.dzcItemN=n.n,n.dzcTilesUrl=r,n.dzcExpansionUrl=cu(t,n.source),su(n))):(n.tilesUrl=r,wo(n))},bh=function(n,t){var i=bf(t);return ar(i,n)},hu=ou.fetchTileSource=function(n,t){var u=n.split("#",1)[0],r=vr[u],i;r?setTimeout(function(){t(ar(r,n))},0):(i=ff(u,function(i,r,u){var e,f;if(r){f=vr[i];if(!f){e=u.responseXML||u.responseText,f=bf(e);if(!f)return;vr[i]=f}t(ar(f,n))}else w("DeepZoom.fetchTileSource (callback): XML fetch failed.")},!0),i||w("DeepZoom.fetchTileSource: Failed to make request."))},kt=o.Network={},bo=kt.MAX_CONNECTIONS_PER_HOSTNAME=6,ko=kt.MAX_CONNECTIONS_TOTAL=30,si={},hi=0,wr={},pr={},tf=kt.numSpotsAvailable=function(n){var t=i.max(0,ko-(hi||0));return n?i.min(t,i.max(0,bo-(si[n]||0))):t},ch=kt.markSpotOpen=function(n){si[n]=i.max(0,(si[n]||0)-1),hi=i.max(0,(hi||0)-1)},lh=kt.markSpotTaken=function(n){si[n]=(si[n]||0)+1,hi=(hi||0)+1};gu=kt.tryMakeImageRequest=nf(wr,function(t){var i=n.createElement("img");return i.onload=th,i.onerror=i.onabort=ih,i.src=t,i}),ff=kt.tryMakeXmlHttpRequest=nf(pr,function(n){return as(n,nh,ks)});var th=gi(wr,!0),ih=gi(wr,!1),nh=gi(pr,!0),ks=gi(pr,!1);bt.prototype.resetCoverage=function(){this.covered=0},bt.prototype.covers=function(){return this.drawnOpaque||this.tilesAbove===this.covered},bt.prototype.isCovered=function(){return this.covered===this.tilesAbove},bt.prototype.cover=function(){return this.covered++,this.covered>this.tilesAbove&&c("tile coverage is broken!"),this.covered===this.tilesAbove},bt.prototype.uncover=function(){return this.covered--,this.covered<0&&c("tile coverage is broken"),this.covered+1===this.tilesAbove},bt.prototype.drawn=function(){return(this.drawnOpaque||this.isCovered())&&c("tile coverage is broken"),this.drawnOpaque=!0,!0};var ci={},lr=!1,or,vu=new bi(1e3),nt={},ps={loading:!1,loaded:!1,failed:!1,img:null,owners:null,tileInfos:null};or=function(){lr||(lr=!0,setTimeout(rh,0))};var ht=o.ImageManager={},ri=null,fr=!0;ht.register=function(n,t){if(fr)return at.register(n,t)},ht.unregister=function(n){return at.unregister(n)},ht.enableMarkupChecking=function(){ri||(ri=at.register(ee))},ht.disableMarkupChecking=function(){ri&&(at.unregister(ri),ri=null)},ht.enable=function(){fr=!0},ht.disable=function(){fr=!1};var oe=typeof n.createElement("canvas").getContext=="function",ni=function(n,t){this.container=n,this.normHeight=t},ct=ni.prototype,le=function(n,t){return oe?new cr(n,t):new du(n,t)},yu=new ni;ct.drawTile=function(n){return n},ct.addLevelOnTop=function(){return!0},ct.addLevelBehind=function(){return!0},ct.removeLevel=function(){},ct.updateBlend=function(){},ct.updateFade=function(){},ct.discardTile=function(){},ct.setLevelDimensions=function(){},cr=function(){ni.apply(this,arguments)},ft=cr.prototype=new ni,ft.drawTile=function(n,t,i,r){var y,e,l,s,u,a,v,o=t.crop,c=t.bounds,h=0;if(!n.complete){w("Seadragon2.Canvas.drawImage: ignoring incomplete image: "+n.src);return}typeof r!="number"?r=t.opacity:h=t.opacity;if(!i.canvas){w("SDCanvasDrawer: nonexistent level");return}return y=i.canvas,e=y.getContext("2d"),l=i.fullSize,s=i.normalizedBounds,r!==1&&(e.save(),h=h||0,e.globalAlpha=(r-h)/(1-h)),a=l.width/s.width,v=l.height/s.height,u=new f((c.x-s.x)*a,(c.y-s.y)*v,c.width*a,c.height*v),o?e.drawImage(n,o.x,o.y,o.width,o.height,u.x,u.y,u.width,u.height):e.drawImage(n,u.x,u.y,u.width,u.height),r!==1&&e.restore(),n},ft.updateBlend=function(n,t,i){t.canvas||c("CanvasDrawer: Attempting to blend tile on nonexistent level!"),this.drawTile(n.view,n,t,i)},ft.updateFade=function(n,t){fi(n.canvas,t)},ft.positionLevel=function(n){var r=n.canvas,t=n.normalizedBounds,i=r.style;i.left=(t.x*100).toFixed(8)+"%",i.top=(t.y/this.normHeight*100).toFixed(8)+"%",i.width=(t.width*100).toFixed(8)+"%",i.height=(t.height/this.normHeight*100).toFixed(8)+"%"},ft.setLevelDimensions=function(n){var l=n.view.canvas,f=n.bounds,o=n.tiles,a,r,h=f.x,c=f.y,y=f.width+h,v=f.height+c,u,i,t=n.dimensions,s;s=o[h][c].bounds.union(o[y][v].bounds),t=s.scale(t.width,new e(0,0)),t.width=kf(t.width)||1,t.height=kf(t.height)||1,l.width=t.width,l.height=t.height,n.view.fullSize=t,n.view.normalizedBounds=s,this.positionLevel(n.view);if(o)for(u=h;u<=y;u++)for(a=o[u],i=c;i<=v;i++)r=a[i],r.view&&this.drawTile(r.view,r,n.view)},ft.makeCanvas=function(t){var r=n.createElement("canvas"),i=r.style;return i.display="block",i.position="absolute",i.overflow="hidden",i.width="100%",i.height="100%",t.canvas=r,t.normalizedBounds=new f(0,0,1,this.normHeight),r},ft.addLevelOnTop=function(){var n={};return this.container.appendChild(this.makeCanvas(n)),n},ft.addLevelBehind=function(n){var t={};return this.container.insertBefore(this.makeCanvas(t),n.canvas),t},ft.removeLevel=function(n){this.container.removeChild(n.canvas),delete n.canvas};var he=n.documentMode?"bicubic":"nearest-neighbor",du=function(){ni.apply(this,arguments)},vt=du.prototype=new ni;vt.drawTile=function(t,i,r){var o=i.crop,h=i.bounds,l=i.opacity,s,u,e,f;return r||c("SDImgDrawer: nonexistent level"),s=n.createElement("img"),u=s.style,s.src=t.src,u.position="absolute",u.msInterpolationMode=he,o?(e=n.createElement("div"),f=e.style,f.position="absolute",f.overflow="hidden",u.left=(-100*o.x/o.width).toFixed(8)+"%",u.top=(-100*o.y/o.height).toFixed(8)+"%",u.width=(100*t.width/o.width).toFixed(8)+"%",u.height=(100*t.height/o.height).toFixed(8)+"%",e.appendChild(s)):(e=s,f=u),f.left=(100*h.x).toFixed(8)+"%",f.top=(100*h.y/this.normHeight).toFixed(8)+"%",f.width=(100*h.width).toFixed(8)+"%",f.height=(100*h.height/this.normHeight).toFixed(8)+"%",r.appendChild(e),typeof l=="number"&&fi(e,l),e},vt.updateBlend=function(n,t,i){fi(n.view,i)},vt.updateFade=function(n,t){fi(n,t)},vt.makeDiv=function(){var i=n.createElement("div"),t=i.style;return t.display="block",t.position="absolute",t.overflow="visible",t.width="100%",t.height="100%",i},vt.addLevelOnTop=function(){var n=this.makeDiv();return this.container.appendChild(n),n},vt.addLevelBehind=function(n){var t=this.makeDiv();return this.container.insertBefore(t,n),t},vt.removeLevel=function(n){this.container.removeChild(n)},vt.discardTile=function(n,t){t.removeChild(n.view)};var rf=function(n,t,i,r){this.blendInTime=i||0,this.fadeOutTime=r||0,this.source=n,this.drawer=t,this.maxLevel=n.minLevel-1,this.clip=new f(0,0,1,n.normHeight),this.levels={},this.position=kr},v=rf.prototype,uf=at;v.update=function(n,t,i){var r=this.source,u,o=this.position,e=r.normHeight;i=i||0,n&&!o.equals(n)&&(this.position=n),t&&(t=new f(t.x/n.width,t.y*e/n.height,t.width/n.width,t.height*e/n.height));if(n){u=ti(pi(tt(g(n.width,n.height))-i+r.sharpen),r.minLevel,r.maxLevel),r.isDzc&&(u>r.dzcMaxLevel?r.expand():r.contract());while(!r.levelExists(u))u--}else u=this.maxLevel;u!==this.maxLevel&&this.setLevel(u),t&&!t.equals(this.clip)&&this.setClipBounds(t)},v.setLevel=function(n){var r=this.maxLevel,t,i,f=this.clip,u;this.maxLevel=n;if(r<n)for(t=r+1;t<=n;t++)i=this.initLevelData(t),this.setLevelClipBounds(i,f),this.drawLevel(i,null,!0);else if(r>n){for(t=r;t>n;t--)i=this.levels[t],i&&i.visible&&(u=this.levels[t]),this.fadeLevel(t),this.setLevelClipBounds(i,kr);this.redrawAllLevels(u)}},v.redrawAllLevels=function(n){for(var u=this.maxLevel,r=this.source.minLevel,i=this.levels,t=u;t>=r;t--)this.drawLevel(i[t],n),i[t].visible&&(n=i[t])},v.setClipBounds=function(n){var u=this.source.minLevel,i=this.maxLevel,r=this.levels,t;for(this.clip=n,t=u;t<=i;t++)this.setLevelClipBounds(r[t],n);this.redrawAllLevels()},v.destroy=function(){for(var t=this.levels,n=this.minLevel;n<=this.maxLevel;n++)t[n].view&&this.drawer.removeLevel(t[n].view);this.levels=null,this.blendTile=dt,this.onTileDrawn=dt,this.getTilePriority=function(){return 0},this.drawer=null},v.blendTile=function(n,i){var u=(new t).getTime(),r=this.levels[i.level];i.opacity=0,i.view=this.drawer.drawTile(n,i,r.view),uf.register(ne,{levelData:r,tile:i,startTime:u,state:this})},v.fadeLevel=function(n){var i=this.levels[n],r=(new t).getTime();i.fading=!0,uf.register(io,{state:this,level:n,startTime:r,levelData:i})},v.initLevelData=function(n){var i=this.levels,t=i[n];return t&&t.visible&&(this.drawer.removeLevel(t.view),t.visible=!1),i[n]=t=new gs(n,this.source),t},v.checkRemoveLevel=function(n){n.tilesVisible<0&&c("coverage is broken"),n.tilesVisible!==0||n.fading||(n.visible=!1,n.view&&(this.drawer.removeLevel(n.view),n.view=null))},v.onUncover=function(n){if(n.uncover()){n.inBounds&&this.levels[n.level].tilesVisible++;if(n.tileBelow)this.onUncover(n.tileBelow)}},v.onCover=function(n){var t;if(n.cover()){t=this.levels[n.level],n.view&&(this.drawer.discardTile(n,t.view),n.view=null);if(n.drawnOpaque)n.drawnOpaque=!1;else if(n.tileBelow)this.onCover(n.tileBelow);t.tilesVisible--,this.checkRemoveLevel(t)}},v.onDrawn=function(n){n.drawn();if(n.tileBelow)this.onCover(n.tileBelow)},v.setLevelClipBounds=function(n,t){var v=n.num,k=this.source,e=n.bounds,o=k.getTilesInRect(v,t),s=n.tiles,f,u,i,r,a=o.x,b=o.y,w=o.height+b,p=o.width+a,d=e.x,g=e.y,tt=d+e.width,nt=g+e.height,l,h,y=n.fading&&this.drawer===yu;if(!s||!e){c("uninitialized level "+v);return}if(o.equals(e))return;for(i=a;i<=p;i++)for(f=s[i],f||(s[i]={},f=s[i]),r=b;r<=w;r++)u=f[r],u||(l=k.getTileBelow(v,i,r),l?(h=this.levels[v-1].tiles[l.x][l.y],h||c("coverage is broken")):h=null,f[r]=new bt(n.num,i,r,k,h),n.tilesVisible++);for(i=d;i<=tt;i++){for(f=s[i],r=g;r<=nt;r++){if(i>=a&&i<=p&&r>=b&&r<=w){r=w;continue}u=f[r],u.view&&!n.fading&&this.drawer.discardTile(u,n.view),u.isCovered()||n.tilesVisible--,u.inBounds=!1;if(u.drawnOpaque)this.onUncover(u.tileBelow);y||delete f[r]}!y&&(i<a||i>p)&&delete s[i]}y||(n.bounds=o),this.checkRemoveLevel(n),n.visible&&!n.fading&&this.drawer.setLevelDimensions(n)},v.drawLevel=function(n,t,i){var v=n.bounds,g=n.num,w=v.x,k=w+v.width,p=v.y,b=p+v.height,s,h,y=this.source,a=this.drawer,d,r,l,u,o;if(n.tilesVisible===0)return;for(n.tilesVisible<0&&c("coverage is broken"),n.visible||(n.visible=!0,n.view=t?a.addLevelBehind(t.view):a.addLevelOnTop(),a.setLevelDimensions(n)),s=w;s<=k;s++)for(h=p;h<=b;h++){if(!y.tileExists(g,s,h))continue;d=new e(s,h),r=n.tiles[s][h];if(r.covers()||r.view||r.loading)continue;l=oh(r.url);if(l.failed)continue;u=r.bounds;if(l.loaded)if(i)this.blendTile(l.img,r);else{r.opacity=1,r.view=a.drawTile(l.img,r,n.view);this.onDrawn(r)}else o=this.position,u=u.intersect(this.clip),u=new f(u.x*o.width+o.x,u.y*o.height/y.normHeight+o.y,u.width*o.width,u.height*o.height/y.normHeight),r.area=u.getArea(),r.distance=u.getCenter().distanceTo(gf),r.loading=!0,fh(r,ro,{levelData:n,state:this})}};var au,ki=o.Image=function(t,i){return vi(this,t),this.state=null,this.lastSrc="",this.container=n.createElement("div"),this.src=i&&i.attributes.src?i.attributes.src.value:this.lastSrc,this.complete=!0,i||(i=rr.call(n,"sdimg")),au(vi(i,this,!0))},lt=ki.prototype,ru=0;typeof devicePixelRatio!="undefined"&&(ru=tt(devicePixelRatio)),ss("sdimg",ki),lt.blendTime=500,lt.fadeTime=500,lt.manualUpdates=!1,lt.clipParent=null,lt.immediateMode=!0,lt.blur=0,(function(){var i,t,f,u="sdimg",r="display:inline-block",e=u+" {"+r+"}";if(n.createStyleSheet)try{t=n.styleSheets.length>0?n.styleSheets[0]:n.createStyleSheet(),t.addRule(u,r,0)}catch(o){w("Error while creating default styles: "+o.message)}else i=n.documentElement.firstChild,t=n.createElement("style"),f=n.createTextNode(e),t.appendChild(f),i.insertBefore(t,i.firstChild)})(),au=function(n){var i=n.container,t=i.style;return i.className="sdimgcontainerdiv",t.textAlign="left",t.overflow="hidden",n.style&&(n.appendChild(i),t.position="relative",t.width=t.height="100%"),n.manualUpdates||(n.timerID=ht.register(lu,n)),n},lt.update=function(n,t){lu(this,null,n,t)},lt.destroy=function(){this.drawer.destroy(),this.timerID&&ht.unregister(this.timerID)},ki.drawImage=function(n,t,i,u,f,e,o,s,h,c){var ft,tt,g,d,rt,b,it,v,vt,ct,yt,ut,at,pt,l,k,a,p,ht,et,st,ot,lt,y=!0,nt;t=t.state;if(!t)return w("Image.drawImage: Image isn't ready yet!"),!1;for(nt=t.maxLevel,f===r?(o=i,s=u,h=t.position.width,c=t.position.height):o===r?(o=i,s=u,h=f,c=e):(n.save(),n.beginPath(),n.rect(o,s,h,c),n.clip(),lt=!0,o-=i*h/f,s-=u*c/e,h*=t.position.width/f,c*=t.position.height/e),ft=t.source.normHeight,tt=t.levels,g=t.source.minLevel;!!(b=tt[g]);g++)if(b.visible){for(v=b.bounds,it=b.opacity,it!==1&&(n.save(),n.globalAlpha*=it,y=!1),ct=v.x,ut=v.y,yt=ct+v.width,at=ut+v.height,vt=b.tiles,d=ct;d<=yt;d++)for(pt=vt[d],rt=ut;rt<=at;rt++)l=pt[rt],l.view?(k=l.opacity,k!==1&&(n.save(),n.globalAlpha*=k,y=!1),a=l.crop,p=l.bounds,ht=o+p.x*h,et=s+p.y*c/ft,st=p.width*h,ot=p.height*c/ft,a?n.drawImage(l.view,a.x,a.y,a.width,a.height,ht,et,st,ot):n.drawImage(l.view,ht,et,st,ot),k!==1&&n.restore()):y=!1;it!==1&&n.restore()}return(nt!==g-1||tt[nt]&&!tt[nt].visible)&&(y=!1),lt&&n.restore(),y},(function(){function p(n){return of(n)}function f(n,t){var r=of(n),i=os(t);return r.minus(i)}function s(t,i){var r=n.body;while(i&&t!==i&&r!==i)try{i=i.parentNode}catch(u){return!1}return t===i}function d(){v=!0}function k(){v=!1}if(o.MouseTracker)return;var u=typeof addEventListener!="function",v=!1,c,r,l,y,e,w=!1,b={},h=[];navigator.msPointerEnabled?(c="MSPointerDown",r="MSPointerUp",l="MSPointerOver",y="MSPointerOut",e="MSPointerMove"):(c="mousedown",r="mouseup",l="mouseover",y="mouseout",e="mousemove"),u?(a(n,c,d,!1),a(n,r,k,!1)):(a(window,c,d,!0),a(window,r,k,!0)),o.MouseTracker=function(o,k){function vt(n,t){var r=b,i;for(i in r)r.hasOwnProperty(i)&&ct!==i&&r[i][n](t)}function ri(){var n;for(n in g)if(g.hasOwnProperty(n)&&g[n])return!0;return!1}function et(n){n=n||window.event,u&&nt&&!s(n.srcElement,o)&&vt("onMouseOver",n);var i=n.target||n.srcElement,r=n.relatedTarget||n.fromElement,t=n.pointerId||0;if(!s(o,i)||s(o,r))return;g[t]=!0,d.trigger("enter",d,t,f(n,o),!!it[t],v)}function ht(n){n=n||window.event,u&&nt&&!s(n.srcElement,o)&&vt("onMouseOut",n);var i=n.target||n.srcElement,r=n.relatedTarget||n.toElement,t=n.pointerId||0;if(!s(o,i)||s(o,r))return;g[t]=!1,d.trigger("exit",d,t,f(n,o),!!it[t],v)}function kt(n){n=n||window.event;if(n.button===2)return;var i=n.pointerId||0;it[i]=!0,g[i]=!0,dt[i]=lt[i]=p(n),bt[i]=(new t).getTime(),d.trigger("press",d,i,f(n,o)),(d.listListeners("press")||d.listListeners("drag"))&&tr(n),u&&w?u&&h.push(ft):(ii(),w=!0,h=[ft])}function ui(i){i=i||window.event;if(i.button===2)return;for(var u=i.pointerId||0,c=(new t).getTime()-bt[u],l=p(i),h=dt[u].distanceTo(l),a=c<=ti&&h<=fi,r=i.target,s=n.body,e=!1,r=i.target;r&&r!==o&&r!==s;r=r.parentNode)ei.hasOwnProperty(r.tagName)&&(e=!0);d.trigger("click",d,u,f(i,o),a,i.shiftKey,e)}function tt(n){n=n||window.event;var t=n.pointerId||0,r=!!it[t],i=!!g[t];if(n.button===2)return;it[t]=!1,d.trigger("release",d,t,f(n,o),r,i),r&&i&&ui(n)}function at(t){t=t||window.event;var i,r;if(t.button===2)return;for(i=0;i<h.length;i++){r=h[i];if(!r.hasMouse())r.onMouseUp(t)}ot(),w=!1,t.srcElement.fireEvent("on"+t.type,n.createEventObject(t)),df(t)}function yt(n){g[n.pointerId||0]||tt(n),ot()}function st(n){n=n||window.event;var r=n.pointerId||0,i=p(n),t=i.minus(lt[r]||i);lt[r]=i,(t.x||t.y)&&d.trigger("drag",d,r,f(n,o),t,n.shiftKey),d.listListeners("drag")&&tr(n)}function pt(n){for(var t=0;t<h.length;t++)h[t].onMouseMove(n);df(n)}function wt(n){n=n||window.event;var t=vs(n);t&&d.trigger("scroll",d,f(n,o),t,n.shiftKey),d.listListeners("scroll")&&tr(n)}function ni(){ut||(a(o,l,et,!1),a(o,y,ht,!1),a(o,c,kt,!1),a(o,r,tt,!1),a(o,"mousewheel",wt,!1),ut=!0,b[ct]=ft)}function gt(){if(ut){rt(o,l,et,!1),rt(o,y,ht,!1),rt(o,c,kt,!1),rt(o,r,tt,!1),rt(o,"mousewheel",wt,!1);while(nt)ot();ut=!1,delete b[ct]}}function ii(){nt||(u?(rt(o,r,tt,!1),a(o,r,at,!0),a(o,e,pt,!0)):(a(window,r,yt,!0),a(window,e,st,!0))),++nt}function ot(){nt===1&&(u?(rt(o,e,pt,!0),rt(o,r,at,!0),a(o,r,tt,!1)):(rt(window,e,st,!0),rt(window,r,yt,!0))),--nt}k=k||{};var d=this,ft,ct=i.random(),ut=!1,nt=0,it={},g={},lt={},bt={},dt={},ei={A:1,INPUT:1,TEXTAREA:1,SELECT:1,OPTION:1,OPTGROUP:1,BUTTON:1,LABEL:1},ti=k.clickTimeThreshold||500,fi=k.clickDistThreshold||5;this.target=o,ft={hasMouse:ri,onMouseOver:et,onMouseOut:ht,onMouseUp:tt,onMouseMove:st},ur.call(this),this.isTracking=function(){return ut},this.setTracking=function(n){n?ni():gt()}}})();var ye=o.MouseTracker,nr=o.Spring=function(n){function v(n){return(1-gr(-n*a))/p}n=n||{};var f=n.initialValue||0,a=n.stiffness||5,p=1-gr(-a),y=n.animationTime||1.5,w=n.decayTime||1,c=f,e=f,u=(new t).getTime(),s=u,h=u,r=0,o=!1,l;this.getCurrent=function(){return f},this.getTarget=function(){return e},this.resetTo=function(n){o=!1,e=n,h=u,c=e,s=h},this.springTo=function(n){o=!1,c=f,s=u,e=n,h=s+1e3*y},this.shiftBy=function(n){c+=n,e+=n},this.toss=function(){l=i.abs(r/(1e3*w)),o=!0},this.grab=function(){o=!1},this.update=function(n){var p=u,y=f,i,a;return u=n||(new t).getTime(),i=u-p,o?(r>0?(r-=l*i,r<0&&(r=0)):r<0&&(r+=l*i,r>0&&(r=0)),f+=r*i,e=f):(f=u>=h?e:c+(e-c)*v((u-s)/(h-s)),i&&(a=gr(-i/40),r=a*r+(1-a)*(f-y)/i)),o}},be=o.SVGZoomContainer=function(n){this.update=function(t){n.setAttribute("viewBox",[t.x,t.y,t.width,t.height].join(" "))}},no=o.HTMLZoomContainer=function(t){var i=n.createElement("div"),f=i.style,u=1,e,o;(function(){var n;f.width="100%",f.height="100%",f.position="relative",t.appendChild(i);while((n=t.firstChild)!==i)i.appendChild(n)})(),this.setSizeRatio=function(n,t){u=n,n=n*100+"%",f.width=n,f.height=n,t&&e!==r&&this.update(e,o)},this.setLocation=function(n,t){var i=n.style;i.left=t.x*u+"px",i.top=t.y*u+"px",i.width=t.width*u+"px",i.height=t.height*u+"px"},this.update=function(n,t){e=n,o=t,rs(i,-n.x*t,-n.y*t,t/u)},this.dispose=function(){var n;t.removeChild(i);while(n=i.firstChild)t.appendChild(n)}},ke=o.CanvasZoomContainer=function(n){var t=n.getContext("2d");this.update=function(i){var u=n.width,f=n.height,r=u/i.width;t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,u,f),t.setTransform(r,0,0,r,-i.x*r,-i.y*r)}},de=o.Viewport=function(n,r,u){function ei(){ur.call(o),o.resizeContent(r),o.goHome(!0),o.update(),ii&&at.register(o.update,yt)}function g(n){return i.pow(2,n)}function ui(n,t){var u=n.x,f=n.y,i=ti(u,t.x,t.x+t.width),r=ti(f,t.y,t.y+t.height);return u===i&&f===r?n:new e(i,r)}function ni(n){var c=o.getWidthZoom(n),e=s/c,h=e/v,r=(o.visibilityRatio-.5)*e,u=(o.visibilityRatio-.5)*h,i=s-2*r,t=w-2*u;return i<0&&(r+=.5*i,i=0),t<0&&(u+=.5*t,t=0),new f(r,u,i,t)}function fi(){var i=y.getCurrent(),r=y.getTarget(),n,t;rt=i,it=r,d=g(i),nt=g(r),pt=d*p,kt=nt*p,n=tt(o.minZoom),t=tt(o.maxZoom),gt=(rt-n)/(t-n)*100,dt=(it-n)/(t-n)*100}function ct(t){var r=new e(c.getCurrent(),a.getCurrent()),y=new e(c.getTarget(),a.getTarget());if(t)return r;if(!l)return y;var p=o.getWidthZoom(),i=s/p,h=i/v,u=new f(r.x-i/2,r.y-h/2,i,h),k=o.pixelFromPoint(l,!0),d=l.minus(u.getTopLeft()).times(n.x/u.width),w=d.minus(k),b=w.divide(n.x/s*p);return y.plus(b)}function lt(n){var r=o.getCenter(n),t=s/o.getWidthZoom(n),i=t/v;return new f(r.x-t/2,r.y-i/2,t,i)}function b(){h=!1,fi(),vt=ct(!0),ot=lt(!0),et=ct(),ut=lt()}function ri(n){return new f(n.x,n.y,n.width,n.height)}function ht(n){return new e(n.x,n.y)}n=new e(n.x,n.y),u=u||{};var o=this,k,w,s,st=u.panSpringOptions||{animationTime:.35},c=new nr(st),a=new nr(st),y=new nr(u.zoomSpringOptions),l=null,ft,v=n.x/n.y,p,bt=u.wrapHorizontal||!1,wt=u.wrapVertical||!1,ii=u.selfUpdating!==!1,yt={},h=!0,d,nt,rt,it,pt,kt,gt,dt,vt,et,ot,ut;this.maxZoom=typeof u.maxZoom=="number"?u.maxZoom:2,this.minZoom=typeof u.minZoom=="number"?u.minZoom:.8,this.visibilityRatio=typeof u.visibilityRatio=="number"?u.visibilityRatio:.8,this.getContainerSize=function(){return ht(n)},this.getBounds=function(n){return h&&b(),ri(n?ot:ut)},this.getCenter=function(n){return h&&b(),ht(n?vt:et)},this.getZoom=function(n){return h&&b(),n?d:nt},this.getExpZoom=function(n){return h&&b(),n?rt:it},this.getWidthZoom=function(n){return h&&b(),n?pt:kt},this.getZoomPercent=function(n){return h&&b(),n?gt:dt},this.applyConstraints=function(n){var h=o.getZoom(),u=ti(h,o.minZoom,o.maxZoom),i,t,r,e;h!==u&&o.zoomTo(u,l,n),u*=p,i=o.getCenter(),t=ui(i,ni()),bt&&(t.x=i.x),wt&&(t.y=i.y),i.equals(t)||(r=s/u,e=r/v,o.fitBounds(new f(t.x-.5*r,t.y-.5*e,r,e),n))},this.fitBounds=function(t,i){var c=v,h=t.getCenter(),r=new f(t.x,t.y,t.width,t.height),l;r.getAspectRatio()<c?(r.width=t.height*c,r.x=h.x-r.width/2):(r.height=t.width/c,r.y=h.y-r.height/2),o.panTo(o.getCenter(!0),!0),o.zoomTo(o.getZoom(!0),null,!0);var u=o.getBounds(),a=o.getWidthZoom(),e=s/r.width;if(e*1.000001>a&&e*.999999<a){o.panTo(h,i);return}l=u.getTopLeft().times(n.x/u.width).minus(r.getTopLeft().times(n.x/r.width)).divide(n.x/u.width-n.x/r.width),o.zoomTo(e/p,l,i)},this.goHome=function(n){var t=o.getCenter();bt&&(t.x=(s+t.x%s)%s,c.resetTo(t.x),c.update()),wt&&(t.y=(w+t.y%w)%w,a.resetTo(t.y),a.update()),o.fitBounds(ft,n)},this.panBy=function(n,t){o.panTo(o.getCenter().plus(n),t)},this.panTo=function(t,i){if(i){c.resetTo(t.x),a.resetTo(t.y),h=!0;return}if(!l){c.springTo(t.x),a.springTo(t.y),h=!0;return}var y=o.getWidthZoom(),r=s/y,p=r/v,u=new f(c.getCurrent()-r/2,a.getCurrent()-p/2,r,p),k=o.pixelFromPoint(l,!0),b=l.minus(u.getTopLeft()).times(n.x/u.width),d=b.minus(k),w=d.divide(n.x/s*y),e=t.minus(w);c.springTo(e.x),a.springTo(e.y),h=!0},this.zoomBy=function(n,t,i){o.zoomTo(o.getZoom()*n,t,i)},this.zoomTo=function(n,t,i){i?y.resetTo(tt(n)):y.springTo(tt(n)),l=t instanceof e?t:null,h=!0},this.toss=function(){c.toss(),a.toss()},this.resize=function(t,i){var u=o.getBounds(),r=u,f=t.x/n.x;n=new e(t.x,t.y),v=n.x/n.y,p=v>k?k/v:1,i&&(r.width=u.width*f,r.height=r.width/v),o.fitBounds(r,!0)},this.resizeContent=function(n){var t;t=o.getBounds(),r=n,k=r.x/r.y,w=r.y,s=r.x,ft=new f(0,0,s,w),p=v>k?k/v:1,h=!0,o.fitBounds(t,!0)},this.zoomToPercent=function(n,t){var i=tt(o.minZoom);o.zoomTo(g(n*(tt(o.maxZoom)-i)/100+i),null,t)},this.update=function(n,i){var w=c.getCurrent(),b=a.getCurrent(),s=y.getCurrent(),f,r,u;i=i||(new t).getTime(),l&&(f=o.pixelFromPoint(l,!0)),y.update(i),h=!0;if(l&&y.getCurrent()!==s){var v=o.pixelFromPoint(l,!0),p=v.minus(f),e=o.deltaPointsFromPixels(p,!0);c.shiftBy(e.x),a.shiftBy(e.y)}else l=null;return r=c.update(i),r=a.update(i)||r,h=!0,r&&o.applyConstraints(),u=c.getCurrent()!==w||a.getCurrent()!==b||y.getCurrent()!==s,u&&o.trigger("change",o),u||n===yt},this.deltaPixelsFromPoints=function(t,i){return t.times(n.x/s*o.getWidthZoom(i))},this.deltaPointsFromPixels=function(t,i){return t.divide(n.x/s*o.getWidthZoom(i))},this.pixelFromPoint=function(t,i){var r=o.getBounds(i);return t.minus(r.getTopLeft()).times(n.x/r.width)},this.pointFromPixel=function(t,i){var r=o.getBounds(i);return t.divide(n.x/r.width).plus(r.getTopLeft())},this.rectPixelsFromPoints=function(t,i,r){var e=o.getBounds(i),u=n.x/e.width;return new f((t.x-e.x)*u-(r?n.x/2:0),(t.y-e.y)*u-(r?n.y/2:0),t.width*u,t.height*u)},ei()},ic=o.Viewer=function(t,u){function d(n,t){var i=n>1;o.zoomBy(n,i&&f.zoomInToPoint||!i&&f.zoomOutToPoint?o.pointFromPixel(t.minus(new e(f.padding.left,f.padding.top)),!0):null),o.applyConstraints()}function it(n){var r,u,i,t=0,s=0,o=0,f=0;for(r in n)if(n.hasOwnProperty(r)){++t,i=n[r],o+=i.x,f+=i.y;for(u in n)n.hasOwnProperty(u)&&u!==r&&(s+=i.distanceTo(n[u]))}return{center:new e(o/t,f/t),size:s/t/(t-1)}}function lt(n,t,i,r,u,e){if(r&&f.isZoomable&&!e){var o=f.zoomPerClick,s=u?1/o:o;d(s,i)}}function vt(n,t,i){l[t]=h[t]=i,++c,p=o.getCenter();if(c>1){var r=it(l);i=r.center,et=i,ut=r.size,ft=o.getZoom(),w=o.pointFromPixel(i.minus(new e(f.padding.left,f.padding.top)),!0)}}function yt(n,t,i){var a,s,b,e,d,nt,tt,g,k,y;h[t]=i,s=-1,c>1?(b=it(h),i=b.center,s=b.size,a=et):a=l[t],f.isZoomable&&s>=0?(e=s/ut,d=e*ft,o.zoomTo(d,r,!0),nt=o.deltaPointsFromPixels(i.minus(a)).times(e),tt=p.minus(nt).minus(w).divide(e).plus(w),o.panTo(tt,!0),o.applyConstraints()):f.isPannable&&(g=i.minus(a),k=o.deltaPointsFromPixels(g.negate(),!0),o.panTo(p.plus(k)),f.constrainDuringPan&&o.applyConstraints(),y=f.dragCursor,ht&&!v&&y&&(v=!0,rt.cursor=y))}function ct(n,t,i,r){if(r){--c,delete h[t],delete l[t];if(c){if(c===1){for(t in h)if(h.hasOwnProperty(t))break;l[t]=h[t],p=o.getCenter(),b=!0}}else f.useMomentum&&!b&&o.toss(),b=!1,o.applyConstraints()}v&&(v=!1,rt.cursor="")}function ot(n,t,r){if(f.isZoomable){var u=i.pow(f.zoomPerScroll,r);d(u,t)}}function st(){f.ignoreChange||f.redraw()}function tt(n,t){return new e(g(n-f.padding.right-f.padding.left,1),g(t-f.padding.top-f.padding.bottom,1))}u=u||{};var o,s,f=this,l={},p,h={},rt=n.documentElement.style,ht=!window.opera,y,a,k=0,v,c=0,et,ut,ft,w,b,nt;f.zoomPerClick=2,f.zoomPerScroll=i.pow(2,1/3),f.zoomInToPoint=!0,f.zoomOutToPoint=!0,f.isPannable=!0,f.isZoomable=!0,f.constrainDuringPan=!1,f.ignoreChange=!1,f.useMomentum=!0,f.dragCursor="move",f.padding={top:0,right:0,bottom:0,left:0},vi(f,u),(function(){var i,n,s,r,h;y=g(t.clientWidth,1),a=g(t.clientHeight,1),i=new e(y,a),n=f.contentSize||i.times(1),f.zoomContainers||(window.SVGSVGElement&&t instanceof SVGSVGElement?(h=nu(t),i=new e(parseFloat(h.width),parseFloat(h.height)),f.contentSize||(n=new e(t.viewBox.baseVal.width,t.viewBox.baseVal.height),n.x===0&&n.y===0&&(n=new e(t.width.baseVal.value,t.height.baseVal.value))),s=new be(t)):window.HTMLCanvasElement&&t instanceof HTMLCanvasElement?(f.contentSize||(n=new e(t.width,t.height)),s=new ke(t)):s=new no(t),f.zoomContainers=[s]),r=tt(i.x,i.y),n.x*=r.x/i.x,n.y*=r.y/i.y,o=new de(r,n,u.viewportOptions),ur.call(f),t.style.msTouchAction="none"})(),s=new ye(t),s.addListener("click",lt),s.addListener("press",vt),s.addListener("drag",yt),s.addListener("release",ct),s.addListener("scroll",ot),s.setTracking(!0),o.addListener("change",st),nt=at.register(function(){k=(k+1)%30;if(k===0){var i=g(t.clientWidth,1),n=g(t.clientHeight,1);(i!==y||n!==a)&&(y=i,a=n,o.resize(tt(i,n),!0),f.trigger("resize",i,n))}return!0}),f.getBounds=function(n){var t=o.getBounds(n),i=o.getContainerSize();return t.x-=t.width*f.padding.left/i.x,t.y-=t.height*f.padding.top/i.y,t.width*=1+(f.padding.left+f.padding.right)/i.x,t.height*=1+(f.padding.top+f.padding.bottom)/i.y,t},f.redraw=function(){for(var i=f.getBounds(!0),r=o.getZoom(!0),t=f.zoomContainers,n=t.length-1;n>=0;n--)t[n].update(i,r)},f.dispose=function(n){at.unregister(nt);if(!n)for(var r=f.zoomContainers,u=r.length,i,t=0;t<u;++t)i=r[t],i.dispose&&i.dispose()},f.redraw(),f.viewport=o,f.tracker=s},hr=window.Pivot={},s={}.hasOwnProperty,u=function(t,i,r){var u=n.createElement(t);return i&&(u.className=i),r&&r.appendChild(u),u},h=function(t,i){t.appendChild(n.createTextNode(i))},ve=1e-5;var er=function(n){return n===1?15:16},ho=["January","February","March","April","May","June","July","August","September","October","November","December"],eo=-9,vf=function(n,t){var r,e,o,u,f;r=t.getFullYear()-n.getFullYear();if(r)return i.floor(i.log(r)/i.LN10);u=t.getMonth();if(u>n.getMonth())return-1;e=t.getDate(),o=n.getDate(),f=er(u);if(o<f&&e>=f)return-2;if(e>o)return-3;r=t.getHours()-n.getHours();if(r>=12)return-4;if(r)return-5;r=t.getMinutes()-n.getMinutes();if(r>=15)return-6;if(r)return-7;return r=t.getSeconds()-n.getSeconds(),r>=5?-8:-9},br=function(n,u,f){function w(n,t,i){t&&(n=t+" to "+i,b.leftLabel=t,b.rightLabel=i),b.label=n}if(!(n<=u)||f<eo)return[];f===r&&(f=vf(n,u)),f<0||(f=i.pow(10,f));var e=n.getFullYear(),s=0,o=1,l=0,v=0,p=0,tt=0,g,h,nt,d,c,a,b,y,k;switch(f){case-9:case-8:p=n.getSeconds();case-7:case-6:v=n.getMinutes();case-5:case-4:l=n.getHours();case-3:case-2:o=n.getDate();case-1:s=n.getMonth();break;default:e=i.floor(e/f)*f}switch(f){case-8:p=i.floor(p/5)*5;break;case-6:v=i.floor(v/15)*15;break;case-4:l=i.floor(l/12)*12;break;case-2:g=er(s),o=o>=g?g:1}n=new t(e,s,o,l,v,p,tt);switch(f){case-9:h=function(n){return new t(e,s,o,l,v,p+n,0)};break;case-8:h=function(n){return new t(e,s,o,l,v,p+n*5,0)};break;case-7:h=function(n){return new t(e,s,o,l,v+n,0,0)};break;case-6:h=function(n){return new t(e,s,o,l,v+n*15,0,0)};break;case-5:h=function(n){return new t(e,s,o,l+n,0,0,0)};break;case-4:h=function(n){return new t(e,s,o,l+n*12,0,0,0)};break;case-3:h=function(n){return new t(e,s,o+n,0,0,0,0)};break;case-2:h=function(n){o>1&&n++;var r=new t(e,s+i.floor(n/2),1,0,0,0,0);return n%2&&r.setDate(er(r.getMonth())),r};break;case-1:h=function(n){return new t(e,s+n,1,0,0,0,0)};break;default:h=function(n){return new t(e+n*f,0,1,0,0,0,0)}}switch(f){case-9:case-8:case-7:case-6:case-5:case-4:y=function(){var i=c.getDate(),t,n;k===i?t="":(t=c.toLocaleDateString()+" ",k=i),t+=c.toLocaleTimeString(),n=k===a.getDate()?"":a.toLocaleDateString()+" ",n+=a.toLocaleTimeString(),w(r,t,n)};break;case-3:y=function(){w(c.toLocaleDateString())};break;case-2:y=function(){w(r,c.toLocaleDateString(),a.toLocaleDateString())};break;case-1:y=function(){var n=c.getFullYear(),t=ho[c.getMonth()];k!==n&&(k=n,t+=" "+n),w(t)};break;case 1:y=function(){w(c.getFullYear())};break;default:y=function(){w(i.floor(c.getFullYear()/f)*f+"s")}}nt=[],d=0,a=n;do d++,c=a,a=h(d),b={lowerBound:c,upperBound:a,items:[]},y(),nt.push(b);while(a<=u);return nt},fo=function(n,t,i,f){function b(n){var t=n.target;t.checked?(f.push(t.filterInfo),s.trigger("filter",i,f)):(f.splice(f.indexOf(t.filterInfo),1),s.trigger("filter",i,f.length?f:r))}function k(n){var t=n.target.filterInfo;f.forEach(function(n){n.checkBox.checked=!1}),t.checkBox.checked=!0,f=[t],s.trigger("filter",i,f)}function p(n){var r,t,i,o,e;r=u("li",null,l),t=u("input","pivot pivot_facetcheckbox",r),t.setAttribute("type","checkbox"),f&&f.some(function(t,i){return t.lowerBound.getTime()===n.lowerBound.getTime()&&t.upperBound.getTime()===n.upperBound.getTime()?(f[i]=n,!0):!1})&&(t.checked=!0),n.checkBox=t,t.onclick=b,i=u("div","pivot_outerlabel",r),i.onclick=k,o=u("div","pivot_facetcount",i),h(o,n.count),e=u("div","pivot_facetlabel",i),h(e,n.label),r.title=n.label,e.filterInfo=o.filterInfo=t.filterInfo=i.filterInfo=n}var e=Infinity,o=-Infinity,v,w,s=this,y,c,a,l;f=f||[],Seadragon2.EventManager.call(s),t.forEach(function(n){var t=n.facets[i];t&&t.forEach(function(n){n>o&&(o=n),n<e&&(e=n)})});if(e===Infinity)return w=u("div","pivot_numberlabel",n),h(w,"Not Currently Applicable"),this;v=vf(e,o),y=br(e,o,v),c=br(e,o,v-1),a=y.concat(c),a.forEach(function(n){n.count=0}),t.forEach(function(n){var t=n.facets[i];t&&t.forEach(function(n){a.forEach(function(t){n>=t.lowerBound&&n<t.upperBound&&t.count++})})}),l=u("ul","pivot",n),y.forEach(p),u("li","pivot_horizbar",l),c.forEach(p)};ir=/<\?(?:\??[^>]+)*\?>/g,yt=function(n,i,r){var f,s=n.template,h=[],a,v=0,y,matchString,l,evalResult,o=n.type,e,c;(o==="html"||o==="fakehtml")&&(r?(r.innerHTML="",f=r):f=u("div","pivot_item"),f.style.width=n.width+"px",f.style.height=(n.height||n.width)+"px");if(o==="canvas")f=typeof s=="function"?s:new Function("ctx","x","y","w","h","item",s);else{while(!!(matchString=ir.exec(s))){matchString=matchString[0],y=ir.lastIndex,l=matchString.length,h.push(s.substring(v,y-l)),matchString=matchString.substring(2,l-2);try{(function(){with(i)evalResult=eval(matchString)})(),typeof evalResult=="number"?evalResult=b(evalResult):evalResult instanceof t&&(evalResult=evalResult.toLocaleString()),h.push(evalResult)}catch(p){Seadragon2.Debug.warn("Error caught in filling template: "+p.message||p)}v=y}h.push(s.substring(v,s.length)),a=h.join(""),o==="html"||o==="fakehtml"?f.unsetHTML=h.join(""):o==="color"?f=function(n,t,i,r,u){return n.fillStyle=a,n.fillRect(t,i,r,u),!0}:o==="img"&&(e=u("img"),e.onload=function(){c=!0},e.unsetSrc=a,f=function(n,t,i,r,u){var f=e.unsetSrc;return f&&(e.src=e.unsetSrc,delete e.unsetSrc),c&&n.drawImage(e,t,i,r,u),c})}return f};var re=hr.PivotViewer=function(f,e,o,c,l,a,v){function ef(){ai={},d=[],rt.forEach(function(n){ii.every(function(t){return t(n)})&&(ai[n.id]=n,d.push(n))})}function ti(n,t){if(!t||t<0)if(kt){var i=kt;kt=function(){i(),n()}}else kt=n;else ti(function(){ti(n,t-1)})}function wu(n){for(var u=k.getContainerSize(),s=u.times(.5),t,e=u.x+u.y,f=[],o=n.length,r,i=0;i<o;i++)r=n[i],t=r.getCenter().minus(s),t=t.times(e/t.distanceTo(du)),f.push(new Seadragon2.Rect(t.x-100,t.y-100,r.width*1.2,r.height*1.2));return f}function di(n){var t=n.unsetHTML;t&&(n.innerHTML=t,delete n.unsetHTML),o.appendChild(n)}function bi(n){var t=n.cloneNode(!0);return t.unsetHTML=n.unsetHTML,t}function cr(n){for(var h=!1,o=n.source,v=n.destination,a=o.length,l=n.startTime=[],f=n.id,e=k.getContainerSize(),y=e.x/2,c=e.y/2,t,u=n.sdimg[p],r=0;r<a;r++)t=v[r],o[r].equals(t)||(h=!0,l[r]=i.random()*300+lr,s.call(tr,f)||ot.push(n),tr[f]=n,u&&u.update(new Seadragon2.Rect(t.x-y,t.y-c,t.width,t.height)));return h}function ir(){for(var t,e,f,h,i,c,s,n,u=ot.length-1;u>=0;u--){for(h={},t=ot[u],c=t.source=[],s=t.destination,t.destination=r,n=s.length,i=0;i<n;i++)e=s[i],f=e.toString(),h.hasOwnProperty(f)||(h[f]=!0,c.push(e));n=c.length,t.html.forEach(function(t,i){if(w[i].type==="html"){var r=t.splice(n,t.length-n);i===p&&r.forEach(function(n){o.removeChild(n),n.pvInDom=!1})}})}tr={},ot=[]}function rr(n,t){af(n,vt*t.x,vt*t.y,t.width/ur*vt)}function hr(){y.removeListener("animationfinish",hr),et.setTracking(!0),ar=!1,ir(),y.trigger("finishedRearrange"),rt.length||d.length||y.trigger("itemsCleared")}function sr(){y.removeListener("animationfinish",sr),ir();for(var i,r=!1,n,t=d.length-1;t>=0;t--)n=d[t],i=n.id,s.call(pt,i)||(n.source=wu(n.destination),cr(n),ht[i]=n,r=!0,n.html.forEach(function(t,i){if(w[i].type==="html")for(var r=n.source.length-1;r>0;r--)t.push(bi(t[0]))}),w[p].type==="html"&&n.html[p].forEach(function(t,i){rr(t,n.source[i]),di(t),t.pvInDom=!0}));r?y.addListener("animationfinish",hr):hr()}function or(){y.removeListener("animationfinish",or);var u,r,c=!1,i,f,h,e,n,t;if(w[p].type==="html")for(n=ot.length-1;n>=0;n--)t=ot[n].html[p],t.forEach(function(n){o.removeChild(n),n.pvInDom=!1}),t.splice(1,t.length-1);ir(),ei&&w.length&&fr(1);for(u in pt)if(s.call(pt,u)&&s.call(ai,u)){for(r=pt[u],i=r.source,f=r.destination,h=i.length,e=f.length,t=r.html,n=h;n<e;n++)i.push(i[0]),t.forEach(function(n,t){if(w[t].type==="html"){var u=n[0],r=bi(u);n.push(r),t===p&&(rr(r,i[0]),di(r),r.pvInDom=!0)}});for(n=e;n<h;n++)f.push(f[0]);cr(r)&&(c=!0)}c?y.addListener("animationfinish",sr):sr()}function cf(){var n,t,i=!1;for(n in pt)s.call(pt,n)&&!s.call(ai,n)&&(i=!0,t=pt[n],t.destination=wu(t.source),cr(t),delete ht[n]);i?y.addListener("animationfinish",or):or()}function pu(n,t,r,u,f,e,o){var et=r.length,tt=0,ut,p=[],h=[],b,l,c,v,y,k,nt,w,s,g,a,d,it,rt,ft;for(o&&(n-=e),ut=0;tt<et;ut++){for(k=i.max(f,e)*fi/(1+2*fi),nt=e-k*2,w=f-k*2,b=[],c=0;c<u&&tt<et;c++)v=r[tt],v.normHeight>nt/w?(y=nt/v.normHeight,l=new Seadragon2.Rect(t+(c+.5)*f-y/2,n+k,y,nt)):(y=w*v.normHeight,l=new Seadragon2.Rect(t+c*f+k,n+.5*e-y/2,w,y)),v.destination.push(l),a={item:v,index:v.destination.length-1},b.push(a),tt++,s=b[c-1]||!o&&h[h.length-1],s&&(l.left=s,s.item.destination[s.index].right=a),g=o?p:h,d=o?-1:0,s=g[c+d],s&&(l.up=s,s.item.destination[s.index].down=a),g=o?h:p,d=o?0:1,s=g[c+d],s&&(l.down=s,s.item.destination[s.index].up=a);o&&(s=h[0],s&&(l.right=s,s.item.destination[s.index].left=a)),l.down||(rt=a),ut||(p=b),h=b,n+=o?-e:e}return ft=o?h[0]:p[0],o?(s=p[p.length-1],rt=s,it=s):it=h[h.length-1],{topLeft:ft,lowest:rt,rightmost:it,itemWidth:w}}function hf(n){var r=i.floor(i.log(n)/i.LN10),t=n*i.pow(10,-r),u=t<2.5?1:t<5?2.5:5;return u*i.pow(10,r)}function sf(){var t=rt.reduce(function(n,t){var r=t.normHeight;return r||(r=t.normHeight=t.sdimg[-1].state.source.normHeight),n+i.log(r)},1),n=i.exp(t/rt.length);return n=n<1?(n+2*fi)/(1+2*fi):(1+2*fi)/(1/n+2*fi)}function uu(n,t,r,u){var f=i.ceil(i.sqrt(u*t*n/r));while(i.ceil(n/f)*t/f*u>r)f++;return f}function ou(){var n;n=bt.parentNode,n&&n.removeChild(bt),n=ri.parentNode,n&&n.removeChild(ri)}function fr(n,t){var u,i,r,f,e;if(w.length){u=p,p=0;while(w[p]&&w[p].width<ei*n)p++;p>w.length-1&&(p=w.length-1);if(p!==u){ur=w[p].width,ou();if(w[u].type==="html")for(i in ht)s.call(ht,i)&&(r=ht[i],f=r.html[u],f.forEach(function(n,t){n.pvInDom&&(n.pvInDom=!1,of&&(f[t]=bi(n)))}));o.innerHTML=""}e=vt,vt=ur/ei;if(e!==vt){vr.setSizeRatio(vt,!t);if(w[p].type==="html")for(i in ht)s.call(ht,i)&&(r=ht[i],r.html[p].forEach(function(n,i){var f=r.source[i];rr(n,f),p!==u&&(!t||nu(t,f))&&(di(n),n.pvInDom=!0)}))}}}function iu(){var bt,e,ri,yt,t,st,vt,oi,et,s,wt,f,v,fi,ot,rt,ti,nt,ui;y.removeListener("animationfinish",iu),y.trigger("hideDetails"),y.trigger("hideInfoButton"),ar=!0,ut=!0,ir(),pt=Seadragon2.Object.clone(ht),ef(),c.innerHTML="";for(var tt=sf(),ni=it[ct]||{},a,l,b,g,kt=k.getContainerSize(),o=new Seadragon2.Rect(0,0,kt.x,kt.y),n=d.length-1;n>=0;n--)d[n].destination=[];if(dt)a=d,a.sort(function(n,t){n=n.facets[ct],t=t.facets[ct];if(!n)return t?1:0;if(!t)return-1;n=n[0],t=t[0];var i=ni.comparator||hi[ni.type];return i(n,t)}),g=a.length,l=uu(g,o.width,o.height,tt),b=o.width/l,l>g&&(b=i.min(o.width/g,o.height/tt)),bt=pu(0,0,a,l,b,b*tt),ei=bt.itemWidth,vi=bt.topLeft,ki=bt.rightmost;else{for(a=lt[ni.type||"String"](ct),e=o.width/a.length,ri=e*.86,at=[],vi=ki=r,yt=0,n=0;n<a.length;n++)t=a[n],t.items.length>yt&&(yt=t.items.length);for(st=100/e,pr.setSizeRatio(st),ft.style.height=st*o.height+"px",35/st>70?(vt=i.max(5,i.round(70*st)),ft.firstChild.style.bottom=vt+7+"px",ft.lastChild.style.height=vt+"px",ft.style.fontSize=vt/2+"px",o.height-=(vt+13)/100*e):(ft.firstChild.style.bottom="",ft.lastChild.style.height="",ft.style.fontSize="",o.height-=.48*e),oi=o.height-.06*e,l=uu(yt,ri,oi,tt),b=ri/l,n=0;n<a.length;n++){fi=e*(n+.07),t=a[n],g=t.items.length,ot=bi(ft),ot.style.left=100*n+1+"px";var si=ot.firstChild,ii=si.firstChild,gt=si.nextSibling;c.appendChild(ot),t.leftLabel?(rt=u("div","pivot_leftlabel",gt),h(rt,t.leftLabel),et?(et.parentNode.removeChild(et),rt.style.left=-rt.offsetWidth/2+"px",rt.style.textAlign="center"):rt.style.width="50%",ti=u("div","pivot_rightlabel",gt),h(ti,t.rightLabel),et=ti):(h(gt,t.label),et=r),g<l&&g>0&&(nt=86*g/l,fi=e*n+(100-nt)/2*e/100,nt+=4,nt=i.round(nt/2)*2,ii.style.width=nt+"px",ii.style.left=(98-nt)/2+"px"),s=pu(o.height,fi,t.items,l,b,b*tt,!0),ei=s.itemWidth,vi||(vi=s.topLeft),s.rightmost&&(ki=s.rightmost),wt&&(f=wt.lowest,v=s.topLeft,f&&v&&(f.item.destination[f.index].down=v,v.item.destination[v.index].up=f),f&&!s.lowest&&(s.lowest=f),f=wt.rightmost,f&&v&&(f.item.destination[f.index].right=v,v.item.destination[v.index].left=f),f&&!s.rightmost&&(s.rightmost=f)),wt=s,ii.style.height=i.round(100*i.ceil(t.items.length/l)*b*tt/e+4)+"px";switch(it[ct].type){case"String":case"Link":ui=t.values;break;case"Number":case"DateTime":ui=[{lowerBound:t.lowerBound,upperBound:t.upperBound,inclusive:t.inclusive}];break;default:Seadragon2.Debug.warn("Unrecognized category type: "+it[ct].type)}at.push({bar:ot,values:ui,min:e*n,name:t.label,count:g})}}p===-1&&ei&&w.length&&fr(1),k.maxZoom=kt.x/b*2,cf()}function wi(){et.setTracking(!1),k.goHome(),nt=r,ou(),gi=!0,e.title="",y.clearListeners("animationfinish"),y.addListener("animationfinish",iu)}function nu(n,t){return t.x+t.width>n.x&&n.x+n.width>t.x&&t.y+t.height>n.y&&n.y+n.height>t.y}function eu(n,t,i,r,u,f){var o,e;n?(o=n.source[t],w[p].type!=="html"?(r.lineWidth=f,r.strokeStyle=i,r.strokeRect(o.x,o.y,o.width,o.height)):(e=n.html[p][t],e.appendChild(u),f=f*vt+"px",u.pvtop.style.height=u.pvright.style.width=u.pvbottom.style.height=u.pvleft.style.width=f)):p!==-1&&(e=u.parentNode,e&&e.removeChild(u))}function yr(n,t,i,r,u,f){n.save();var e;try{e=f.canvas[p](n,t,i,r,u,f)}catch(o){}return n.restore(),e}function pf(n,u){var ei=k.getContainerSize(),hr,h,f,ft,rt,cr,l,ct,yt,bi,b,lt,ht,vr,ir,oi,si,fi,ti,v,vt,wi,ur,pt,ii,ki,sr,c,gt,er,dr,hi,vi,pi,or,ai;lr=u||(new t).getTime(),kt&&(cr=kt,kt=r,cr());if(ar){y.redraw(),l=w[p].type,ct=l==="sdimg"||l==="fakehtml",yt=l==="html",bi=l==="canvas"||l==="color"||l==="img",ir=!0;if(ct||bi)for(rt=d.length-1;rt>=0;rt--){h=d[rt],hr=h.id;if(!s.call(tr,hr)){ht=h.source;if(ht)for(ft=h.sdimg[p],f=ht.length-1;f>=0;f--)v=ht[f],ct&&ft?kr(wt,ft,v.x,v.y,v.width,v.height):yr(wt,v.x,v.y,v.width,v.height,h)}}for(rt=ot.length-1;rt>=0;rt--)for(h=ot[rt],ht=h.source,vr=h.destination,ur=h.startTime,ft=h.sdimg[p],f=ht.length-1;f>=0;f--)v=ht[f],vt=vr[f],wi=ur[f],b=wi===r?1:i.max((lr-wi)/700,0),b<1?(ir=!1,b=b<.5?(i.exp(b*gr)-1)*vu:1-(i.exp((1-b)*gr)-1)*vu,lt=1-b):(b=1,lt=0),oi=v.x*lt+vt.x*b,si=v.y*lt+vt.y*b,fi=v.width*lt+vt.width*b,ti=v.height*lt+vt.height*b,ct&&ft?kr(wt,ft,oi,si,fi,ti):yt?rr(h.html[p][f],new Seadragon2.Rect(oi,si,fi,ti)):yr(wt,oi,si,fi,ti,h);ir&&y.trigger("animationfinish",y)}else{pt=k.update(),!gi&&pt&&y.trigger("animationstart",y),ut=ut||pt;if(ut){ut=!1,tt=r,ii=g,g=r,hi=Infinity,ki=y.getBounds(!0),fr(k.getZoom(!0),ki),l=w[p].type,ct=l==="sdimg"||l==="fakehtml",yt=l==="html",bi=l==="canvas"||l==="color"||l==="img",y.redraw(),sr=y.getBounds(),er=k.getZoomPercent(),y.trigger("zoom",er),ci&&(pi=k.pointFromPixel(ci.minus(new Seadragon2.Point(y.padding.left,y.padding.top)),!0));if(!dt){if(ci)for(or=at.length,f=0;f<or;f++)if(at[f].min>pi.x)break;else g=at[f];g&&!g.count&&(g=r),g!==ii&&(g?(g.bar.className="pivot_bar pivot_highlight",e.title=g.name):e.title="",ii&&(ii.bar.className="pivot_bar"))}var br=(ei.x-a)*.5,pr=ei.y*.5,yi,wr=new Seadragon2.Point(-a/2,0),et;for(ni=r,nr=!1,rt=d.length-1;rt>=0;rt--)for(h=d[rt],yi=h.source,ft=h.sdimg[p],f=yi.length-1;f>=0;f--)c=yi[f],c&&(nu(ki,c)?(nu(sr,c)&&(gt=k.rectPixelsFromPoints(c,!1,!0),ct&&ft&&ft.update(gt),(gt.width>br||gt.height>pr)&&(nr=!0),vi=gt.getCenter().distanceTo(wr),vi<hi&&(hi=vi,ni=h,au=f,dr=c)),ct&&ft?ut=!kr(wt,ft,c.x,c.y,c.width,c.height)||ut:yt?(et=h.html[p][f],et.pvInDom||(di(et),et.pvInDom=!0)):ut=!yr(wt,c.x,c.y,c.width,c.height,h)||ut,ci&&c.contains(pi)&&(tt=h,st=f)):yt&&(et=h.html[p][f],et.pvInDom&&(o.removeChild(et),et.pvInDom=!1)));ai=k.deltaPointsFromPixels(new Seadragon2.Point(3,0)).x,eu(tt,st,cu,wt,bt,ai),ni&&nr?(ui?y.trigger("showDetails",ni,it):y.trigger("showInfoButton"),k.visibilityRatio=(ei.x-a)/ei.x):(ui?y.trigger("hideDetails"):y.trigger("hideInfoButton"),k.visibilityRatio=1),eu(nt,li,su,wt,ri,ai)}gi&&!pt&&y.trigger("animationfinish",y),gi=pt}return!0}function wf(){ci=r,ut=!0}function yf(n){n=n||window.event,ci=Seadragon2.Mouse.getPosition(n).minus(Seadragon2.Element.getPosition(e)),ut=!0}function pi(n,u,f,e,o,s){var ft=(new t).getTime(),h,c,l,w,v,ut;if(f){f=k.pointFromPixel(f.minus(new Seadragon2.Point(y.padding.left,y.padding.top)),!0);if(!dt){for(ut=at.length,c=0;c<ut;c++)if(at[c].min>f.x)break;else g=at[c];g&&!g.count&&(g=r)}for(l=d.length-1;l>=0;l--)for(v=d[l],w=v.source,c=w.length-1;c>=0;c--)h=w[c],h&&h.contains(f)&&(tt=v,st=c)}if(!s&&e&&ft-lu>lf){if(tt&&(nt!==tt||li!==st)){nt=tt,li=st,h=tt.source[st];var et=k.getContainerSize(),b=et.x,ot=et.y,p,rt=ui?b-a:b;p=i.max((rt/h.width*h.height/ot*1.4-1)/2,.2),h=new Seadragon2.Rect(h.x-h.width*p,h.y,h.width*(1+2*p)*b/rt,h.height),k.fitBounds(h)}else!tt&&g?y.trigger("filterrequest",{facet:ct,values:g.values,type:it[ct].type}):(nt=r,k.goHome());lu=ft}}function vf(){v.focus()}function ku(){var t=n.documentElement;dr=!1,t.className=t.className.replace(" pivot_move","")}function bu(){dr||(dr=!0,n.documentElement.className+=" pivot_move"),nt=r}function gu(){nt=r,v.focus()}function wr(n){var u=n.keyCode,i,t;if(u>=37&&u<=40){if(k.getZoomPercent()){i=ni.source[au];switch(u){case 37:t=i.left;break;case 38:t=i.up;break;case 39:t=i.right;break;case 40:t=i.down}}else switch(u){case 37:case 38:t=ki;break;case 39:case 40:t=vi}t&&(nt!==t.item||li!==t.index)&&(tt=t.item,st=t.index,pi(r,0,r,!0)),n.preventDefault&&n.preventDefault()}}function nf(n,t){ti(function(){f.width=n,f.height=t}),k.resizeContent(k.getContainerSize()),k.update(),wi()}function tu(n){for(var r=u("div"),e,f,o=["top","right","bottom","left"],t,i=0;i<4;i++)for(e=r["pv"+o[i]]=u("div",n,r),f=e.style,t=0;t<4;t++)i!==t&&(f[o[t]]="-1px");return r}function ff(){pr=new Seadragon2.HTMLZoomContainer(c),vr=new Seadragon2.HTMLZoomContainer(o),Seadragon2.Viewer.call(y,e,{constrainDuringPan:!0,ignoreChange:!0,viewportOptions:{minZoom:1,visibilityRatio:1,selfUpdating:!1},padding:{top:5,right:5,bottom:5,left:l+5},dragCursor:"",zoomContainers:[pr,new Seadragon2.CanvasZoomContainer(f),vr]}),c=c.firstChild,o=o.firstChild,et=y.tracker,k=y.viewport,et.clearListeners("click"),et.addListener("exit",wf),Seadragon2.Event.add(e,"mousemove",yf,!1),et.addListener("click",pi),et.addListener("press",vf),et.addListener("release",ku),et.addListener("drag",bu),et.addListener("scroll",gu),v.addEventListener("keydown",wr,!1),y.addListener("resize",nf),Seadragon2.Timer.register(pf),ft=u("div","pivot_bar");var n;n=u("div","pivot_outerbar",ft),u("div","pivot_innerbar",n),u("div","pivot_barlabel",ft),bt=tu("pivot_hoverborder"),ri=tu("pivot_selectedborder"),o.appendChild(bt),o.appendChild(ri),cu=Seadragon2.Element.getStyle(bt.pvtop).backgroundColor,su=Seadragon2.Element.getStyle(ri.pvtop).backgroundColor,o.removeChild(bt),o.removeChild(ri)}function ru(){var t,n;for(t in si)s.call(si,t)&&(n=si[t],(function(){var u=parseInt(t,10),r=n.level,f=n.items;Seadragon2.Xml.fetch(n.url,function(){var e,n,t;try{e=JSON.parse(this.responseText)}catch(a){Seadragon2.Debug.warn("Error in parsing JSON from content endpoint");return}if(e.ready){delete si[u],yi--,r===p.toString()&&(ut=!0),n=e.dzi,t=n.url,t=t.substr(0,t.length-4)+"_files/";var h=n.width,s=n.height,o=n.tileSize,l=n.tileFormat,c=i.min(i.log(o)/i.LN2,i.ceil(i.log(i.max(h,s))/i.LN2));f.forEach(function(n,i){var u=n.sdimg[r]=new Seadragon2.Image(yu);u.src=new Seadragon2.DzcTileSource(h,s,o,c,i,t,l,i),u.update()})}e.failed&&(delete si[u],yi--)},function(){Seadragon2.Debug.warn("Received failure code from server-side renderer")})})());yi&&ti(ru,60)}function tf(){var o,t,e,u,f,h=[].reduce,i;u={href:location.href,style:h.call(n.styleSheets,function(n,t){return n+h.call(t.cssRules,function(n,t){return n+t.cssText},"")},"")};for(t in oi)s.call(oi,t)&&(e=oi[t],i=w[t],o=i.renderer+"pivot/",u.width=i.width,u.height=i.height||i.width,u.items=e.map(function(n){return n.html[t][0].innerHTML}),f=JSON.stringify(u),f=ue(f),(function(){var u=t,r=i.renderer,n=e;Seadragon2.Xml.fetch(o,function(){var t;try{t=JSON.parse(this.responseText)}catch(i){Seadragon2.Debug.warn("Failed to parse JSON response from server.");return}si[uf++]={level:u,url:r+"content/"+t.id,items:n},yi++,yi===1&&ti(ru,60)},function(){Seadragon2.Debug.warn("Failed to post collection data. Status text: "+this.statusText+"; response: "+this.responseText)},f)})());oi={},er=r}function rf(n){var f=n.html,i=n.html=[],h=n.canvas,u=n.canvas=[],o=n.sdimg,t=n.sdimg=[],l,s,c=!f,e;o&&(t[-1]=o[-1]),w.forEach(function(e,a){switch(e.type){case"canvas":i.push([]),u.push(e.func),t.push(r);break;case"img":case"color":i.push([]),u.push(yt(e,n)),t.push(r);break;case"sdimg":i.push([]),u.push(r),t.push(t[-1]);break;case"fakehtml":c?(l=e.renderer,s=oi[a]=oi[a]||[],s.push(n),er===r&&(er=!0,ti(tf)),i.push([yt(e,n)]),u.push(yt(e.fallback||{type:"color",template:"gray"},n)),t.push(r)):(i.push(f[a]),u.push(h[a]),t.push(o[a]));break;case"html":f?(i.push(f[a]),f[a].forEach(function(t){yt(e,n,t)})):i.push([yt(e,n)]),u.push(r),t.push(r);break;default:Seadragon2.Debug.warn("updateTemplate: unrecognized template type")}}),w.length&&(e=w[w.length-1],n.normHeight=(e.height||e.width)/e.width)}function hu(n,t){s.call(n,t)?n[t]++:n[t]=1}var it={},rt=[],ct="",y=this,et,k,gi=!1,ar=!1,ai={},pt={},tr={},ht={},gt={},d=[],ot=[],dt=!0,lr=(new t).getTime(),gr=8,vu=1/(2*(i.exp(gr/2)-1)),wt=f.getContext("2d"),ii=[],ci,tt,st,nt,li,ni,au,vi,ki,nr,g,ft,at=[],pr,vr,dr,fi=.05,ui=!0,du=new Seadragon2.Point(0,0),kr=Seadragon2.Image.drawImage,af=Seadragon2.Element.transform,ut=!0,lu=0,lf=300,w=[],hi,lt,fu;w[-1]={type:"sdimg"};var p=-1,ur,vt,ei,kt,bt,ri,cu,su,yu={manualUpdates:!0},of=function(){var t=u("div"),n=u("div");return n.innerHTML="a",t.appendChild(n),t.innerHTML="",!n.firstChild}(),oi={},er,si={},yi=0,uf=0;hi={Number:function(n,t){return n-t},String:function(n,t){return n>t?1:n===t?0:-1},Link:function(n,t){return n=n.content,t=t.content,n>t?1:n===t?0:-1}},hi.DateTime=hi.Number,hi.LongString=hi.String,lt={String:function(n){function w(n){n=n.content||n,c=e[n],c||(c=e[n]={}),c[b]=h}for(var h,e={},b,a,c,t=[],u,v,r,l,p,y,f,o=d.length-1;o>=0;o--)h=d[o],b=h.id,a=h.facets[n],a?a.forEach(w):w("(no info)");for(u in e)s.call(e,u)&&t.push({label:u,items:e[u],values:[u]});return v=it[n].comparator||function(n,t){return n>t?1:n===t?0:-1},t.sort(function(n,t){var i=v(n.label,t.label);return i?i>0&&t.label!=="(no info)"||n.label==="(no info)"?1:-1:0}),r=i.ceil(t.length/12),r>1&&(l=[],t.forEach(function(n,i){if(i%r==0||n.label==="(no info)")f={label:n.label},l.push(f),p=f.values=n.values,y=f.items=n.items;else{p.push(n.values[0]);var u,e=n.items;for(u in e)s.call(e,u)&&(y[u]=e[u]);(i%r==r-1||i===t.length-1||t[i+1].label==="(no info)")&&(f.label+=" to "+n.label)}}),t=l),t.forEach(function(n){var r=[],t,i=n.items;for(t in i)s.call(i,t)&&r.push(i[t]);n.items=r}),t},Number:function(n,t){function k(n){n>c&&(c=n),n<e&&(e=n)}for(var o,h,c=-Infinity,e=Infinity,u=[],f,w,v,s,l,a,y,p,r=d.length-1;r>=0;r--)o=d[r],h=o.facets[n],h?h.forEach(k):w=!0;if(t)u=br(e,c);else for(f=hf((c-e)/4),f&&(e=f*i.floor(e/f)),r=e;r<c||f===0&&!u.length;r+=f)l=r+f,a=b(r),y=b(l),u.push({label:a+" to "+y,lowerBound:r,upperBound:l,leftLabel:a,rightLabel:y,items:[]});for(u.length&&(s=u.length-1,u[s].inclusive=!0),w&&(v=[],u.push({label:"(no info)",items:v})),p=t?function(n){for(var i,t=0;t<=s;t++){i=u[t];if(n<i.upperBound||t===s){i.items.push(o);break}}}:function(n){var t=i.floor((n-e)/f);(isNaN(t)||t<0)&&(t=0),t>s&&(t=s),u[t].items.push(o)},r=d.length-1;r>=0;r--)o=d[r],h=o.facets[n],h?h.forEach(p):v.push(o);return u}},lt.LongString=lt.String,lt.Link=lt.String,lt.DateTime=function(n){return lt.Number(n,!0)},fu=function(){var n=0;return function(){var t;do t=(n++).toString();while(s.call(gt,t));return t}}(),this.zoomToPercent=function(n){k.zoomToPercent(n),k.applyConstraints()},this.moveLeft=function(){wr({keyCode:37})},this.moveRight=function(){wr({keyCode:39})},this.setCenterItem=function(n){if(!s.call(gt,n))throw"setCenterItem: No matching ID found: "+n;if(!et.isTracking())throw"setCenterItem: Can't execute during rearrange.";if(!s.call(ai,n))throw"setCenterItem: Item is currently not filtered in.";var t=gt[n];t!==nt&&(tt=t,st=0,pi(r,0,r,!0))},this.collapseDetails=function(){ui=!1,nt&&(tt=nt,st=li,nt=r,pi(r,0,r,!0)),y.trigger("hideDetails"),y.trigger("showInfoButton")},this.expandDetails=function(){ui=!0,nt&&(tt=nt,st=li,nt=r,pi(r,0,r,!0)),y.trigger("hideInfoButton"),y.trigger("showDetails",ni,it)},this.sortBy=function(n){ct=n,wi()},this.gridView=function(){return dt?!1:(dt=!0,wi(),!0)},this.graphView=function(){return dt?(dt=!1,wi(),!0):!1},this.filter=function(){wi()},this.addFilter=function(n){typeof n=="function"&&ii.push(n)},this.removeFilter=function(n){var t=ii.indexOf(n);t!==-1&&ii.splice(t,1)},this.clearFilters=function(){ii=[]},this.setFacets=function(n){if(rt.length)throw"You must set facet categories before adding items.";ii=[],it=n;var i,r,t;for(i in it)s.call(it,i)&&(r=it[i],t=r.orders,t&&t.length&&(function(){var i=t[0].order,n={};i.forEach(function(t,i){n[t]=i}),r.comparator=function(t,i){var u=s.call(n,t),r=s.call(n,i);return u?r?n[t]-n[i]:-1:r?1:t===i?0:t>i?1:-1}})());y.trigger("hideDetails"),y.trigger("hideInfoButton"),y.trigger("facetsSet",it)},this.addItems=function(n){function i(){t--,t||(rt=rt.concat(r),n.forEach(rf),y.filter())}if(!rt.length&&(d.length||ot.length)){ti(function(){y.addItems(n)});return}var t=1,r=[];n.forEach(function(n){var e=n.sdimg=n.sdimg||[],f,u;n.img&&(f=e[-1]=e[-1]||new Seadragon2.Image(yu),f.src=n.img,f.update(),f.state||(t++,f.addEventListener("load",i,!1))),u=n.id,u||typeof u=="number"||(u=n.id=fu()),n.name||(n.name=""),n.description||(n.description=""),n.href||(n.href=""),n.facets||(n.facets={}),s.call(gt,u)||(gt[u]=n,r.push(n)),ni===n&&nr&&ui&&(y.trigger("hideDetails"),y.trigger("showDetails",n,it))}),i()},this.setTemplates=function(n){if(rt.length||d.length||ot.length)throw"You must set templates before adding items!";w=n.sort(function(n,t){return n.width-t.width}),w[-1]={type:"sdimg"},w.forEach(function(n){n.type==="canvas"&&(n.func=yt(n)),n.type==="html"&&n.renderer&&(n.type="fakehtml")}),p=-1},this.clearItems=function(){rt=[],gt={},y.filter()},this.getItemById=function(n){return gt[n]},this.setTitle=function(n){y.trigger("titleChange",n)},this.setCopyright=function(n){y.trigger("copyright",n)},this.runFiltersWithout=function(n){this.removeFilter(n);var t=rt.filter(function(n){return ii.every(function(t){return t(n)})});return this.addFilter(n),t},this.runSearch=function(n,i){function f(i){i=i.content||i,typeof i=="number"?i=b(i):i instanceof t&&(i=i.toLocaleDateString()+" "+i.toLocaleTimeString());var f=i.toLowerCase().indexOf(n);f===0?hu(u,i):f>0&&hu(r,i)}var u,r,e;return i?(u={},r={},e={front:u,rest:r}):u=r={},n=n.toLowerCase(),n&&rt.forEach(function(n){var i=n.facets,t;for(t in i)s.call(i,t)&&i[t].forEach(f);f(n.name)}),e},ff()},ae=hr.CxmlLoader={load:function(n,i){function e(){Seadragon2.Debug.error("Failed to fetch CXML: "+i)}function f(){function et(n,t,i){if(n.getAttributeNS)return n.getAttributeNS(t,i);for(var f=n.attributes,r,e=f.length,u=0;u<e;u++){r=f[u];if(r.namespaceURI===t&&r.baseName===i)return r.value}return null}var lt=this.responseXML||Seadragon2.Xml.parse(this.responseText),d,l,s,a,ut,p,y,c,rt,k,it,ht,b,ft,v,w,g,vt,tt,ct,st,h,at,ot,yt,nt;if(!lt){Seadragon2.Debug.error("Failed to parse CXML: "+i);return}rt=[],d=lt.documentElement,nt=d.ELEMENT_NODE||1,st=et(d,r,"Supplement"),st&&Seadragon2.Xml.fetch(i.split("/").slice(0,-1).join("/")+"/"+st,f,e),h=d.getAttribute("Name"),h&&n.setTitle(h),l=d.getElementsByTagName("FacetCategories")[0];if(l){for(l=l.childNodes,ut=l.length,a=0;a<ut;a++){s=l[a];if(s.nodeType===nt)for(u[s.getAttribute("Name")]=p={index:a},p.type=s.getAttribute("Type"),p.isFilterVisible=et(s,r,"IsFilterVisible")==="true",p.isMetaDataVisible=et(s,r,"IsMetaDataVisible")==="true",p.isWordWheelVisible=et(s,r,"IsWordWheelVisible")==="true",c=s.childNodes,it=c.length,k=0;k<it;k++){v=c[k].firstChild;if(v)if((v.localName||v.baseName)==="SortOrder"&&v.namespaceURI===r)for(p.orders=p.orders||[],ot={name:v.getAttribute("Name")},at=ot.order=[],p.orders.push(ot),v=v.childNodes,ft=v.length,b=0;b<ft;b++)h=v[b],(h.localName||h.baseName)==="SortValue"&&h.namespaceURI===r&&at.push(h.getAttribute("Value"))}}n.setFacets(u)}for(l=d.childNodes,a=l.length-1;a>=0;a--)h=l[a],h.tagName==="Extension"&&(c=h.firstChild,c&&(c.localName||c.baseName)==="Copyright"&&c.namespaceURI===r&&n.setCopyright({href:i.split("/").slice(0,-1).join("/")+"/"+c.getAttribute("Href"),name:c.getAttribute("Name")}));l=d.getElementsByTagName("Items")[0];if(!l)return;for(h=l.getAttribute("ImgBase"),h&&(o=i.slice(0,i.lastIndexOf("/")+1)+h.replace("\\","/")),l=l.childNodes,ut=l.length,a=0;a<ut;a++){s=l[a];if(s.nodeType===nt){ct=s.getAttribute("Id"),y=n.getItemById(ct),y?yt=!0:(y={},y.id=ct,y.facets={}),rt.push(y),h=s.getAttribute("Href"),h&&(y.href=h),h=s.getAttribute("Name"),h&&(y.name=h),h=s.getAttribute("Img"),h&&(y.img=o+h),tt=s.getElementsByTagName("Description"),tt.length&&(y.description=tt[0].textContent||tt[0].text),c=s.getElementsByTagName("Facets")[0];if(c)for(c=c.childNodes,it=c.length,k=0;k<it;k++){s=c[k];if(s.nodeType===nt)for(ht=s.getAttribute("Name"),p=u[ht],y.facets[ht]=vt=[],v=s.childNodes,ft=v.length,b=0;b<ft;b++){s=v[b];if(s.nodeType===nt){switch(p.type){case"String":case"LongString":w=g=s.getAttribute("Value").trim();break;case"Link":w=s.getAttribute("Name").trim(),g={content:w,href:s.getAttribute("Href")};break;case"Number":w=s.getAttribute("Value"),g=parseFloat(w);break;case"DateTime":w=s.getAttribute("Value"),g=new t(w);break;default:Seadragon2.Debug.warn("Unknown facet type "+p.type),w=g=s.getAttribute("Value")}vt.push(g)}}}}}rt.length&&n.addItems(rt)}var r="http://schemas.microsoft.com/livelabs/pivot/collection/2009",o,u;n.setTitle(i),u={},Seadragon2.Xml.fetch(i,f,e)}},ws=hr.init=function(n,f){function ur(){lt.style.height="80px",yt.innerHTML="more",yt.onclick=rr}function ai(n){n.className=n.className.replace(" pivot_activesort","")+" pivot_hoverable"}function yi(n){n.className=n.className.replace(" pivot_hoverable","")+" pivot_activesort"}function d(n,t,i){var u=y[n],f,o;if(t&&t.length>0)if(u)u.values=t;else{switch(i){case"String":case"LongString":case"Link":o=function(t){return u.values.some(function(i){var r=t.facets[n];return r?r.some(function(n){return n=n.content||n,i===n}):i==="(no info)"})};break;case"DateTime":case"Number":o=function(t){return u.values.some(function(i){var u=t.facets[n];return u?u.some(function(n){return n>=i.lowerBound&&(i.inclusive?n<=i.upperBound:n<i.upperBound)}):i.lowerBound===r})};break;default:Seadragon2.Debug.warn("Unrecognized facet type "+i);return}u=y[n]={filter:o,values:t},e.addFilter(u.filter),ot++,f=ht[n],f&&(f.style.visibility="visible"),ot===1&&(w.style.visibility="visible")}else u&&(delete y[n],e.removeFilter(u.filter),ot--),f=ht[n],f&&(f.style.visibility=""),ot||v||(w.style.visibility="")}function or(n){var t=y[p],i,r=p;n.target.checked?t?t.values.push(n.target.name):d(r,[n.target.name],pt):(i=t.values.indexOf(n.target.name),i!==-1&&t.values.splice(i,1),t.values.length||d(p)),e.filter()}function vr(n){var f=y[p],t=n.target.parentNode.previousSibling,u,i,o,r;t.checked=!0,u=t.name;if(f){for(r=rt.lastChild.childNodes,o=r.length,i=0;i<o;i++)t=r[i].firstChild,t.name!==u&&(t.checked=!1);f.values=[u],e.filter()}else or({target:t})}function lr(n,t,i,r){d(n,[{lowerBound:t,upperBound:i,inclusive:r}],"Number"),e.filter()}function ar(n){d(n),e.filter()}function dr(n,t){d(n,t,"DateTime"),e.filter()}function gr(n,t){return t.count-n.count}function kr(n,t){return n=n.value,t=t.value,n===t?0:n==="(no info)"?1:t==="(no info)"?-1:n>t?1:-1}function wr(){si.currentComparator=(si.currentComparator+1)%si.comparators.length,g()}function gi(n){var t,r,c,w,f,b,k,a,o,ut,ft,et,v,d,g,it,nt,tt;rt&&(rt.style.height="0px",rt.style.overflow="hidden"),t=n.target,t.name||(t=t.parentNode),si=t,p=t.name,pt=t.facetType,r=t.nextSibling,r.innerHTML="",c=y[p]||{},w=e.runFiltersWithout(c.filter);switch(pt){case"Link":case"String":case"LongString":f={},d=function(n){n=n.content||n,f[n]||(f[n]=0),f[n]++},w.forEach(function(n){n.facets[p]?n.facets[p].forEach(d):d("(no info)")}),k=[];for(b in f)s.call(f,b)&&k.push({value:b,count:f[b]});k.sort(t.comparators[t.currentComparator]),g=u("div","pivot_sortlabel",r),h(g,t.comparatorNames[t.currentComparator]),g.onclick=wr,it=u("ul","pivot",r),et=c.values||[],k.forEach(function(n){a=u("li",null,it),o=u("input","pivot pivot_facetcheckbox",a),o.setAttribute("type","checkbox"),o.name=n.value,et.indexOf(n.value)!==-1&&(o.checked=!0),o.onclick=or,v=u("div","pivot_outerlabel",a),v.onclick=vr,ft=u("div","pivot_facetcount",v),h(ft,n.count),ut=u("div","pivot_facetlabel",v),h(ut,n.value),a.title=n.value});break;case"Number":nt=new oo(r,w,p,c.values),nt.addListener("filter",lr),nt.addListener("unfilter",ar);break;case"DateTime":tt=new fo(r,w,p,c.values),tt.addListener("filter",dr);break;default:Seadragon2.Debug.warn("Unrecognized facet type: "+pt)}r.style.height=i.max(150,parseFloat(Seadragon2.Element.getStyle(l).height)+ri)+"px",r.style.overflowY="auto",rt=r}function g(){rt&&gi({target:rt.previousSibling})}function br(n){d(n.target.parentNode.name),e.filter(),g(),n.stopPropagation()}function wi(n){var r=n.facets,i=v.trim().toLowerCase().split(" ");return i.every(function(i){return n.name.toLowerCase().indexOf(i)!==-1||ci.some(function(n){var u=r[n];return u&&u.some(function(n){return n=n.content||n,typeof n=="number"&&(n=b(n)),n instanceof t&&(n=n.toLocaleDateString()+" "+n.toLocaleTimeString()),n.toLowerCase().indexOf(i)!==-1})})})}function ei(){v?(o.value=v,it.className="pivot_searchbtn pivot_clrsearch",it.onmousedown=nr):(nt.className="pivot_watermark",o.value="Search...",it.onmousedown=null),at.innerHTML="",a=-1,ft=0}function nr(n){it.className="pivot_searchbtn",v=null,ot||(w.style.visibility=""),ei(),e.removeFilter(wi),n!==!0&&(e.filter(),g())}function di(n){e.clearFilters();var t;for(t in ht)s.call(ht,t)&&(ht[t].style.visibility="");v&&nr(!0),w.style.visibility="",y={},ot=0,n!==!0&&(e.filter(),g())}function fi(){var n=!!v;v=o.value,n||e.addFilter(wi),w.style.visibility="visible",ei(),e.filter(),g()}function ki(n){var i=[],t;for(t in n)s.call(n,t)&&i.push({value:t,count:n[t]});i.sort(function(n,t){return t.count-n.count}),i.every(function(n){if(ft>=10)return!1;var t=u("li",null,at);return h(t,n.value),t.onmousedown=function(){o.value=n.value,fi()},ft++,!0})}function bi(n){var t=at.childNodes[a];t&&(t.className=""),a=n,a<ft?a<-1&&(a=ft-1):a=-1,a===-1?o.value=ui:(t=at.childNodes[a],t.className="pivot_highlight",o.value=t.firstChild.textContent)}function pi(n){switch(n.keyCode){case 38:bi(a-1);break;case 40:bi(a+1);break;case 13:wt.focus();break;default:ui=o.value;var t=e.runSearch(ui,!0);at.innerHTML="",a=-1,ft=0,ki(t.front),ki(t.rest)}}function sr(){v?(it.className="pivot_searchbtn",pi({})):(nt.className="",o.value=""),it.onmousedown=fi}function cr(){var o={},f,n,t,i;for(f in y)if(s.call(y,f)){for(var h=y[f].values,e=[],u,c=h.length,r=0;r<c;++r)n=h[r],typeof n=="string"?(e.push(n),u="String"):(t=n.lowerBound,i=n.upperBound,typeof t!="number"&&typeof i!="number"?(t=t.getTime(),i=i.getTime(),u="DateTime"):u="Number",e.push({lowerBound:t,upperBound:i,inclusive:n.inclusive}));o[f]={values:e,dataType:u}}return JSON.stringify({filters:o,search:v,sortBy:k.value,view:et.className.indexOf("pivot_activesort")!==-1?"grid":"graph"})}function hr(n){n=JSON.parse(n);var f=n.filters,l=n.search,h=n.sortBy,i;for(i in f)if(s.call(f,i)){var c=f[i],u=c.dataType,r=c.values;u==="DateTime"&&r.forEach(function(n){n.lowerBound=new t(n.lowerBound),n.upperBound=new t(n.upperBound)}),u==="Number"&&r.forEach(function(n){n.lowerBound===null&&(n.lowerBound=-Infinity),n.upperBound===null&&(n.upperBound=Infinity)}),d(i,r,u)}l&&(o.value=l,fi()),h&&(k.value=h,e.sortBy(h)),n.view==="graph"&&st.onclick(),g()}var wt,tt,ct,li,bt,ut,gt,rr,ii,ti,ni,st,et,k,tr,nt,o,v,at,it,ft,a,ui,ri,rt,si,p,pt,y,ot,w,ht,ci;while(n.firstChild)n.removeChild(n.firstChild);if(!u("canvas").getContext){h(n,"Your browser doesn't support canvas! Get a better one.");return}wt=u("input","pivot_input",n),wt.setAttribute("type","checkbox");var er=u("div","pivot pivot_viewbox",n),vt=u("div","pivot pivot_topbar",er),fr=u("div","pivot pivot_title",vt),oi=u("div","pivot pivot_canvas",er),hi=u("div","pivot pivot_layer",oi),yr=u("div","pivot pivot_layer",hi),dt=u("canvas","pivot",hi);dt.height=dt.offsetHeight,dt.width=dt.offsetWidth;var pr=u("div","pivot pivot_layer",hi),l=u("div","pivot pivot_pane pivot_filterpane",oi),ir=l.offsetLeft+l.offsetWidth,e=new re(dt,hi,pr,yr,ir,ir,wt),c=u("div","pivot pivot_pane pivot_detailspane",oi);c.style.opacity=0,c.style.display="none",tt=u("div","pivot_hoverable pivot_left pivot_larr",c),tt.onclick=function(){e.moveLeft()},tt=u("div","pivot_left pivot_subtle pivot_vertbar",c),h(tt,"|"),tt=u("div","pivot_hoverable pivot_left pivot_rarr",c),tt.onclick=function(){e.moveRight()},tt=u("div","pivot_hoverable pivot_right pivot_collapse",c),tt.onclick=function(){e.collapseDetails()},ct=u("h2","pivot",c),ct=u("a","pivot",ct),ct.setAttribute("target","_blank");var kt=u("div","pivot pivot_scrollable",c),lt=u("div","pivot pivot_description",kt),yt=u("div","pivot_sortlabel",kt),vi=u("dl","pivot",kt);return u("div","pivot_horizbar",c),li=u("div","pivot_copyright",c),ut=u("div","pivot_info",oi),ut.style.display="none",ut.onclick=function(){e.expandDetails()},gt=!1,rr=function(){lt.style.height="auto",yt.innerHTML="less",yt.onclick=ur},e.addListener("showDetails",function(n,i){var rt,o,p,tt,ot,ft,v,it,et,y,f,k,a,w,nt,ut;bt||(c.style.display="",setTimeout(function(){c.style.opacity=1},0),l.className+=" pivot_faded",ti!==r&&(clearTimeout(ti),ti=r));if(n!==bt){ct.innerHTML="",h(ct,n.name||"???"),rt=n.href,rt&&ct.setAttribute("href",rt),kt.style.height=parseFloat(Seadragon2.Element.getStyle(c).height)-kt.offsetTop-25+"px",lt.innerHTML="",n.description&&h(lt,n.description),lt.style.height="auto",lt.offsetHeight>80?(ur(),yt.style.display="block"):yt.style.display="none",vi.innerHTML="",p=n.facets,w=[];for(o in p)a=i[o],s.call(p,o)&&a&&a.isMetaDataVisible&&w.push(o);for(w.sort(function(n,t){return(i[n].index||0)-(i[t].index||0)}),ut=w.length,nt=0;nt<ut;++nt)for(o=w[nt],a=i[o],ot=u("dt","pivot",vi),h(ot,o),tt=p[o],tt=p[o],et=tt.length,ft=u("dd","pivot",vi),it=0;it<et;it++){v=u("div",r,ft),y=r,f=tt[it];switch(a.type){case"String":case"LongString":h(v,f),y=f;break;case"Link":k=u("a",r,v),k.target="_blank",k.href=f.href,h(k,f.content);break;case"Number":h(v,b(f)),y={upperBound:f,lowerBound:f,inclusive:!0};break;case"DateTime":h(v,f.toLocaleDateString()+" "+f.toLocaleTimeString()),y={lowerBound:f,upperBound:new t(f.getTime()+1e3)};break;default:Seadragon2.Debug.warn("Unrecognized facet type in details pane: "+a.type)}y!==r&&a.isFilterVisible&&(v.className+=" pivot_filterable",(function(){var i=o,t=[y],n=a.type;v.onclick=function(){di(!0),d(i,t,n),g(),e.filter()}})())}bt=n}}),e.addListener("hideDetails",function(){bt&&(c.style.opacity=0,ti=setTimeout(function(){c.style.display="none",ti=r},500),bt=null,l.className=l.className.replace(" pivot_faded",""))}),e.addListener("showInfoButton",function(){gt||(ut.style.display="",setTimeout(function(){ut.style.opacity=1},0),l.className+=" pivot_faded",gt=!0,ii!==r&&(clearTimeout(ii),ii=r))}),e.addListener("hideInfoButton",function(){gt&&(ut.style.opacity=0,ii=setTimeout(function(){ut.style.display="none",ii=r},500),gt=!1,l.className=l.className.replace(" pivot_faded",""))}),ni=u("div","pivot pivot_sorttools pivot_zoomslider",vt),ni=new uo(ni,0,100,0,"Zoom Out","Zoom In"),st=u("div","pivot_sorttools pivot_graph pivot_hoverable",vt),st.title="Graph View",et=u("div","pivot_sorttools pivot_grid pivot_activesort",vt),et.title="Grid View",st.onclick=function(){e.graphView()&&(yi(st),ai(et))},et.onclick=function(){e.gridView()&&(yi(et),ai(st))},k=u("select","pivot pivot_sorttools",vt),k.onchange=function(){e.sortBy(k.value)},tr=u("div","pivot_sorttools pivot_subtle",vt),h(tr,"Sort:"),e.addListener("zoom",function(n){ni.setValue(n)}),ni.addListener("change",function(n){e.zoomToPercent(n)}),e.addListener("titleChange",function(n){fr.innerHTML="",h(fr,n)}),e.addListener("copyright",function(n){li.innerHTML="";var t=u("a",r,li);t.href=n.href,t.target="_blank",h(t,n.name)}),e.addListener("resize",g),e.addListener("filterrequest",function(n){var t=n.type,i=n.values;d(n.facet,i,t),(t==="String"||t==="Link"||t==="LongString")&&i.length===1?e.gridView()&&(yi(et),ai(st)):e.filter(),g()}),e.addListener("facetsSet",function(n){var t,st,i,et,r,ct,c,b,tt,lt,d,g,ut;ci=[],k.innerHTML="";for(t in n)s.call(n,t)&&(n[t].isFilterVisible&&(st=u("option",null,k),st.value=t,h(st,t)),n[t].isWordWheelVisible&&ci.push(t));e.sortBy(k.value),y={},ot=0,a=-1,ft=0,v=null,ui=null,rt=null,p="",pt=null,l.innerHTML="",ri=-10,w=u("div","pivot_clrlabel pivot_clr",l),w.onclick=di,ht={},c=u("div","pivot_clrbtn pivot_clr",w),c.innerHTML="×",h(w,"Clear All"),nt=u("form",null,l),nt.onsubmit=function(n){fi(),n.preventDefault()},o=u("input","pivot_searchbox",nt),o.type="text",o.onfocus=sr,o.onblur=ei,o.onkeyup=pi,it=u("span","pivot_searchbtn",nt),it.innerHTML="×",at=u("ul","pivot pivot_results",nt),ei(),ri-=nt.offsetHeight+w.offsetHeight,b=[];for(t in n)s.call(n,t)&&n[t].isFilterVisible&&b.push(t);for(b.sort(function(t,i){return(n[t].index||0)-(n[i].index||0)}),lt=b.length,tt=0;tt<lt;++tt)t=b[tt],r=n[t],i=u("div","pivot pivot_facetname",l),i.onclick=gi,i.name=t,i.facetType=r.type,(r.type==="String"||r.type==="LongString"||r.type==="Link")&&(d=i.comparatorNames=[],g=i.comparators=[],i.currentComparator=0,r.orders&&r.orders.length&&r.comparator&&((function(){var n=r.comparator;g.push(function(t,i){return n(t.value,i.value)})})(),d.push("Sort: "+r.orders[0].name)),d.push("Sort: Quantity"),g.push(gr),d.push("Sort: A-Z"),g.push(kr)),c=ht[t]=c.cloneNode(!0),c.onclick=br,i.appendChild(c),ct=u("div","pivot_facetlabel",i),h(ct,t),ri-=i.offsetHeight,et=u("div","pivot pivot_facetvalues",l),et.style.height=0,et.style.overflow="hidden";if(f){ut=location.hash;if(ut&&ut.length>2)try{hr(decodeURIComponent(ut.substr(1)))}catch(vt){Seadragon2.Debug.warn("bad URL hash")}}}),n.addEventListener("click",function(n){var t=n.target;t!==o&&t!==k&&wt.focus()}),f&&e.addListener("finishedRearrange",function(){location.hash="#"+encodeURIComponent(cr())}),e};Seadragon2.ImageManager.disable(),addEventListener("load",function(){for(var t,u,f,o=n.getElementsByClassName("pivot_ajax_viewer"),i,e=o.length,r=0;r<e;r++)t=o[r],u=t.getAttribute("data-collection"),i=t.getAttribute("data-use-hash"),i=i&&i.toLowerCase()!=="false",f=ws(t,i),t.pivotViewer=f,u&&ae.load(f,u)},!1)})(document,Date,Math)