text: var BAM_MAGIC=21840194,BAI_MAGIC=21578050;function BamFile(){}function Vob(a,b){this.block=a;this.offset=b}Vob.prototype.toString=function(){return""+this.block+":"+this.offset};function Chunk(a,b){this.minv=a;this.maxv=b}
  function makeBam(a,b,c){var d=new BamFile;d.data=a;d.bai=b;d.data.slice(0,65536).fetch(function(e){if(!e)return dlog("Couldn't access BAM");e=unbgzf(e);e=new Uint8Array(e);readInt(e,0);for(var h=readInt(e,4),j="",i=0;i<h;++i)j+=String.fromCharCode(e[i+8]);j=readInt(e,h+8);h=h+12;d.chrToIndex={};d.indexToChr=[];for(i=0;i<j;++i){for(var l=readInt(e,h),m="",o=0;o<l-1;++o)m+=String.fromCharCode(e[h+4+o]);readInt(e,h+l+4);d.chrToIndex[m]=i;if(m.indexOf("chr")==0)d.chrToIndex[m.substring(3)]=i;else d.chrToIndex["chr"+
  m]=i;d.indexToChr.push(m);h=h+8+l}if(d.indices)return c(d)});d.bai.fetch(function(e){if(!e)return dlog("Couldn't access BAI");var h=new Uint8Array(e);if(readInt(h,0)!=BAI_MAGIC)return dlog("Not a BAI file");var j=readInt(h,4);d.indices=[];for(var i=8,l=0;l<j;++l){var m=i,o=readInt(h,i);i+=4;for(var r=0;r<o;++r){readInt(h,i);var p=readInt(h,i+4);i+=8+p*16}r=readInt(h,i);i+=4;i+=r*8;if(o>0)d.indices[l]=new Uint8Array(e,m,i-m)}if(d.chrToIndex)return c(d)})}
  BamFile.prototype.blocksForRange=function(a,b,c){var d=this.indices[a];if(!d)return[];a=reg2bins(b,c);for(var e=[],h=0;h<a.length;++h)e[a[h]]=true;a=[];var j=[];h=readInt(d,0);for(var i=4,l=0;l<h;++l){var m=readInt(d,i),o=readInt(d,i+4);i+=8;if(e[m])for(var r=0;r<o;++r){var p=readVob(d,i),t=readVob(d,i+8);(m<4681?j:a).push(new Chunk(p,t));i+=16}else i+=o*16}h=readInt(d,i);e=null;b=Math.min(b>>14,h-1);c=Math.min(c>>14,h-1);for(h=b;h<=c;++h)if(b=readVob(d,i+4+h*8))if(!e||b.block<e.block||b.offset<e.offset)e=
  b;d=[];if(e!=null)for(h=0;h<j.length;++h){c=j[h];c.maxv.block>=e.block&&c.maxv.offset>=e.offset&&d.push(c)}j=d;d=[];for(h=0;h<j.length;++h)d.push(j[h]);for(h=0;h<a.length;++h)d.push(a[h]);d.sort(function(q,s){var u=q.minv.block-s.minv.block;return u!=0?u:q.minv.offset-s.minv.offset});a=[];if(d.length>0){j=d[0];for(h=1;h<d.length;++h){c=d[h];if(c.minv.block==j.maxv.block)j=new Chunk(j.minv,c.maxv);else{a.push(j);j=c}}a.push(j)}return a};
  BamFile.prototype.fetch=function(a,b,c,d){function e(){if(m>=i.length)return d(l);else if(o){var r=new Uint8Array(o);h.readBamRecords(r,i[m].minv.offset,l,b,c,j);o=null;++m;return e()}else{var p=i[m];r=p.minv.block;h.data.slice(r,p.maxv.block+65536-r).fetch(function(t){o=unbgzf(t,p.maxv.block-p.minv.block+1);return e()})}}var h=this,j=this.chrToIndex[a],i;if(j===undefined)i=[];else(i=this.blocksForRange(j,b,c))||d(null,"Error in index fetch");var l=[],m=0,o;e()};
  var SEQRET_DECODER=["=","A","C","x","G","x","x","x","T","x","x","x","x","x","x","N"],CIGAR_DECODER=["M","I","D","N","S","H","P","=","X","?","?","?","?","?","?","?"];function BamRecord(){}
  BamFile.prototype.readBamRecords=function(a,b,c,d,e,h){for(;;){var j=readInt(a,b);j=b+j+4;if(j>=a.length)return c;var i=new BamRecord,l=readInt(a,b+4),m=readInt(a,b+8),o=readInt(a,b+12),r=(o&65280)>>8,p=o&255,t=readInt(a,b+16)&65535;o=readInt(a,b+20);readInt(a,b+24);readInt(a,b+28);readInt(a,b+32);for(var q="",s=0;s<p-1;++s)q+=String.fromCharCode(a[b+36+s]);b=b+36+p;s="";for(p=0;p<t;++p){var u=readInt(a,b);s=s+(u>>4)+CIGAR_DECODER[u&15];b+=4}i.cigar=s;t="";p=o+1>>1;for(s=0;s<p;++s){u=a[b+s];t+=SEQRET_DECODER[(u&
  240)>>4];t+=SEQRET_DECODER[u&15]}b+=p;i.seq=t;t="";for(s=0;s<o;++s)t+=String.fromCharCode(a[b+s]);b+=o;i.quals=t;i.pos=m;i.mq=r;i.readName=q;for(i.segment=this.indexToChr[l];b<j;){m=String.fromCharCode(a[b])+String.fromCharCode(a[b+1]);r=String.fromCharCode(a[b+2]);if(r=="A"){r=String.fromCharCode(a[b+3]);b+=4}else if(r=="i"||r=="I"){r=readInt(a,b+3);b+=7}else if(r=="c"||r=="C"){r=a[b+3];b+=4}else if(r=="s"||r=="S"){r=readShort(a,b+3);b+=5}else if(r=="f")throw"FIXME need floats";else if(r=="Z"){b+=
  3;for(r="";;){q=a[b++];if(q==0)break;else r+=String.fromCharCode(q)}}else throw"Unknown type "+r;i[m]=r}if(!d||i.pos<=e&&i.pos+o>=d)if(h===undefined||l==h)c.push(i);b=j}};function readInt(a,b){return a[b+3]<<24|a[b+2]<<16|a[b+1]<<8|a[b]}function readShort(a,b){return a[b+1]<<8|a[b]}function readVob(a,b){var c=(a[b+6]&255)*4294967296+(a[b+5]&255)*16777216+(a[b+4]&255)*65536+(a[b+3]&255)*256+(a[b+2]&255),d=a[b+1]<<8|a[b];return c==0&&d==0?null:new Vob(c,d)}
  function unbgzf(a,b){b=Math.min(b||1,a.byteLength-100);for(var c=[],d=[0],e=0;d[0]<b;){var h=new Uint8Array(a,d[0],100);h=h[11]<<8|h[10];h=jszlib_inflate_buffer(a,12+h+d[0],Math.min(65536,a.byteLength-12-h-d[0]),d);d[0]+=8;e+=h.byteLength;c.push(h)}if(c.length==1)return c[0];else{d=new Uint8Array(e);for(h=e=0;h<c.length;++h){var j=new Uint8Array(c[h]);arrayCopy(j,0,d,e,j.length);e+=j.length}return d.buffer}}
  function reg2bin(a,b){--b;if(a>>14==b>>14)return 4681+(a>>14);if(a>>17==b>>17)return 585+(a>>17);if(a>>20==b>>20)return 73+(a>>20);if(a>>23==b>>23)return 9+(a>>23);if(a>>26==b>>26)return 1+(a>>26);return 0}var MAX_BIN=37449;
  function reg2bins(a,b){var c,d=[];--b;d.push(0);for(c=1+(a>>26);c<=1+(b>>26);++c)d.push(c);for(c=9+(a>>23);c<=9+(b>>23);++c)d.push(c);for(c=73+(a>>20);c<=73+(b>>20);++c)d.push(c);for(c=585+(a>>17);c<=585+(b>>17);++c)d.push(c);for(c=4681+(a>>14);c<=4681+(b>>14);++c)d.push(c);return d}var BIG_WIG_MAGIC=-2003829722,BIG_BED_MAGIC=-2021002517,BIG_WIG_TYPE_GRAPH=1,BIG_WIG_TYPE_VSTEP=2,BIG_WIG_TYPE_FSTEP=3;function BigWig(){}
  BigWig.prototype.readChromTree=function(a){var b=this;this.chromsToIDs={};this.idsToChroms={};this.maxID=0;var c=this.unzoomedDataOffset;c=c+4-(c-this.chromTreeOffset&3);this.data.slice(this.chromTreeOffset,c-this.chromTreeOffset).fetch(function(d){var e=new Uint8Array(d),h=new Int16Array(d),j=new Int32Array(d),i=j[2],l=function(m){var o=e[m],r=h[m/2+1];m+=4;for(var p=0;p<r;++p)if(o==0){m+=i;var t=j[m/4]<<32|j[m/4+1];m+=8;t-=b.chromTreeOffset;l(t)}else{t="";for(var q=0;q<i;++q){var s=e[m++];if(s!=
  0)t+=String.fromCharCode(s)}q=e[m+3]<<24|e[m+2]<<16|e[m+1]<<8|e[m+0];m+=8;b.chromsToIDs[t]=q;if(t.indexOf("chr")==0)b.chromsToIDs[t.substr(3)]=q;b.idsToChroms[q]=t;b.maxID=Math.max(b.maxID,q)}};l(32);a(b)})};function BigWigView(a,b,c,d){this.bwg=a;this.cirTreeOffset=b;this.cirTreeLength=c;this.isSummary=d}BED_COLOR_REGEXP=/^[0-9]+,[0-9]+,[0-9]+/;BigWigView.prototype.readWigData=function(a,b,c,d){a=this.bwg.chromsToIDs[a];if(a===undefined)return d([]);else this.readWigDataById(a,b,c,d)};
  BigWigView.prototype.readWigDataById=function(a,b,c,d){var e=this;if(this.cirHeader){var h=[],j=0;Date.now();var i=function(o,r){j+=o.length;for(var p=4+e.cirBlockSize*32,t,q=0;q<o.length;++q){var s=new Range(o[q],o[q]+p);t=t?union(t,s):s}p=t.ranges();for(t=0;t<p.length;++t)l(o,p[t],r)},l=function(o,r,p){r.max();r.min();e.bwg.data.slice(r.min(),r.max()-r.min()).fetch(function(t){for(var q=0;q<o.length;++q)if(r.contains(o[q])){var s=t,u=o[q]-r.min(),v=p,w=new Int8Array(s),z=new Int16Array(s);s=new Int32Array(s);
  w=w[u];z=z[u/2+1];u+=4;if(w!=0)for(w=0;w<z;++w){var x=u/4,D=s[x],C=s[x+1],A=s[x+2],B=s[x+3],G=s[x+4]<<32|s[x+5];v=s[x+6]<<32|s[x+7];if((a<0||D<a||D==a&&C<=c)&&(a<0||A>a||A==a&&B>=b))h.push({offset:G,size:v});u+=32}else{var E=[];for(w=0;w<z;++w){x=u/4;D=s[x];C=s[x+1];A=s[x+2];B=s[x+3];G=s[x+4]<<32|s[x+5];if((a<0||D<a||D==a&&C<=c)&&(a<0||A>a||A==a&&B>=b))E.push(G);u+=24}E.length>0&&i(E,v+1)}--j;j==0&&m()}})},m=function(){h.sort(function(q,s){return(q.offset|0)-(s.offset|0)});if(h.length==0)d([]);else{var o=
  [],r=function(q,s,u,v){v||(v={});var w=new DASFeature;w._chromId=q;w.segment=e.bwg.idsToChroms[q];w.min=s;w.max=u;w.type="bigwig";for(k in v)w[k]=v[k];o.push(w)},p=function(q,s,u,v){if((a<0||q==a)&&s<=c&&u>=b)r(q,s,u,v)},t=function(){if(h.length==0){Date.now();d(o)}else{var q=h[0];if(q.data){var s=new Uint8Array(q.data);if(e.isSummary){var u=new Int16Array(q.data),v=new Int32Array(q.data),w=new Float32Array(q.data);s=q.data.byteLength/32;for(u=0;u<s;++u){q=v[u*8];var z=v[u*8+1],x=v[u*8+2],D=v[u*8+
  3],C=w[u*8+5],A=w[u*8+6];if(a<0||q==a){D={type:"bigwig",score:A/D,maxScore:C};if(e.bwg.type=="bigbed")D.type="density";p(q,z+1,x,D)}}}else if(e.bwg.type=="bigwig"){u=new Int16Array(q.data);v=new Int32Array(q.data);w=new Float32Array(q.data);q=v[0];z=v[1];D=v[3];x=v[4];C=s[20];s=u[11];if(C==BIG_WIG_TYPE_FSTEP)for(u=0;u<s;++u){C=w[u+6];p(q,z+u*D+1,z+u*D+x,{score:C})}else if(C==BIG_WIG_TYPE_VSTEP)for(u=0;u<s;++u){z=v[u*2+6];C=w[u*2+7];p(q,z+1,z+x,{score:C})}else if(C==BIG_WIG_TYPE_GRAPH)for(u=0;u<s;++u){z=
  v[u*3+6];x=v[u*3+7];C=w[u*3+8];if(z>x)z=x;p(q,z+1,x,{score:C})}else dlog("Currently not handling bwgType="+C)}else if(e.bwg.type=="bigbed")for(v=0;v<s.length;){q=s[v+3]<<24|s[v+2]<<16|s[v+1]<<8|s[v+0];z=s[v+7]<<24|s[v+6]<<16|s[v+5]<<8|s[v+4];x=s[v+11]<<24|s[v+10]<<16|s[v+9]<<8|s[v+8];v+=12;for(u="";;){w=s[v++];if(w!=0)u+=String.fromCharCode(w);else break}w={};var B=u.split("\t");if(B.length>0)w.label=B[0];if(B.length>1)w.score=stringToInt(B[1]);if(B.length>2)w.orientation=B[2];if(B.length>5){u=B[5];
  if(BED_COLOR_REGEXP.test(u))w.override_color="rgb("+u+")"}if(B.length<9||e.bwg.definedFieldCount<12)q==a&&p(q,z+1,x,w);else if(q==a&&z<=c&&x>=b){x=B[3]|0;u=B[4]|0;D=B[6]|0;C=B[7].split(",");A=B[8].split(",");w.type="bb-transcript";var G=new DASGroup;G.id=B[0];G.type="bb-transcript";G.notes=[];w.groups=[G];if(B.length>10){G=B[9];B=B[10];var E=new DASGroup;E.id=G;E.label=B;E.type="gene";w.groups.push(E)}B=null;for(G=0;G<D;++G){E=(A[G]|0)+z;E=new Range(E,E+(C[G]|0));B=B?union(B,E):E}C=B.ranges();for(z=
  0;z<C.length;++z){D=C[z];r(q,D.min()+1,D.max(),w)}if(u>x)if(z=intersection(B,new Range(x,u))){w.type="bb-translation";x=z.ranges();for(z=0;z<x.length;++z){D=x[z];r(q,D.min()+1,D.max(),w)}}}}else dlog("Don't know what to do with "+e.bwg.type);h.splice(0,1);t()}else{s=q.offset;var P=q.size;for(q=1;q<h.length&&h[q].offset==s+P;){P+=h[q].size;++q}e.bwg.data.slice(s,P).fetch(function(R){for(var J=0,S=0;J<P;){var F=h[S],L;if(e.bwg.uncompressBufSize>0)L=jszlib_inflate_buffer(R,J+2,F.size-2);else{L=new Uint8Array(F.size);
  arrayCopy(new Uint8Array(R,J,F.size),0,L,0,F.size);L=L.buffer}F.data=L;J+=F.size;++S}t()})}}};t()}};i([e.cirTreeOffset+48],1)}else this.bwg.data.slice(this.cirTreeOffset,48).fetch(function(o){e.cirHeader=o;o=new Int32Array(e.cirHeader);e.cirBlockSize=o[1];e.readWigDataById(a,b,c,d)})};BigWigView.prototype.getFirstAdjacent=function(a,b,c,d){a=this.bwg.chromsToIDs[a];if(a===undefined)return d([]);else this.getFirstAdjacentById(a,b,c,d)};
  BigWigView.prototype.getFirstAdjacentById=function(a,b,c,d){var e=this;if(this.cirHeader){var h=null,j=-1,i=-1,l=0;Date.now();var m=function(p,t){l+=p.length;for(var q=4+e.cirBlockSize*32,s,u=0;u<p.length;++u){var v=new Range(p[u],Math.min(p[u]+q,e.cirTreeOffset+e.cirTreeLength));s=s?union(s,v):v}q=s.ranges();for(s=0;s<q.length;++s)o(p,q[s],t)},o=function(p,t,q){t.max();t.min();e.bwg.data.slice(t.min(),t.max()-t.min()).fetch(function(s){for(var u=0;u<p.length;++u)if(t.contains(p[u])){var v=s,w=p[u]-
  t.min(),z=q,x=new Int8Array(v),D=new Int16Array(v);v=new Int32Array(v);x=x[w];D=D[w/2+1];w+=4;if(x!=0)for(x=0;x<D;++x){var C=w/4,A=v[C],B=v[C+1],G=v[C+2],E=v[C+3],P=v[C+4]<<32|v[C+5];z=v[C+6]<<32|v[C+7];if(c<0&&(A<a||A==a&&B<=b)||c>0&&(G>a||G==a&&E>=b))if(!/_random/.exec(e.bwg.idsToChroms[A]))if(h==null||c<0&&(G>j||G==j&&E>i)||c>0&&(A<j||A==j&&B<i)){h={offset:P,size:z};i=c<0?E:B;j=c<0?G:A}w+=32}else{var R=-1,J=-1;for(x=0;x<D;++x){C=w/4;A=v[C];B=v[C+1];G=v[C+2];E=v[C+3];P=v[C+4]<<32|v[C+5];if(c<0&&
  (A<a||A==a&&B<=b)&&G>=a||c>0&&(G>a||G==a&&E>=b)&&A<=a)if(R<0||E>J){R=P;J=c<0?E:B}w+=24}R>=0&&m([R],z+1)}--l;l==0&&r()}})},r=function(){if(h==null)return dlog("got nothing");var p=[h];p.sort(function(w,z){return(w.offset|0)-(z.offset|0)});if(p.length==0)d([]);else{var t=null,q=-1,s=-1,u=function(w,z,x,D){if(c<0&&(w<a||x<b)||c>0&&(w>a||z>b)){(D=D)||(D={});var C=new DASFeature;C.segment=e.bwg.idsToChroms[w];C.min=z;C.max=x;C.type="bigwig";for(k in D)C[k]=D[k];if(t==null||c<0&&(w>q||x>s)||c>0&&(w<q||
  z<s)){t=C;s=c<0?x:z;q=w}}},v=function(){if(p.length==0){Date.now();d([t])}else{var w=p[0];if(w.data){var z=new Uint8Array(w.data);if(e.isSummary){var x=new Int16Array(w.data),D=new Int32Array(w.data),C=new Float32Array(w.data);z=w.data.byteLength/32;for(x=0;x<z;++x){w=D[x*8];var A=D[x*8+1],B=D[x*8+2],G={type:"bigwig",score:C[x*8+6]/D[x*8+3]};if(e.bwg.type=="bigbed")G.type="density";u(w,A+1,B,G)}}else if(e.bwg.type=="bigwig"){x=new Int16Array(w.data);D=new Int32Array(w.data);C=new Float32Array(w.data);
  w=D[0];A=D[1];G=D[3];B=D[4];var E=z[20];z=x[11];if(E==BIG_WIG_TYPE_FSTEP)for(x=0;x<z;++x){E=C[x+6];u(w,A+x*G+1,A+x*G+B,{score:E})}else if(E==BIG_WIG_TYPE_VSTEP)for(x=0;x<z;++x){A=D[x*2+6];E=C[x*2+7];u(A+1,A+B,{score:E})}else if(E==BIG_WIG_TYPE_GRAPH)for(x=0;x<z;++x){A=D[x*3+6]+1;B=D[x*3+7];E=C[x*3+8];if(A>B)A=B;u(A+1,B,{score:E})}else dlog("Currently not handling bwgType="+E)}else if(e.bwg.type=="bigbed")for(D=0;D<z.length;){w=z[D+3]<<24|z[D+2]<<16|z[D+1]<<8|z[D+0];A=z[D+7]<<24|z[D+6]<<16|z[D+5]<<
  8|z[D+4];B=z[D+11]<<24|z[D+10]<<16|z[D+9]<<8|z[D+8];D+=12;for(C="";;){x=z[D++];if(x!=0)C+=String.fromCharCode(x);else break}x={};C=C.split("\t");if(C.length>0)x.label=C[0];if(C.length>1)x.score=100;if(C.length>2)x.orientation=C[2];u(w,A+1,B,x)}else dlog("Don't know what to do with "+e.bwg.type);p.splice(0,1);v()}else{z=w.offset;var P=w.size;for(w=1;w<p.length&&p[w].offset==z+P;){P+=p[w].size;++w}e.bwg.data.slice(z,P).fetch(function(R){for(var J=0,S=0;J<P;){var F=p[S],L;if(e.bwg.uncompressBufSize>
  0)L=jszlib_inflate_buffer(R,J+2,F.size-2);else{L=new Uint8Array(F.size);arrayCopy(new Uint8Array(R,J,F.size),0,L,0,F.size);L=L.buffer}F.data=L;J+=F.size;++S}v()})}}};v()}};m([e.cirTreeOffset+48],1)}else this.bwg.data.slice(this.cirTreeOffset,48).fetch(function(p){e.cirHeader=p;p=new Int32Array(e.cirHeader);e.cirBlockSize=p[1];e.readWigDataById(a,min,max,d)})};BigWig.prototype.readWigData=function(a,b,c,d){this.getUnzoomedView().readWigData(a,b,c,d)};
  BigWig.prototype.getUnzoomedView=function(){if(!this.unzoomedView){var a=4E3;if(this.zoomLevels[0])a=this.zoomLevels[0].dataOffset-this.unzoomedIndexOffset;this.unzoomedView=new BigWigView(this,this.unzoomedIndexOffset,a,false)}return this.unzoomedView};BigWig.prototype.getZoomedView=function(a){a=this.zoomLevels[a];if(!a.view)a.view=new BigWigView(this,a.indexOffset,4E3,true);return a.view};function makeBwgFromURL(a,b,c){makeBwg(new URLFetchable(a,{credentials:c}),b,a)}
  function makeBwgFromFile(a,b){makeBwg(new BlobFetchable(a),b,"file")}
  function makeBwg(a,b,c){var d=new BigWig;d.data=a;d.name=c;d.data.slice(0,512).fetch(function(e){if(!e)return b(null,"Couldn't fetch file");var h=new Int16Array(e);e=new Int32Array(e);if(e[0]==BIG_WIG_MAGIC)d.type="bigwig";else if(e[0]==BIG_BED_MAGIC)d.type="bigbed";else b(null,"Not a supported format");d.version=h[2];d.numZoomLevels=h[3];d.chromTreeOffset=e[2]<<32|e[3];d.unzoomedDataOffset=e[4]<<32|e[5];d.unzoomedIndexOffset=e[6]<<32|e[7];d.fieldCount=h[16];d.definedFieldCount=h[17];d.asOffset=e[9]<<
  32|e[10];d.totalSummaryOffset=e[11]<<32|e[12];d.uncompressBufSize=e[13];d.extHeaderOffset=e[14]<<32|e[15];d.zoomLevels=[];for(h=0;h<d.numZoomLevels;++h)d.zoomLevels.push({reduction:e[h*6+16],dataOffset:e[h*6+18]<<32|e[h*6+19],indexOffset:e[h*6+20]<<32|e[h*6+21]});d.readChromTree(function(){return b(d)})})}
  BigWig.prototype._tsFetch=function(a,b,c,d,e){var h=this;if(a>=this.zoomLevels.length-1)if(this.topLevelReductionCache){for(var j=[],i=this.topLevelReductionCache,l=0;l<i.length;++l)i[l]._chromId==b&&j.push(i[l]);return e(j)}else this.getZoomedView(this.zoomLevels.length-1).readWigDataById(-1,0,3E8,function(m){h.topLevelReductionCache=m;return h._tsFetch(a,b,c,d,e)});else return this.getZoomedView(a).readWigDataById(b,c,d,e)};
  BigWig.prototype.thresholdSearch=function(a,b,c,d,e){function h(){if(i.length==0)return e(null);i.sort(function(r,p){var t=r.zoom-p.zoom;if(t!=0)return t;t=r.chrOrd-p.chrOrd;return t!=0?t:r.min-p.min*c});var o=i.splice(0,1)[0];j._tsFetch(o.zoom,o.chr,o.min,o.max,function(r){var p=c>0?0:3E8;if(o.fromRef)p=b;for(var t=0;t<r.length;++t){var q=r[t];if(c>0){if(q.maxScore>d)if(o.zoom==0){if(q.min>p)return e(q)}else q.max>p&&i.push({chr:o.chr,chrOrd:o.chrOrd,zoom:Math.max(0,o.zoom-2),min:q.min,max:q.max,
  fromRef:o.fromRef})}else if(q.maxScore>d)if(o.zoom==0){if(q.max<p)return e(q)}else q.min<p&&i.push({chr:o.chr,chrOrd:o.chrOrd,zoom:Math.max(0,o.zoom-2),min:q.min,max:q.max,fromRef:o.fromRef})}h()})}c=c<0?-1:1;var j=this;a=this.chromsToIDs[a];for(var i=[{chrOrd:0,chr:a,zoom:j.zoomLevels.length-4,min:0,max:3E8,fromRef:true}],l=1;l<=this.maxID+1;++l){var m=(a+c*l)%(this.maxID+1);if(m<0)m+=this.maxID+1;i.push({chrOrd:l,chr:m,zoom:j.zoomLevels.length-1,min:0,max:3E8})}h()};
  BigWig.prototype.getExtraIndices=function(a){thisB=this;if(this.version<4||this.extHeaderOffset==0)return a(null);else this.data.slice(this.extHeaderOffset,64).fetch(function(b){if(!b)return a(null,"Couldn't fetch extension header");var c=new Int16Array(b);b=new Int32Array(b);var d=c[1];b=b[1]<<32|b[2];console.log("extHeaderSize = "+c[0]);console.log("extraIndexCount = "+d);console.log("extraIndexListOffset = "+b);thisB.data.slice(b,d*20).fetch(function(e){if(!e)return a(null,"Couldn't fetch index info");
  var h=new Int16Array(e);e=new Int32Array(e);for(var j=[],i=0;i<d;++i)j.push({type:h[i*10],fieldCount:h[i*10+1],offset:e[i*5+1]<<32|e[i*5+2],field:h[i*10+8]});a(j)})})};function BlobFetchable(a){this.blob=a}BlobFetchable.prototype.slice=function(a,b){var c;c=this.blob.slice?b?this.blob.slice(a,a+b):this.blob.slice(a):b?this.blob.webkitSlice(a,a+b):this.blob.webkitSlice(a);return new BlobFetchable(c)};
  BlobFetchable.prototype.fetch=function(a){var b=new FileReader;b.onloadend=function(){a(bstringToBuffer(b.result))};b.readAsBinaryString(this.blob)};function URLFetchable(a,b,c,d){if(!d)if(typeof b==="object"){d=b;b=undefined}else d={};this.url=a;this.start=b||0;if(c)this.end=c;this.opts=d}URLFetchable.prototype.slice=function(a,b){var c=this.start,d=this.end;c=c&&a?c+a:a||c;d=b&&c?c+b-1:d||b-1;return new URLFetchable(this.url,c,d,this.opts)};
  var seed=0,isIOS=navigator.userAgent.indexOf("Safari")>=0&&navigator.userAgent.indexOf("Chrome")<0;
  URLFetchable.prototype.fetch=function(a,b,c){var d=this;b=b||1;if(b>3)return a(null);var e=new XMLHttpRequest,h,j=this.url;if(isIOS)j=j+"?salt="+ ++seed;e.open("GET",j,true);e.overrideMimeType("text/plain; charset=x-user-defined");if(this.end){e.setRequestHeader("Range","bytes="+this.start+"-"+this.end);h=this.end-this.start+1}e.responseType="arraybuffer";e.onreadystatechange=function(){if(e.readyState==4)if(e.status==200||e.status==206)if(e.response){var i=e.response.byteLength;return h&&h!=i&&(!c||
  i!=c)?d.fetch(a,b+1,i):a(e.response)}else if(e.mozResponseArrayBuffer)return a(e.mozResponseArrayBuffer);else{i=e.responseText;return h&&h!=i.length&&(!c||i.length!=c)?d.fetch(a,b+1,i.length):a(bstringToBuffer(e.responseText))}else return d.fetch(a,b+1)};if(this.opts.credentials)e.withCredentials=true;e.send("")};function bstringToBuffer(a){if(!a)return null;for(var b=new Uint8Array(a.length),c=0;c<b.length;++c)b[c]=a.charCodeAt(c);return b.buffer}
  var NS_SVG="http://www.w3.org/2000/svg",NS_HTML="http://www.w3.org/1999/xhtml",NS_XLINK="http://www.w3.org/1999/xlink";function Region(a,b,c){this.min=b;this.max=c;this.chr=a}
  function Browser(a){a||(a={});this.uiPrefix="http://www.biodalliance.org/release-0.10/";this.sources=[];this.tiers=[];this.featureListeners=[];this.featureHoverListeners=[];this.viewListeners=[];this.regionSelectListeners=[];this.tierListeners=[];this.tierSelectionWrapListeners=[];this.cookieKey="browser";this.karyoEndpoint=new DASSource("http://www.derkholm.net:8080/das/hsa_54_36p/");this.registry="http://www.dasregistry.org/das/sources";this.coordSystem={speciesName:"Human",taxon:9606,auth:"NCBI",
  version:"36",ucscName:"hg18"};this.chains={};this.pageName="dalliance_container";this.maxExtra=2.5;this.minExtra=0.5;this.zoomFactor=1;this.zoomMin=10;this.origin=0;this.targetQuantRes=5;this.featurePanelWidth=750;this.zoomBase=100;this.zoomExpt=30;this.zoomSliderValue=100;this.entryPoints=null;this.currentSeqMax=-1;this.highlights=[];this.autoSizeTiers=false;this.guidelineStyle="foreground";this.guidelineSpacing=75;this.fgGuide=null;this.positionFeedback=false;this.selectedTiers=[1];this.placards=[];this.maxViewWidth=
  5E5;this.reverseScrolling=false;this.rulerLocation="center";this.tierBackgroundColors=["rgb(245,245,245)","white"];this.minTierHeight=30;this.browserLinks={Ensembl:"http://ncbi36.ensembl.org/Homo_sapiens/Location/View?r=${chr}:${start}-${end}",UCSC:"http://genome.ucsc.edu/cgi-bin/hgTracks?db=hg18&position=chr${chr}:${start}-${end}"};this.availableSources=new Observed;this.defaultSources=[];this.mappableSources={};this.hubs=[];this.hubObjects=[];this.sourceCache=new SourceCache;for(var b in a)this[b]=
  a[b];var c=this;window.addEventListener("load",function(){c.realInit()},false)}
  Browser.prototype.realInit=function(){this.supportsBinary=true;this.defaultChr=this.chr;this.defaultStart=this.viewStart;this.defaultEnd=this.viewEnd;this.defaultSources=[];for(var a=0;a<this.sources.length;++a)this.defaultSources.push(this.sources[a]);this.restoreStatus&&this.restoreStatus();var b=this;this.browserHolderHolder=document.getElementById(this.pageName);this.browserHolder=makeElement("div",null,{tabIndex:-1},{outline:"none",display:"inline-block",width:"100%"});removeChildren(this.browserHolderHolder);
  this.browserHolderHolder.appendChild(this.browserHolder);this.svgHolder=makeElement("div",null,{className:"main-holder"});this.initUI(this.browserHolder,this.svgHolder);this.tierHolder=makeElement("div",null,{className:"tier-holder"});this.svgHolder.appendChild(this.tierHolder);this.bhtmlRoot=makeElement("div");this.disablePoweredBy||this.bhtmlRoot.appendChild(makeElement("span",["Powered by ",makeElement("a","Dalliance",{href:"http://www.biodalliance.org/"})," "+VERSION],{className:"powered-by"}));
  this.browserHolder.appendChild(this.bhtmlRoot);window.addEventListener("resize",function(){b.resizeViewer()},false);this.ruler=makeElement("div",null,{className:"guideline"});this.svgHolder.appendChild(this.ruler);setTimeout(function(){b.realInit2()},1)};
  Browser.prototype.realInit2=function(){var a=this;this.featurePanelWidth=this.tierHolder.getBoundingClientRect().width|0;this.scale=this.featurePanelWidth/(this.viewEnd-this.viewStart);if(!this.zoomMax)this.zoomMax=this.zoomExpt*Math.log(this.maxViewWidth/this.zoomBase);this.zoomSliderValue=this.zoomExpt*Math.log((this.viewEnd-this.viewStart+1)/this.zoomBase);this.tierHolder.addEventListener("mousewheel",function(h){if(h.wheelDeltaX){h.stopPropagation();h.preventDefault();h=h.wheelDeltaX/5;a.reverseScrolling||
  (h=-h);a.move(h)}},false);this.tierHolder.addEventListener("MozMousePixelScroll",function(h){if(h.axis==1){h.stopPropagation();h.preventDefault();if(h.detail!=0){h=h.detail/4;if(a.reverseScrolling)h=-h;a.move(h)}}},false);var b=function(h){if(h.keyCode==13){var j=false;for(h=0;h<a.tiers.length;++h){var i=a.tiers[h];if(i.wantedLayoutHeight&&i.wantedLayoutHeight!=i.layoutHeight){i.layoutHeight=i.wantedLayoutHeight;i.placard=null;i.clipTier();j=true}}j&&a.arrangeTiers()}else if(h.keyCode==32||h.charCode==
  32){if(a.isSnapZooming){a.isSnapZooming=false;j=a.savedZoom||10}else{a.isSnapZooming=true;j=a.savedZoom||1}a.savedZoom=a.zoomSliderValue;a.zoomSliderValue=j;a.zoom(Math.exp(1*j/a.zoomExpt));a.snapZoomLockout=true;h.stopPropagation();h.preventDefault()}else if(h.keyCode==39){h.stopPropagation();h.preventDefault();if(h.ctrlKey){var l=0;if(h.shiftKey)l=1;var m=(a.viewStart+a.viewEnd+1)/2|0;h=a.getSelectedTier();h<0||a.tiers[h].findNextFeature(a.chr,m,-1,l,function(r){if(r){var p=r.min,t=r.max;if(l)if(t<
  m-1){t++;p=t}else t=p;var q=a.viewEnd-a.viewStart+1;parseFloat(q/2)==parseInt(q/2)&&q--;p=(p+t-q)/2+1;a.setLocation(r.segment,p,p+q-1)}else alert("no next feature")})}else a.move(h.shiftKey?100:25)}else if(h.keyCode==37){h.stopPropagation();h.preventDefault();if(h.ctrlKey){l=0;if(h.shiftKey)l=1;m=(a.viewStart+a.viewEnd+1)/2|0;h=a.getSelectedTier();h<0||a.tiers[h].findNextFeature(a.chr,m,1,l,function(r){if(r){var p=r.min,t=r.max;if(l)if(p>m+1)t=p;else{t++;p=t}var q=a.viewEnd-a.viewStart+1;parseFloat(q/
  2)==parseInt(q/2)&&q--;p=(p+t-q)/2+1;a.setLocation(r.segment,p,p+q-1)}else alert("no next feature")})}else a.move(h.shiftKey?-100:-25)}else if(h.keyCode==38||h.keyCode==87){h.stopPropagation();h.preventDefault();if(h.shiftKey){h=a.getSelectedTier();if(!(h<0)){j=a.tiers[h];h=j.forceHeight||j.subtiers[0].height;if(h>=40){j.forceHeight=h-10;j.draw()}}}else if(h.ctrlKey){h=a.getSelectedTier();if(!(h<0)){j=a.tiers[h];if(j.quantLeapThreshold){i=j.subtiers[0].height;var o=j.subtiers[0].quant;if(o){h=1*o.min;
  o=1*o.max;i=(o-h)/i;j.quantLeapThreshold=h+((Math.round((j.quantLeapThreshold-h)/i)|0)+1)*i;j.draw()}}}}else{h=a.getSelectedTier();h>0?a.setSelectedTier(h-1):a.notifyTierSelectionWrap(-1)}}else if(h.keyCode==40||h.keyCode==83){h.stopPropagation();h.preventDefault();if(h.shiftKey){h=a.getSelectedTier();if(!(h<0)){j=a.tiers[h];h=j.forceHeight||j.subtiers[0].height;j.forceHeight=h+10;j.draw()}}else if(h.ctrlKey){h=a.getSelectedTier();if(!(h<0)){j=a.tiers[h];if(j.quantLeapThreshold){i=j.subtiers[0].height;
  if(o=j.subtiers[0].quant){h=1*o.min;o=1*o.max;i=(o-h)/i;o=Math.round((j.quantLeapThreshold-h)/i)|0;if(o>1){j.quantLeapThreshold=h+(o-1)*i;j.draw()}}}}}else{h=a.getSelectedTier();h<a.tiers.length-1&&a.setSelectedTier(h+1)}}else if(h.keyCode==187||h.keyCode==61){h.stopPropagation();h.preventDefault();a.zoomStep(-10)}else if(h.keyCode==189||h.keyCode==173){h.stopPropagation();h.preventDefault();a.zoomStep(10)}else if(h.keyCode==73||h.keyCode==105){h.stopPropagation();h.preventDefault();h=a.getSelectedTier();
  if(!(h<0)){i=a.tiers[h];if(i.infoVisible){i.infoElement.style.display="none";i.updateHeight();i.infoVisible=false}else{i.infoElement.style.display="block";i.updateHeight();i.infoVisible=true}}}else if(h.keyCode==84||h.keyCode==116)if(h.shiftKey){h.stopPropagation();h.preventDefault();for(h=0;h<a.tiers.length;++h){i=a.tiers[h];if(i.dasSource.collapseSuperGroups){if(j===undefined)j=!i.bumped;i.bumped=j;i.layoutWasDone=false;i.draw();i.updateLabel()}}}else{if(!h.ctrlKey&&!h.metaKey){h.stopPropagation();
  h.preventDefault();h=a.getSelectedTier();if(!(h<0)){i=a.tiers[h];if(i.dasSource.collapseSuperGroups){if(j===undefined)j=!i.bumped;i.bumped=j;i.layoutWasDone=false;i.draw();i.updateLabel()}}}}else if(h.keyCode==77||h.keyCode==109){h.stopPropagation();h.preventDefault();a.selectedTiers.length>1&&a.mergeSelectedTiers()}};this.browserHolder.addEventListener("focus",function(){a.browserHolder.addEventListener("keydown",b,false)},false);this.browserHolder.addEventListener("blur",function(){a.browserHolder.removeEventListener("keydown",
  b,false)},false);this.hPopupHolder=makeElement("div");this.hPopupHolder.style["font-family"]="helvetica";this.hPopupHolder.style["font-size"]="12pt";this.hPopupHolder.classList.add("dalliance");document.body.appendChild(this.hPopupHolder);for(var c=0;c<this.sources.length;++c){var d=this.sources[c];if(d.bwgURI&&!this.supportsBinary){if(!this.binaryWarningGiven){this.popit({clientX:300,clientY:100},"Warning",makeElement("p","your browser does not support binary data formats, some track(s) not loaded.  We currently recommend Google Chrome 9 or later, or Firefox 4 or later."));
  this.binaryWarningGiven=true}}else this.makeTier(d)}a.arrangeTiers();a.refresh();a.setSelectedTier(1);a.positionRuler();for(d=0;d<this.tiers.length;++d){c=this.tiers[d];if(c.sequenceSource){c.sequenceSource.getSeqInfo(this.chr,function(h){if(h)a.currentSeqMax=h.length});break}}this.queryRegistry();for(var e in this.chains)this.queryRegistry(e,true);if(this.hubs)for(c=0;c<this.hubs.length;++c)connectTrackHub(this.hubs[c],function(h,j){j?console.log(j):a.hubObjects.push(h)})};
  Browser.prototype.touchStartHandler=function(a){a.stopPropagation();a.preventDefault();this.touchOriginX=a.touches[0].pageX;if(a.touches.length==2){a=Math.abs(a.touches[0].pageX-a.touches[1].pageX);this.zooming=true;this.zoomLastSep=this.zoomInitialSep=a;this.zoomInitialScale=this.scale}};
  Browser.prototype.touchMoveHandler=function(a){a.stopPropagation();a.preventDefault();if(a.touches.length==1){var b=a.touches[0].pageX;this.touchOriginX&&b!=this.touchOriginX&&this.move(b-this.touchOriginX);this.touchOriginX=b}else if(this.zooming&&a.touches.length==2){b=Math.abs(a.touches[0].pageX-a.touches[1].pageX);if(b!=this.zoomLastSep){a=(a.touches[0].pageX+a.touches[1].pageX)/2;var c=this.viewStart+a/this.scale|0;this.scale=this.zoomInitialScale*(b/this.zoomInitialSep);this.viewStart=c-a/this.scale|
  0;for(a=0;a<this.tiers.length;++a)this.tiers[a].draw()}this.zoomLastSep=b}};Browser.prototype.touchEndHandler=function(a){a.stopPropagation();a.preventDefault()};Browser.prototype.touchCancelHandler=function(){};Browser.prototype.makeTier=function(a){try{this.realMakeTier(a)}catch(b){console.log(b.stack)}};
  Browser.prototype.realMakeTier=function(a){var b=this,c=this.tierBackgroundColors[this.tiers.length%this.tierBackgroundColors.length],d=makeElement("canvas",null,{width:""+((this.featurePanelWidth|0)+2E3),height:"50",className:"viewport"}),e=makeElement("canvas",null,{width:+((this.featurePanelWidth|0)+2E3),height:"50",className:"viewport-overlay"}),h=makeElement("span",""),j=makeElement("div",[makeElement("i",null,{className:"icon-warning-sign"})," ",h],{className:"placard"}),i=makeElement("div",
  [d,e],{className:"view-holder"});i.style.background=c;i.addEventListener("touchstart",function(A){return b.touchStartHandler(A)},false);i.addEventListener("touchmove",function(A){return b.touchMoveHandler(A)},false);i.addEventListener("touchend",function(A){return b.touchEndHandler(A)},false);i.addEventListener("touchcancel",function(A){return b.touchCancelHandler(A)},false);var l=new DasTier(this,a,d,i,e,j,h);l.oorigin=this.viewStart;l.background=c;l.quantOverlay=makeElement("canvas",null,{width:"50",
  height:"56",className:"quant-overlay"});l.holder.appendChild(l.quantOverlay);var m=false,o,r,p,t=function(A,B){var G=l.subtiers;if(G){var E=0;for(B-=MIN_PADDING;E<G.length&&B>G[E].height&&E<G.length-1;){B=B-G[E].height-MIN_PADDING;++E}if(!(E>=G.length)){G=G[E].glyphs;A-=(l.glyphCacheOrigin-b.viewStart)*b.scale;return glyphLookup(G,A)}}},q=function(A){A.preventDefault();A.stopPropagation();A=A.clientX;if(l.dasSource.tier_type!=="sequence"&&A!=r){b.move(A-r);r=A}b.isDragging=true},s=function(){window.removeEventListener("mousemove",
  q,true);window.removeEventListener("mouseup",s,true)};i.addEventListener("mousedown",function(A){b.browserHolder.focus();A.preventDefault();i.getBoundingClientRect();A=A.clientX;window.addEventListener("mousemove",q,true);window.addEventListener("mouseup",s,true);o=r=A;b.isDragging=false},false);i.addEventListener("mousemove",function(A){var B=i.getBoundingClientRect(),G=A.clientX-B.left,E=A.clientY-B.top;p&&clearTimeout(p);m||(p=setTimeout(function(){var P=t(G,E);P&&P.length>0&&b.notifyFeatureHover(A,
  P[P.length-1],P,l)},1E3))});var u=null;i.addEventListener("mouseup",function(A){var B=i.getBoundingClientRect(),G=A.clientX-B.left;B=A.clientY-B.top;var E=t(G,B);if(E&&E.length>0&&!b.isDragging)if(u){clearTimeout(u);u=null;b.featureDoubleClick(E,G,B)}else u=setTimeout(function(){u=null;b.notifyFeature(A,E[E.length-1],E,l)},500);if(b.isDragging&&G!=o&&l.dasSource.tier_type==="sequence"){B=b.viewStart+G/b.scale;var P=b.viewStart+o/b.scale;if(B<P){G=B|0;B=P|0}else{G=P|0;B=B|0}b.notifyRegionSelect(b.chr,
  G,B)}b.isDragging=false},false);i.addEventListener("mouseout",function(){m=false});l.removeButton=makeElement("i",null,{className:"icon-remove"});l.bumpButton=makeElement("i",null,{className:"icon-plus-sign"});l.loaderButton=makeElement("img",null,{src:this.uiPrefix+"img/loader.gif"},{display:"none"});l.infoElement=makeElement("div",l.dasSource.desc,{},{display:"none",maxWidth:"200px",whiteSpace:"normal",color:"rgb(100,100,100)"});l.nameButton=makeElement("a",[],{className:"tier-tab"});l.nameButton.appendChild(l.removeButton);
  a.pennant&&l.nameButton.appendChild(makeElement("img",null,{src:a.pennant,width:"16",height:"16"}));l.nameButton.appendChild(makeElement("span",[a.name,l.infoElement],{},{display:"inline-block",marginLeft:"5px",marginRight:"5px"}));l.nameButton.appendChild(l.bumpButton);l.nameButton.appendChild(l.loaderButton);l.label=makeElement("span",[l.nameButton],{className:"btn-group"},{zIndex:1001,position:"absolute",left:"2px",top:"2px",opacity:0.8,display:"inline-block"});c=makeElement("div",[i,j,l.label],
  {},{position:"relative",display:"block"});l.row=c;l.removeButton.addEventListener("click",function(A){A.stopPropagation();A.preventDefault();b.removeTier(a)},false);l.nameButton.addEventListener("click",function(A){A.stopPropagation();A.preventDefault();if(A.shiftKey){A=-1;for(var B=0;B<b.tiers.length;++B)if(b.tiers[B]===l){A=B;break}if(A>=0){B=b.selectedTiers.indexOf(A);if(B>=0)b.selectedTiers.splice(B,1);else{b.selectedTiers.push(A);b.selectedTiers.sort()}b.markSelectedTiers();b.selectedTiers.length>
  0?b.browserHolder.focus():b.notifyTierSelectionWrap(-1)}}else{for(B=0;B<b.tiers.length;++B)if(b.tiers[B]===l){b.browserHolder.focus();if(b.selectedTiers.length!=1||b.selectedTiers[0]!=B){b.setSelectedTier(B);return}}if(l.infoVisible){l.infoElement.style.display="none";l.updateHeight();l.infoVisible=false}else{l.infoElement.style.display="block";l.updateHeight();l.infoVisible=true}}},false);l.bumpButton.addEventListener("click",function(A){A.stopPropagation();A.preventDefault();var B;if(l.dasSource.collapseSuperGroups){if(B===
  undefined)B=!l.bumped;l.bumped=B;l.layoutWasDone=false;l.draw();l.updateLabel()}},false);var v,w,z,x=false,D=function(A){var B=l.label;A.stopPropagation();A.preventDefault();if(!v){v=B.cloneNode(true);v.style.cursor="pointer";b.svgHolder.appendChild(v);B.style.visibility="hidden";for(var G=0;G<b.tiers.length;++G)if(b.tiers[G]===l){w=G;break}z=A.clientY}G=b.svgHolder.getBoundingClientRect();v.style.left=B.getBoundingClientRect().left-G.left+"px";v.style.top=A.clientY-G.top-10+"px";B=A.clientY-b.tierHolder.getBoundingClientRect().top;
  for(G=0;G<b.tiers.length;++G){var E=b.tiers[G].row.getBoundingClientRect();B-=E.bottom-E.top;if(B<0){if(G<w&&A.clientY<z||G>w&&A.clientY>z){B=[];for(E=0;E<b.selectedTiers.length;++E)B.push(b.tiers[b.selectedTiers[E]]);b.tiers.splice(w,1);b.tiers.splice(G,0,l);E=b.sources[w];b.sources.splice(w,1);b.sources.splice(G,0,E);b.selectedTiers=[];for(E=0;E<b.tiers.length;++E)B.indexOf(b.tiers[E])>=0&&b.selectedTiers.push(E);w=G;z=A.clientY;removeChildren(b.tierHolder);for(A=0;A<b.tiers.length;++A)b.tierHolder.appendChild(b.tiers[A].row);
  b.tierHolder.appendChild(b.ruler);x=true;b.arrangeTiers()}break}}},C=function(A){var B=l.label;A.stopPropagation();A.preventDefault();if(v){v.style.cursor="auto";b.svgHolder.removeChild(v);v=null;B.style.visibility=null}document.removeEventListener("mousemove",D,false);document.removeEventListener("mouseup",C,false);if(x){for(A=0;A<b.tiers.length;++A)if(b.tiers[A]==l){b.setSelectedTier(A);break}b.notifyTier()}};l.label.addEventListener("mousedown",function(A){A.stopPropagation();A.preventDefault();
  x=false;document.addEventListener("mousemove",D,false);document.addEventListener("mouseup",C,false)},false);this.tierHolder.appendChild(c);this.tiers.push(l);l.init();l.currentlyHeight=50;this.updateHeight();l.updateLabel();l.featureSource&&l.featureSource.addActivityListener&&l.featureSource.addActivityListener(function(A){l.loaderButton.style.display=A>0?"inline-block":"none"})};Browser.prototype.refreshTier=function(a){this.knownSpace&&this.knownSpace.invalidate(a)};
  Browser.prototype.arrangeTiers=function(){for(var a=0;a<this.tiers.length;++a){var b=this.tiers[a];b.background=this.tierBackgroundColors[a%this.tierBackgroundColors.length];b.holder.style.background=b.background}};
  Browser.prototype.refresh=function(){this.notifyLocation();var a=100/this.scale|0,b=1E3/this.scale|0,c=(this.viewStart+this.viewEnd)/2,d=c-this.origin;this.origin=c;this.scaleAtLastRedraw=this.scale;for(c=0;c<this.tiers.length;++c){var e=d;if(this.tiers[c].originHaxx)e+=this.tiers[c].originHaxx;this.tiers[c].originHaxx=e}d=this.targetQuantRes/this.scale;c=Math.max(1,(this.viewStart|0)-a);a=Math.min((this.viewEnd|0)+a,(this.currentSeqMax|0)>0?this.currentSeqMax|0:1E9);e=Math.max(1,(this.viewStart|
  0)-b);b=Math.min((this.viewEnd|0)+b,(this.currentSeqMax|0)>0?this.currentSeqMax|0:1E9);if(!this.knownSpace||this.knownSpace.chr!==this.chr){for(var h=null,j=0;j<this.tiers.length;++j)if(this.tiers[j].sequenceSource){h=this.tiers[j].sequenceSource;break}this.knownSpace=new KnownSpace(this.tiers,this.chr,e,b,d,h)}if((h=this.knownSpace.bestCacheOverlapping(this.chr,c,a))&&h.min<=c&&h.max>=a){this.drawnStart=Math.max(h.min,e);this.drawnEnd=Math.min(h.max,b)}else{this.drawnStart=e;this.drawnEnd=b}this.knownSpace.viewFeatures(this.chr,
  this.drawnStart,this.drawnEnd,d);this.drawOverlays()};function setSources(a,b,c){if(c)for(var d=0;d<b.length;++d)b[d].mapping=c;a.set(b)}
  Browser.prototype.queryRegistry=function(a,b){var c,d;if(a){c=this.chains[a].coords;this.mappableSources[a]||(this.mappableSources[a]=new Observed);d=this.mappableSources[a]}else{c=this.coordSystem;d=this.availableSources}var e=hex_sha1(miniJSONify(c));if(b){var h=localStorage["dalliance.registry."+e+".last_queried"];if(h)try{setSources(d,JSON.parse(localStorage["dalliance.registry."+e+".sources"]),a);if((Date.now()|0)-(h|0)<432E5)return}catch(j){console.log("Bad registry cache: "+j)}}(new DASRegistry(this.registry)).sources(function(i){for(var l=
  [],m=0;m<i.length;++m){var o=i[m];if(!(!o.coords||o.coords.length==0)){var r=o.coords[0];r.taxon!=c.taxon||r.auth!=c.auth||r.version!=c.version||l.push(o)}}localStorage["dalliance.registry."+e+".sources"]=JSON.stringify(l);localStorage["dalliance.registry."+e+".last_queried"]=""+Date.now();setSources(d,l,a)},function(){},c)};
  Browser.prototype.move=function(a){var b=this.viewEnd-this.viewStart;this.viewStart-=a/this.scale;this.viewEnd=this.viewStart+b;if(this.currentSeqMax>0&&this.viewEnd>this.currentSeqMax){this.viewEnd=this.currentSeqMax;this.viewStart=this.viewEnd-b}if(this.viewStart<1){this.viewStart=1;this.viewEnd=this.viewStart+b}this.notifyLocation();for(a=0;a<this.tiers.length;++a){this.tiers[a].viewport.style.left=""+((-((this.viewStart-this.tiers[a].norigin)*this.scale)|0)-1E3)+"px";this.tiers[a].overlay.style.left=
  ""+((-((this.viewStart-this.tiers[a].oorigin)*this.scale)|0)-1E3)+"px"}this.spaceCheck()};Browser.prototype.zoomStep=function(a){var b=1*this.zoomSliderValue;a=b+a;if(a<this.zoomMin)a=this.zoomMin;if(a>this.zoomMax)a=this.zoomMax;if(a!=b){this.zoomSliderValue=a;this.zoom(Math.exp(1*a/this.zoomExpt))}};
  Browser.prototype.zoom=function(a){this.zoomFactor=a;a=Math.round((this.viewStart+this.viewEnd)/2)|0;this.viewStart=a-this.zoomBase*this.zoomFactor/2;this.viewEnd=a+this.zoomBase*this.zoomFactor/2;if(this.currentSeqMax>0&&this.viewEnd>this.currentSeqMax+5){a=this.viewEnd-this.viewStart+1;this.viewEnd=this.currentSeqMax;this.viewStart=this.viewEnd-a+1}if(this.viewStart<1){a=this.viewEnd-this.viewStart+1;this.viewStart=1;this.viewEnd=this.viewStart+a-1}this.scale=this.featurePanelWidth/(this.viewEnd-
  this.viewStart);this.refresh()};Browser.prototype.spaceCheck=function(){if(!this.knownSpace||this.knownSpace.chr!==this.chr)this.refresh();else{var a=100/this.scale|0;if((this.drawnStart|0)>Math.max(1,(this.viewStart|0)-a|0)||(this.drawnEnd|0)<Math.min((this.viewEnd|0)+a,(this.currentSeqMax|0)>0?this.currentSeqMax|0:1E9))this.refresh()}};
  Browser.prototype.resizeViewer=function(a){var b=this.featurePanelWidth;this.featurePanelWidth=this.tierHolder.getBoundingClientRect().width|0|0;if(b!=this.featurePanelWidth){this.viewEnd=this.viewStart+(this.viewEnd-this.viewStart)*this.featurePanelWidth/b;b=this.viewEnd-this.viewStart+1;if(this.currentSeqMax>0&&this.viewEnd>this.currentSeqMax){this.viewEnd=this.currentSeqMax;this.viewStart=this.viewEnd-b+1}if(this.viewStart<1){this.viewStart=1;this.viewEnd=this.viewStart+b-1}this.positionRuler();
  a||this.spaceCheck();this.notifyLocation()}};Browser.prototype.addTier=function(a){this.sources.push(a);this.makeTier(a);this.positionRuler();this.notifyTier()};function sourceDataURI(a){if(a.uri)return a.uri;else if(a.bwgBlob)return"file:"+a.bwgBlob.name;else if(a.bamBlob)return"file:"+a.bamBlob.name;return a.bwgURI||a.bamURI||a.jbURI||a.twoBitURI||"http://www.biodalliance.org/magic/no_uri"}
  function sourceStyleURI(a){return a.stylesheet_uri?a.stylesheet_uri:a.tier_type=="sequence"?"http://www.biodalliance.org/magic/sequence":sourceDataURI(a)}function sourcesAreEqual(a,b){if(sourceDataURI(a)!=sourceDataURI(b)||sourceStyleURI(a)!=sourceStyleURI(b))return false;if(a.overlay){if(!b.overlay||b.overlay.length!=a.overlay.length)return false;for(var c=0;c<a.overlay.length;++c)if(!sourcesAreEqual(a.overlay[c],b.overlay[c]))return false}else if(b.overlay)return false;return true}
  Browser.prototype.removeTier=function(a){var b=-1;if(typeof a.index!=="undefined"&&a.index>=0&&a.index<this.tiers.length)b=a.index;else for(var c=0;c<this.tiers.length;++c)if(sourcesAreEqual(a,this.tiers[c].dasSource)){b=c;break}if(b<0)throw"Couldn't find requested tier";this.tierHolder.removeChild(this.tiers[b].row);this.tiers.splice(b,1);this.sources.splice(b,1);a=[];for(c=0;c<this.selectedTiers.length;++c){var d=this.selectedTiers[c];if(d<b)a.push(d);else d>b&&a.push(d-1)}this.selectedTiers=a;
  this.markSelectedTiers();this.arrangeTiers();this.notifyTier()};
  Browser.prototype.setLocation=function(a,b,c,d){d||(d=function(i){if(i)throw i;});var e=this;if(!a||a==this.chr)return this._setLocation(null,b,c,null,d);else{for(var h,j=0;j<this.tiers.length;++j)if(this.tiers[j].sequenceSource){h=this.tiers[j].sequenceSource;break}if(!h)return d("Need a sequence source");h.getSeqInfo(a,function(i){if(i)return e._setLocation(a,b,c,i,d);else{var l;l=a.indexOf("chr")==0?a.substr(3):"chr"+a;h.getSeqInfo(l,function(m){return m?e._setLocation(l,b,c,m,d):d("Couldn't find sequence '"+
  a+"'")})}})}};
  Browser.prototype._setLocation=function(a,b,c,d,e){if(a){if(a.indexOf("chr")==0)a=a.substring(3);this.chr=a;this.currentSeqMax=d.length}b|=0;c|=0;a=Math.max(10,c-b+1);if(b<1){b=1;c=b+a-1}if(c>this.currentSeqMax){c=this.currentSeqMax;b=Math.max(1,c-a+1)}this.viewStart=b;this.viewEnd=c;b=this.featurePanelWidth/(this.viewEnd-this.viewStart);c=Math.abs(b-this.scale)>1.0E-4;this.scale=b;this.zoomSliderValue=this.zoomExpt*Math.log((this.viewEnd-this.viewStart+1)/this.zoomBase);this.isSnapZooming=false;
  this.savedZoom=null;this.notifyLocation();if(c)this.refresh();else for(b=0;b<this.tiers.length;++b){this.tiers[b].viewport.style.left=""+((-((this.viewStart-this.tiers[b].norigin)*this.scale)|0)-1E3)+"px";this.tiers[b].overlay.style.left=""+((-((this.viewStart-this.tiers[b].oorigin)*this.scale)|0)-1E3)+"px"}this.spaceCheck();return e()};Browser.prototype.addFeatureListener=function(a){this.featureListeners.push(a)};
  Browser.prototype.notifyFeature=function(a,b,c,d){for(var e=0;e<this.featureListeners.length;++e)try{this.featureListeners[e](a,b,c,d)}catch(h){console.log(h.stack)}};Browser.prototype.addFeatureHoverListener=function(a){this.featureHoverListeners.push(a)};Browser.prototype.notifyFeatureHover=function(a,b,c,d){for(var e=0;e<this.featureHoverListeners.length;++e)try{this.featureHoverListeners[e](a,b,c,d)}catch(h){console.log(h.stack)}};Browser.prototype.addViewListener=function(a){this.viewListeners.push(a)};
  Browser.prototype.notifyLocation=function(){for(var a=0;a<this.viewListeners.length;++a)try{this.viewListeners[a](this.chr,this.viewStart|0,this.viewEnd|0,this.zoomSliderValue,{current:this.zoomSliderValue,min:this.zoomMin,max:this.zoomMax})}catch(b){console.log(b.stack)}};Browser.prototype.addTierListener=function(a){this.tierListeners.push(a)};Browser.prototype.notifyTier=function(){for(var a=0;a<this.tierListeners.length;++a)try{this.tierListeners[a]()}catch(b){console.log(b.stack)}};
  Browser.prototype.addRegionSelectListener=function(a){this.regionSelectListeners.push(a)};Browser.prototype.notifyRegionSelect=function(a,b,c){for(var d=0;d<this.regionSelectListeners.length;++d)try{this.regionSelectListeners[d](a,b,c)}catch(e){console.log(e.stack)}};Browser.prototype.highlightRegion=function(a,b,c){this.highlights.push(new Region(a,b,c));var d=this.viewStart-1E3/this.scale,e=this.viewEnd+1E3/this.scale;a==this.chr&&b<e&&c>d&&this.drawOverlays()};
  Browser.prototype.drawOverlays=function(){for(var a=0;a<this.tiers.length;++a)this.tiers[a].drawOverlay()};Browser.prototype.featuresInRegion=function(a,b,c){var d=[];if(a!==this.chr)return[];for(a=0;a<this.tiers.length;++a)for(var e=this.tiers[a].currentFeatures||[],h=0;h<e.length;++h){var j=e[h];j.min<=c&&j.max>=b&&d.push(j)}return d};Browser.prototype.getSelectedTier=function(){return this.selectedTiers.length>0?this.selectedTiers[0]:-1};
  Browser.prototype.setSelectedTier=function(a){this.selectedTiers=[a];this.markSelectedTiers()};Browser.prototype.markSelectedTiers=function(){for(var a=0;a<this.tiers.length;++a){var b=this.tiers[a].nameButton;this.selectedTiers.indexOf(a)>=0?b.classList.add("active"):b.classList.remove("active")}this.selectedTiers.length>0&&this.browserHolder.focus()};Browser.prototype.addTierSelectionWrapListener=function(a){this.tierSelectionWrapListeners.push(a)};
  Browser.prototype.notifyTierSelectionWrap=function(a){for(var b=0;b<this.tierSelectionWrapListeners.length;++b)try{this.tierSelectionWrapListeners[b](a)}catch(c){console.log(c.stack)}};
  Browser.prototype.positionRuler=function(){var a="none",b="",c="";if(this.rulerLocation=="center"){a="block";b=""+(this.featurePanelWidth/2|0)+"px"}else if(this.rulerLocation=="left"){a="block";b="0px"}else if(this.rulerLocation=="right"){a="block";c="0px"}else a="none";this.ruler.style.display=a;this.ruler.style.left=b;this.ruler.style.right=c;for(var d=0;d<this.tiers.length;++d){var e=this.tiers[d].quantOverlay;if(e){e.style.display=a;e.style.left=b;e.style.right=c}}};
  Browser.prototype.featureDoubleClick=function(a,b){if(!(!a||a.length==0)){f=a[a.length-1];if(f.min&&f.max){var c=((f.min|0)-(this.viewStart|0))*this.scale,d=(f.max-f.min+1)*this.scale,e=((f.min|0)+(f.max|0))/2;if(d>10){c=1*(b-c)/d;if(c<0.3)e=f.min|0;else if(c>0.7)e=(f.max|0)+1}c=this.viewEnd-this.viewStart;this.setLocation(null,e-c/2,e+c/2)}}};
  Browser.prototype.updateHeight=function(){for(var a=0,b=0;b<this.tiers.length;++b)a+=this.tiers[b].currentHeight||30;this.svgHolder.style.maxHeight=""+Math.max(a,500)+"px"};function glyphLookup(a,b,c){c=c||[];for(var d=0;d<a.length;++d){var e=a[d];if(!e.notSelectable&&e.min()<=b&&e.max()>=b){if(e.feature)c.push(e.feature);else e.group&&c.push(e.group);return e.glyphs?glyphLookup(e.glyphs,b,c):e.glyph?glyphLookup([e.glyph],b,c):c}}return c}var TAGVAL_NOTE_RE=/^([A-Za-z]+)=(.+)/;
  Browser.prototype.addFeatureInfoPlugin=function(a){if(!this.featureInfoPlugins)this.featureInfoPlugins=[];this.featureInfoPlugins.push(a)};function FeatureInfo(a,b,c){var d=pick(c.type,b.type),e=pick(c.label,b.label,c.id,b.id);if(e&&e.indexOf("__dazzle")!=0)d=d+": "+e;this.hit=a;this.feature=b;this.group=c;this.title=d;this.sections=[]}FeatureInfo.prototype.setTitle=function(a){this.title=a};
  FeatureInfo.prototype.add=function(a,b){if(typeof b==="string")b=makeElement("span",b);this.sections.push({label:a,info:b})};
  Browser.prototype.featurePopup=function(a,b,c,d){b=c.length;var e=--b>=0?c[b]:{},h=--b>=0?c[b]:{};c=new FeatureInfo(c,e,h);b=this.featureInfoPlugins||[];for(fipi=0;fipi<b.length;++fipi)try{b[fipi](e,c)}catch(j){console.log(j.stack||j)}b=d.featureInfoPlugins||[];for(fipi=0;fipi<b.length;++fipi)try{b[fipi](e,c)}catch(i){console.log(i.stack||i)}this.removeAllPopups();d=makeElement("table",null,{className:"table table-striped table-condensed"});d.style.width="100%";d.style.margin="0px";b=0;if(e.method){var l=
  makeElement("tr",[makeElement("th","Method"),makeElement("td",e.method)]);d.appendChild(l);++b}l=h.segment?h:e;l=makeElement("tr",[makeElement("th","Location"),makeElement("td",l.segment+":"+l.min+"-"+l.max)]);l.style.backgroundColor=this.tierBackgroundColors[b%this.tierBackgroundColors.length];d.appendChild(l);++b;if(e.score!==undefined&&e.score!==null&&e.score!="-"){l=makeElement("tr",[makeElement("th","Score"),makeElement("td",""+e.score)]);d.appendChild(l);++b}if((l=maybeConcat(h.links,e.links))&&
  l.length>0){l=makeElement("tr",[makeElement("th","Links"),makeElement("td",l.map(function(r){return makeElement("div",makeElement("a",r.desc,{href:r.uri,target:"_new"}))}))]);d.appendChild(l);++b}e=maybeConcat(h.notes,e.notes);for(h=0;h<e.length;++h){l="Note";var m=e[h],o=m.match(TAGVAL_NOTE_RE);if(o){l=o[1];m=o[2]}l=makeElement("tr",[makeElement("th",l),makeElement("td",m)]);d.appendChild(l);++b}for(b=0;b<c.sections.length;++b){e=c.sections[b];d.appendChild(makeElement("tr",[makeElement("th",e.label),
  makeElement("td",e.info)]))}this.popit(a,c.title,d,{width:400})};function Chainset(a,b,c,d){this.uri=a;this.srcTag=b;this.destTag=c;this.coords=d;this.chainsBySrc={};this.chainsByDest={};this.postFetchQueues={}}function parseCigar(a){for(var b=[],c=RegExp("([0-9]*)([MID])","g"),d;(d=c.exec(a))!=null;){var e=d[1];if(e.length==0)e=1;b.push({cnt:e|0,op:d[2]})}return b}
  Chainset.prototype.fetchChainsTo=function(a){var b=this;(new DASSource(this.uri)).alignments(a,{},function(c){b.chainsByDest[a]||(b.chainsByDest[a]=[]);for(var d=0;d<c.length;++d)for(var e=c[d],h=0;h<e.blocks.length;++h){for(var j=e.blocks[h],i,l,m=0;m<j.segments.length;++m){var o=j.segments[m],r=e.objects[o.object];if(r.dbSource===b.srcTag)i=o;else if(r.dbSource===b.destTag)l=o}if(i&&l){j={srcChr:e.objects[i.object].accession,srcMin:i.min|0,srcMax:i.max|0,srcOri:i.strand,destChr:e.objects[l.object].accession,
  destMin:l.min|0,destMax:l.max|0,destOri:l.strand,blocks:[]};m=parseCigar(i.cigar);o=parseCigar(l.cigar);for(var p=r=0,t=0,q=0;t<m.length&&q<o.length;)if(m[t].op=="M"&&o[q].op=="M"){var s=Math.min(m[t].cnt,o[q].cnt);j.blocks.push([r,p,s]);if(m[t].cnt==s)++t;else m[t].cnt-=s;if(o[q].cnt==s)++q;else o[q]-=s;r+=s;p+=s}else if(m[t].op=="I")p+=m[t++].cnt;else if(o[q].op=="I")r+=o[q++].cnt;pusho(b.chainsBySrc,j.srcChr,j);pusho(b.chainsByDest,j.destChr,j)}}if(b.postFetchQueues[a]){c=b.postFetchQueues[a];
  for(d=0;d<c.length;++d)c[d]();b.postFetchQueues[a]=null}})};Chainset.prototype.mapPoint=function(a,b){for(var c=this.chainsBySrc[a]||[],d=0;d<c.length;++d){var e=c[d];if(b>=e.srcMin&&b<=e.srcMax){var h;h=e.srcOri=="-"?e.srcMax-b:b-e.srcMin;for(var j=e.blocks,i=0;i<j.length;++i){var l=j[i],m=l[0],o=l[1];l=l[2];if(h>=m&&h<=m+l){c=h-m;return{seq:e.destChr,pos:e.destOri=="-"?e.destMax-o-c:c+o+e.destMin,flipped:e.srcOri!=e.destOri}}}}}return null};
  Chainset.prototype.unmapPoint=function(a,b){for(var c=this.chainsByDest[a]||[],d=0;d<c.length;++d){var e=c[d];if(b>=e.destMin&&b<=e.destMax){d=e.srcOri=="-"?e.destMax-b:b-e.destMin;for(var h=e.blocks,j=0;j<h.length;++j){var i=h[j];c=i[0];var l=i[1];i=i[2];if(d>=l&&d<=l+i){d=d-l;h=d+c+e.srcMin;h=e.destOri=="-"?e.srcMax-c-d:d+c+e.srcMin;return{seq:e.srcChr,pos:h,flipped:e.srcOri!=e.destOri}}}return null}}return null};
  Chainset.prototype.sourceBlocksForRange=function(a,b,c,d){if(this.chainsByDest[a]){var e=this.unmapPoint(a,b),h=this.unmapPoint(a,c);!e||!h||e.seq!=h.seq?d([]):d([new DASSegment(e.seq,e.pos,h.pos)])}else{e=!this.postFetchQueues[a];var j=this;pusho(this.postFetchQueues,a,function(){j.sourceBlocksForRange(a,b,c,d)});e&&this.fetchChainsTo(a)}};function DColour(a,b,c,d){this.red=a|0;this.green=b|0;this.blue=c|0;if(d)this.name=d}
  DColour.prototype.toSvgString=function(){if(!this.name)this.name="rgb("+this.red+","+this.green+","+this.blue+")";return this.name};var palette={red:new DColour(255,0,0,"red"),green:new DColour(0,255,0,"green"),blue:new DColour(0,0,255,"blue"),yellow:new DColour(255,255,0,"yellow"),white:new DColour(255,255,255,"white"),black:new DColour(0,0,0,"black")},COLOR_RE=/^#([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})$/,CSS_COLOR_RE=/rgb\(([0-9]+),([0-9]+),([0-9]+)\)/;
  function dasColourForName(a){var b=palette[a];if(!b){if(b=COLOR_RE.exec(a))b=new DColour("0x"+b[1]|0,"0x"+b[2]|0,"0x"+b[3]|0,a);else if(b=CSS_COLOR_RE.exec(a))b=new DColour(b[1]|0,b[2]|0,b[3]|0,a);else{console.log("couldn't handle color: "+a);b=palette.black}palette[a]=b}return b}
  function makeGradient(a,b,c,d){var e=[];b=dasColourForName(b);c=dasColourForName(c);if(d){d=dasColourForName(d);for(var h=0;h<a;++h){var j=1*h/(a-1),i,l;if(j<0.5){i=b;l=c;j=j*2}else{i=c;l=d;j=j*2-1}i=(new DColour(i.red*(1-j)+l.red*j|0,i.green*(1-j)+l.green*j|0,i.blue*(1-j)+l.blue*j|0)).toSvgString();e.push(i)}}else for(h=0;h<a;++h){j=1*h/(a-1);i=(new DColour(b.red*(1-j)+c.red*j|0,b.green*(1-j)+c.green*j|0,b.blue*(1-j)+c.blue*j|0)).toSvgString();e.push(i)}return e}
  var dasLibErrorHandler=function(a){alert(a)},dasLibRequestQueue=[];function DASSegment(a,b,c,d){this.name=a;this.start=b;this.end=c;this.description=d}DASSegment.prototype.toString=function(){return this.name+":"+this.start+".."+this.end};DASSegment.prototype.isBounded=function(){return this.start&&this.end};DASSegment.prototype.toDASQuery=function(){var a="segment="+this.name;if(this.start&&this.end)a+=":"+this.start+","+this.end;return a};
  function DASSource(a,b){var c;if(typeof a=="string"){this.uri=a;c=b||{}}else c=a||{};for(var d in c)if(typeof c[d]!="function")this[d]=c[d];if(!this.coords)this.coords=[];if(!this.props)this.props={};if((this.dasBaseURI=this.uri)&&this.dasBaseURI.substr(this.uri.length-1)!="/")this.dasBaseURI+="/"}function DASCoords(){}function coordsMatch(a,b){return a.taxon==b.taxon&&a.auth==b.auth&&a.version==b.version}
  DASSource.prototype.entryPoints=function(a){this.doCrossDomainRequest(this.dasBaseURI+"entry_points",function(b){if(!b)return a([]);var c=[];b=b.getElementsByTagName("SEGMENT");for(var d=0;d<b.length;++d){var e=b[d],h=e.getAttribute("id"),j=e.getAttribute("size"),i;if(j){i=1;j=j|0}else{if(i=e.getAttribute("start"))i|=0;if(j=e.getAttribute("stop"))j|=0}var l=null;if(e.firstChild)l=e.firstChild.nodeValue;c.push(new DASSegment(h,i,j,l))}a(c)})};
  function DASSequence(a,b,c,d,e){this.name=a;this.start=b;this.end=c;this.alphabet=d;this.seq=e}
  DASSource.prototype.sequence=function(a,b){this.doCrossDomainRequest(this.dasBaseURI+"sequence?"+a.toDASQuery(),function(c){if(c){var d=[];c=c.getElementsByTagName("SEQUENCE");for(var e=0;e<c.length;++e){var h=c[e],j=h.getAttribute("id"),i=h.getAttribute("start"),l=h.getAttribute("stop"),m=null;if(h.firstChild){h=h.firstChild.nodeValue;m="";for(var o=0;;){var r=h.indexOf("\n",o);if(r>=0){m+=h.substring(o,r);o=r+1}else{m+=h.substring(o);break}}}d.push(new DASSequence(j,i,l,"DNA",m))}b(d)}else b([])})};
  function DASFeature(){}function DASGroup(){}function DASLink(a,b){this.desc=a;this.uri=b}
  DASSource.prototype.features=function(a,b,c){b=b||{};var d;if(this.features_uri)d=this.features_uri;else{var e=[];if(a)e.push(a.toDASQuery());else if(b.group){a=b.group;if(typeof a=="string")e.push("group_id="+a);else for(var h=0;h<a.length;++h)e.push("group_id="+a[h])}if(b.adjacent){a=b.adjacent;if(typeof a=="string")a=[a];for(h=0;h<a.length;++h)e.push("adjacent="+a[h])}if(b.type)if(typeof b.type=="string")e.push("type="+b.type);else for(a=0;a<b.type.length;++a)e.push("type="+b.type[a]);b.maxbins&&
  e.push("maxbins="+b.maxbins);if(e.length>0)d=this.dasBaseURI+"features?"+e.join(";");else c([],"No filters specified")}this.doCrossDomainRequest(d,function(j,i){if(j){for(var l=[],m={},o=j.getElementsByTagName("SEGMENT"),r=0;r<o.length;++r){var p=o[r],t=p.getAttribute("id");m[t]={min:p.getAttribute("start"),max:p.getAttribute("stop")};p=p.getElementsByTagName("FEATURE");for(var q=0;q<p.length;++q){var s=p[q],u=new DASFeature;u.segment=t;u.id=s.getAttribute("id");u.label=s.getAttribute("label");var v=
  elementValue(s,"START"),w=elementValue(s,"END");if((v|0)>(w|0)){u.min=w|0;u.max=v|0}else{u.min=v|0;u.max=w|0}v=s.getElementsByTagName("TYPE");if(v.length>0){v=v[0];if(v.firstChild)u.type=v.firstChild.nodeValue;u.typeId=v.getAttribute("id");u.typeCv=v.getAttribute("cvId")}u.type=elementValue(s,"TYPE");if(!u.type&&u.typeId)u.type=u.typeId;u.method=elementValue(s,"METHOD");(v=elementValue(s,"ORIENTATION"))||(v="0");u.orientation=v;u.score=elementValue(s,"SCORE");u.links=dasLinksOf(s);u.notes=dasNotesOf(s);
  v=s.getElementsByTagName("GROUP");for(w=0;w<v.length;++w){var z=v[w],x=new DASGroup;x.type=z.getAttribute("type");x.id=z.getAttribute("id");x.links=dasLinksOf(z);x.notes=dasNotesOf(z);if(u.groups)u.groups.push(x);else u.groups=Array(x)}if(u.notes)for(v=0;v<u.notes.length;++v){w=u.notes[v];if(w.indexOf("Genename=")==0){z=new DASGroup;z.type="gene";z.id=w.substring(9);if(u.groups)u.groups.push(z);else u.groups=Array(z)}}v=s.getElementsByTagName("PART");if(v.length>0){z=[];for(w=0;w<v.length;++w)z.push(v[w].getAttribute("id"));
  u.parts=z}v=s.getElementsByTagName("PARENT");if(v.length>0){s=[];for(w=0;w<v.length;++w)s.push(v[w].getAttribute("id"));u.parents=s}l.push(u)}}c(l,undefined,m)}else c([],"Failed request: "+(i.status==0?"server may not support CORS":"status="+i.status))},function(j){c([],j)})};function DASAlignment(a){this.type=a;this.objects={};this.blocks=[]}
  DASSource.prototype.alignments=function(a,b,c){var d=this.dasBaseURI+"alignment?query="+a;this.doCrossDomainRequest(d,function(e){if(e){var h=[];e=e.getElementsByTagName("alignment");for(var j=0;j<e.length;++j){for(var i=e[j],l=new DASAlignment(i.getAttribute("alignType")),m=i.getElementsByTagName("alignObject"),o=0;o<m.length;++o){var r=m[o];r={id:r.getAttribute("intObjectId"),accession:r.getAttribute("dbAccessionId"),version:r.getAttribute("objectVersion"),dbSource:r.getAttribute("dbSource"),dbVersion:r.getAttribute("dbVersion")};
  l.objects[r.id]=r}i=i.getElementsByTagName("block");for(m=0;m<i.length;++m){r=i[m];o={order:r.getAttribute("blockOrder"),segments:[]};r=r.getElementsByTagName("segment");for(var p=0;p<r.length;++p){var t=r[p];t={object:t.getAttribute("intObjectId"),min:t.getAttribute("start"),max:t.getAttribute("end"),strand:t.getAttribute("strand"),cigar:elementValue(t,"cigar")};o.segments.push(t)}l.blocks.push(o)}h.push(l)}c(h)}else c([],"Failed request "+d)})};function DASStylesheet(){this.styles=[]}
  DASStylesheet.prototype.pushStyle=function(a,b,c){a||(a={type:"default"});a=shallowCopy(a);if(b)a.zoom=b;a.style=c;this.styles.push(a)};function DASStyle(){}
  DASSource.prototype.stylesheet=function(a,b){var c,d=this.credentials;if(this.stylesheet_uri){c=this.stylesheet_uri;d=false}else c=this.dasBaseURI+"stylesheet";doCrossDomainRequest(c,function(e){if(e){var h=new DASStylesheet;e=e.getElementsByTagName("TYPE");for(var j=0;j<e.length;++j){var i=e[j],l={};l.type=i.getAttribute("id");l.label=i.getAttribute("label");l.method=i.getAttribute("method");i=i.getElementsByTagName("GLYPH");for(var m=0;m<i.length;++m){var o=i[m],r=o.getAttribute("zoom"),p=childElementOf(o);
  o=new DASStyle;o.glyph=p.localName;for(p=p.firstChild;p;){if(p.nodeType==Node.ELEMENT_NODE)
  
  {
  	if (p.firstChild) {
  		o[p.localName]=p.firstChild.nodeValue;
  	}
  }
  
  
  p=p.nextSibling}h.pushStyle(l,r,o)}}a(h)}else b&&b()},d)};function DASRegistry(a,b){b=b||{};this.uri=a;this.opts=b}
  DASRegistry.prototype.sources=function(a,b,c){c||(c={});var d=[];c.taxon&&d.push("organism="+c.taxon);c.auth&&d.push("authority="+c.auth);c.version&&d.push("version="+c.version);c=this.uri;if(d.length>0)c=c+"?"+d.join("&");doCrossDomainRequest(c,function(e){if(!e&&b)b();else{var h=[];e=e.getElementsByTagName("SOURCE");for(var j=0;j<e.length;++j){var i=e[j],l=i.getElementsByTagName("VERSION");if(!(l.length<1)){var m=l[0],o=m.getElementsByTagName("COORDINATES");l=[];for(var r=0;r<o.length;++r){var p=
  o[r],t=new DASCoords;t.auth=p.getAttribute("authority");t.taxon=p.getAttribute("taxid");t.version=p.getAttribute("version");l.push(t)}o=[];p=m.getElementsByTagName("CAPABILITY");var q;for(r=0;r<p.length;++r){t=p[r];o.push(t.getAttribute("type"));if(t.getAttribute("type")=="das1:features"){q=t.getAttribute("query_uri");q=q.substring(0,q.length-8)}}r={};m=m.getElementsByTagName("PROP");for(p=0;p<m.length;++p)pusho(r,m[p].getAttribute("name"),m[p].getAttribute("value"));if(q){i=new DASSource(q,{source_uri:i.getAttribute("uri"),
  name:i.getAttribute("title"),desc:i.getAttribute("description"),coords:l,props:r,capabilities:o});h.push(i)}}}a(h)}})};function elementValue(a,b){var c=a.getElementsByTagName(b);return c.length>0&&c[0].firstChild?c[0].firstChild.nodeValue:null}function childElementOf(a){if(a.hasChildNodes()){a=a.firstChild;do{if(a.nodeType==Node.ELEMENT_NODE)return a;a=a.nextSibling}while(a!=null)}return null}
  function dasLinksOf(a){for(var b=[],c=a.getElementsByTagName("LINK"),d=0;d<c.length;++d){var e=c[d];if(e.parentNode==a)b.push(new DASLink(e.firstChild?e.firstChild.nodeValue:"Unknown",e.getAttribute("href")))}return b}function dasNotesOf(a){var b=[];a=a.getElementsByTagName("NOTE");for(var c=0;c<a.length;++c)a[c].firstChild&&b.push(a[c].firstChild.nodeValue);return b}
  function doCrossDomainRequest(a,b,c,d){if(window.XDomainRequest){var e=new XDomainRequest;e.onload=function(){var h=new ActiveXObject("Microsoft.XMLDOM");h.async=false;h.loadXML(e.responseText);b(h)};e.open("get",a)}else{Date.now();e=new XMLHttpRequest;e.onreadystatechange=function(){if(e.readyState==4)if(e.status>=200||e.status==0)b(e.responseXML,e)};e.open("get",a,true);if(c)e.withCredentials=true;d&&e.setRequestHeader("X-DAS-Authorisation",d);e.setRequestHeader("Accept","application/xml,*/*")}e.send("")}
  DASSource.prototype.doCrossDomainRequest=function(a,b,c){var d;if(this.xUser)d="Basic "+btoa(this.xUser+":"+this.xPass);try{return doCrossDomainRequest(a,b,this.credentials,d)}catch(e){if(c)c(e);else throw e;}};Browser.prototype.removeAllPopups=function(){removeChildren(this.hPopupHolder);removeChildren(this.popupHolder)};
  Browser.prototype.makeTooltip=function(a,b){var c=false,d=this,e=null,h;h=function(){c=false;if(e){clearTimeout(e);e=null}a.removeEventListener("mouseout",h,false)};var j;j=function(i){var l=i.clientX+window.scrollX,m=i.clientY+window.scrollY;e||(e=setTimeout(function(){var o=makeElement("div",[makeElement("div",null,{className:"tooltip-arrow"}),makeElement("div",b,{className:"tooltip-inner"})],{className:"tooltip bottom in"},{display:"block",top:""+(m+20)+"px",left:""+Math.max(l-30,20)+"px"});d.hPopupHolder.appendChild(o);
  var r;r=function(p){try{d.hPopupHolder.removeChild(o)}catch(t){}window.removeEventListener("mousemove",r,false);c&&a.offsetParent!=null&&j(p)};window.addEventListener("mousemove",r,false);e=null},1E3))};a.addEventListener("mouseover",function(i){c=true;a.addEventListener("mouseout",h,false);j(i)},false);a.addEventListener("DOMNodeRemovedFromDocument",function(){c=false;if(e){clearTimeout(e);e=null}},false)};
  Browser.prototype.popit=function(a,b,c,d){var e=this;d||(d={});a||(a={});var h=d.width||200,j;if(a.clientX){d=a.clientX;j=a.clientY}else{d=500;j=50}d+=document.documentElement.scrollLeft||document.body.scrollLeft;j+=document.documentElement.scrollTop||document.body.scrollTop;var i=window.innerWidth,l=j+20,m=Math.min(d-h/2,i-h-30),o=makeElement("div");o.className="popover fade "+(a.clientX?"bottom ":"")+"in";o.style.display="block";o.style.position="absolute";o.style.top=""+l+"px";o.style.left=""+
  m+"px";o.style.width=h+"px";if(h>276)o.style.maxWidth=h+"px";o.appendChild(makeElement("div",null,{className:"arrow"}));if(b){var r=makeElement("button","",{className:"close"});r.innerHTML="&times;";r.addEventListener("mouseover",function(){r.style.color="red"},false);r.addEventListener("mouseout",function(){r.style.color="black"},false);r.addEventListener("click",function(v){v.preventDefault();v.stopPropagation();e.removeAllPopups()},false);a=makeElement("h4",[makeElement("span",b,null,{maxWidth:"200px"}),
  r],{},{paddingLeft:"10px",paddingRight:"10px"});var p,t,q,s;q=function(v){v.stopPropagation();v.preventDefault();m+=v.clientX-p;if(m<8)m=8;if(m>i-h-32)m=i-h-26;l+=v.clientY-t;l=Math.max(10,l);o.style.top=""+l+"px";o.style.left=""+Math.min(m,i-h-10)+"px";p=v.clientX;t=v.clientY};s=function(v){v.stopPropagation();v.preventDefault();window.removeEventListener("mousemove",q,false);window.removeEventListener("mouseup",s,false)};a.addEventListener("mousedown",function(v){v.preventDefault();v.stopPropagation();
  p=v.clientX;t=v.clientY;window.addEventListener("mousemove",q,false);window.addEventListener("mouseup",s,false)},false);o.appendChild(a)}o.appendChild(makeElement("div",c,{className:"popover-content"},{padding:"0px"}));this.hPopupHolder.appendChild(o);var u={node:o,displayed:true};o.addEventListener("DOMNodeRemoved",function(v){if(v.target==o)u.displayed=false},false);return u};
  function makeTreeTableSection(a,b,c){function d(){if(c){e.className="icon-chevron-down";b.style.display="table"}else{e.className="icon-chevron-right";b.style.display="none"}}var e=makeElement("i");d();e.addEventListener("click",function(h){h.preventDefault();h.stopPropagation();c=!c;d()},false);a=makeElement("h6",[e," ",a],{},{display:"block",background:"gray",color:"white",width:"100%",padding:"5px 2px",margin:"0px"});return makeElement("div",[a,b],{})}function dlog(a){console.log(a)}
  var MIN_PADDING=3,DEFAULT_SUBTIER_MAX=25;function isDasBooleanTrue(a){a=(""+a).toLowerCase();return a==="yes"||a==="true"}function SubTier(){this.glyphs=[];this.height=0;this.quant=null}SubTier.prototype.add=function(a){this.glyphs.push(a);this.height=Math.max(this.height,a.height());if(a.quant&&this.quant==null)this.quant=a.quant};SubTier.prototype.hasSpaceFor=function(a){for(var b=0;b<this.glyphs.length;++b){var c=this.glyphs[b];if(c.min()<=a.max()&&c.max()>=a.min())return false}return true};var GLOBAL_GC;
  function drawFeatureTier(a){GLOBAL_GC=a.viewport.getContext("2d");sortFeatures(a);var b=[],c=false;for(var d in a.ungroupedFeatures){var e=a.ungroupedFeatures[d];if(c=a.styleForFeature(e[0]))if(c.glyph=="LINEPLOT"){b.push(makeLineGlyph(e,c,a));c=true}else for(var h=0;h<e.length;++h){c=e[h];if(!c.parts){var j=glyphForFeature(c,0,a.styleForFeature(c),a);j&&b.push(j)}}}if(a.dasSource.collapseSuperGroups&&!a.bumped)for(var i in a.superGroups){d=a.superGroups[i];a.groups[i].type=a.groups[d[0]].type;e=
  {};for(j=0;j<d.length;++j){var l=a.groupedFeatures[d[j]];for(h=0;h<l.length;++h){c=l[h];pusho(e,c.type,c)}if(a.groups[i]&&!a.groups[i].links||a.groups[i].links.length==0)a.groups[i].links=a.groups[d[0]].links;delete a.groupedFeatures[d[j]]}for(var m in e){l=e[m];var o=l[0],r=null;for(h=0;h<l.length;++h){c=l[h];c=new Range(c.min,c.max);r=r?union(r,c):c}r=r.ranges();for(var p=0;p<r.length;++p){var t=r[p],q=((t.max()|0)-(t.min()|0)+1)*d.length,s=0;for(h=0;h<l.length;++h){c=l[h];if((c.min|0)<=t.max()&&
  (c.max|0)>=t.min()){var u=Math.max(c.min|0,t.min());c=Math.min(c.max|0,t.max());s+=c-u+1}}c=new DASFeature;for(k in o)c[k]=o[k];c.min=t.min();c.max=t.max();if(c.label&&d.length>1)c.label+=" ("+d.length+" vars)";c.visualWeight=1*s/q;pusho(a.groupedFeatures,i,c)}}delete a.superGroups[i]}d=[];for(var v in a.groupedFeatures)d.push(v);d.sort(function(w,z){var x=a.groupedFeatures[w][0].score-a.groupedFeatures[z][0].score;return x>0?-1:x==0?0:1});m={};for(c=0;c<d.length;++c){v=d[c];if(j=glyphsForGroup(a.groupedFeatures[v],
  0,a.groups[v],a,a.dasSource.collapseSuperGroups&&!a.bumped?"collapsed_gene":"tent")){j.group=a.groups[v];m[v]=j}}for(i in a.superGroups){d=a.superGroups[i];v=[];c=1E10;e=-10000000000;for(h=0;h<d.length;++h){l=m[d[h]];m[d[h]]=null;if(l){v.push(l);c=Math.min(c,l.min());e=Math.max(e,l.max())}}for(h=0;h<v.length;++h){l=v[h];b.push(new PaddedGlyph(l,c,e))}}for(j in m)(l=m[j])&&b.push(l);i=new SubTier;v=[];c=false;d=a.dasSource.subtierMax||DEFAULT_SUBTIER_MAX;m=0;a:for(;m<b.length;++m){j=b[m];if(j.bump)c=
  true;if(j.bump&&(a.bumped||a.dasSource.collapseSuperGroups)){for(c=0;c<v.length;++c){e=v[c];if(e.hasSpaceFor(j)){e.add(j);continue a}}if(v.length>=d)a.status="Too many overlapping features, truncating at "+d;else{e=new SubTier;e.add(j);v.push(e)}}else i.add(j)}if(i.glyphs.length>0)v=[i].concat(v);for(c=0;c<v.length;++c){e=v[c];e.quant&&e.glyphs.unshift(new GridGlyph(e.height))}for(c=0;c<v.length;++c){e=v[c];e.glyphs.sort(function(w,z){return(w.zindex||0)-(z.zindex||0)})}a.subtiers=v;a.glyphCacheOrigin=
  a.browser.viewStart}function formatQuantLabel(a){a=""+a;var b=a.indexOf(".");if(b<0)return a;else{var c=2;a.substring(0,1)=="-"&&++c;return b>=c?a.substring(0,b):a.substring(0,b+2)}}
  DasTier.prototype.paint=function(){var a=this.subtiers;if(a){var b=this.viewport.width|0;if(b<this.browser.featurePanelWidth+1950)this.viewport.width=b=(this.browser.featurePanelWidth|0)+2E3;for(var c=MIN_PADDING,d=0;d<a.length;++d)c=c+a[d].height+MIN_PADDING;c+=6;this.viewport.setAttribute("height",c);this.viewport.style.left="-1000px";this.holder.style.height=""+Math.max(c,this.browser.minTierHeight)+"px";this.updateHeight();this.drawOverlay();this.norigin=this.browser.viewStart;var e=this.viewport.getContext("2d");
  e.fillStyle=this.background;e.clearRect(0,0,b,Math.max(c,200));e.restore();e.save();c=(this.glyphCacheOrigin-this.browser.viewStart)*this.browser.scale+1E3;e.translate(c,MIN_PADDING);for(d=0;d<a.length;++d){for(var h=null,j=a[d].glyphs,i=0;i<j.length;++i){var l=j[i];if(l.min()<b-c&&l.max()>-c){l=j[i];l.draw(e);if(l.quant)h=l.quant}}e.translate(0,a[d].height+MIN_PADDING)}e.restore();if(h&&this.quantLeapThreshold&&this.featureSource&&sourceAdapterIsCapable(this.featureSource,"quantLeap")){a=3+a[0].height*
  (1-(this.quantLeapThreshold-h.min)/(h.max-h.min));e.save();e.strokeStyle="red";e.lineWidth=0.3;e.moveTo(0,a);e.lineTo(5E3,a);e.stroke();e.restore()}this.paintQuant()}};
  DasTier.prototype.paintQuant=function(){var a;if(this.subtiers&&this.subtiers.length>0)a=this.subtiers[0].quant;if(a&&this.quantOverlay){var b=this.subtiers[0].height,c=this.quantOverlay.width;this.quantOverlay.height=this.viewport.height;var d=this.quantOverlay.getContext("2d");d.fillStyle="white";d.globalAlpha=0.6;if(this.browser.rulerLocation=="right"){d.fillRect(c-30,0,30,20);d.fillRect(c-30,b-20+MIN_PADDING*2,30,20)}else{d.fillRect(0,0,30,20);d.fillRect(0,b-20+MIN_PADDING*2,30,20)}d.globalAlpha=
  1;d.strokeStyle="black";d.lineWidth=1;d.beginPath();if(this.browser.rulerLocation=="right"){d.moveTo(c-8,MIN_PADDING);d.lineTo(c,MIN_PADDING);d.lineTo(c,b+MIN_PADDING);d.lineTo(c-8,b+MIN_PADDING)}else{d.moveTo(8,MIN_PADDING);d.lineTo(0,MIN_PADDING);d.lineTo(0,b+MIN_PADDING);d.lineTo(8,b+MIN_PADDING)}d.stroke();d.fillStyle="black";if(this.browser.rulerLocation=="right"){d.textAlign="right";d.fillText(formatQuantLabel(a.max),c-8,10);d.fillText(formatQuantLabel(a.min),c-8,b+MIN_PADDING-2)}else{d.textAlign=
  "left";d.fillText(formatQuantLabel(a.max),8,10);d.fillText(formatQuantLabel(a.min),8,b+MIN_PADDING-2)}}};
  function glyphsForGroup(a,b,c,d){var e=d.styleForFeature(c),h,j=[];b=null;for(var i=0;i<a.length;++i){var l=a[i];if(l.orientation&&b==null)b=l.orientation;if(!h&&l.label)h=l.label;var m=d.styleForFeature(l);if(m)if(!l.parts)(l=glyphForFeature(l,0,m,d,null,true))&&j.push(l)}if(j.length==0)return null;a="flat";if(d.dasSource.collapseSuperGroups&&!d.bumped)if(b==="+")a="collapsed+";else{if(b==="-")a="collapsed-"}else if(b==="+")a="hat+";else if(b==="-")a="hat-";d=null;if(h||e&&(e.LABEL||e.LABELS))d=
  c.label||h;c=new GroupGlyph(j,a);if(d){if(b==="+")d=">"+d;else if(b==="-")d="<"+d;c=new LabelledGlyph(c,d)}c.bump=true;return c}
  function glyphForFeature(a,b,c,d,e,h){var j=d.browser.scale,i=d.browser.viewStart,l=c.glyph||"BOX",m=a.min,o=a.max,r=a.orientation,p=a.score,t=a.label,q=(m-i)*j,s=Math.max((o-i+1)*j,q+1);i=d.forceHeight||c.HEIGHT||e||12;var u=i=1*i;j=c.BUMP&&isDasBooleanTrue(c.BUMP);var v;if(l==="CROSS"||l==="EX"||l==="TRIANGLE"||l==="DOT"||l==="SQUARE"||l==="STAR"){m=c.FGCOLOR||"black";u=c.BGCOLOR||"none";i=d.forceHeight||c.HEIGHT||e||12;o=c.SIZE||i;u=1*i;o=1*o;i=(q+s)/2;q=o/2;if(l==="EX")s=new ExGlyph(i,o,m);else if(l===
  "TRIANGLE")s=new TriangleGlyph(i,o,c.DIRECTION||"N",c.LINEWIDTH||o,m);else if(l==="DOT")s=new DotGlyph(i,o,m);else if(l==="SQUARE")s=new BoxGlyph(i-q,0,o,o,m,null);else if(l==="STAR"){s=5;if(c.POINTS)s=c.POINTS|0;s=new StarGlyph(i,q,s,m,null)}else s=new CrossGlyph(i,o,m);if(isDasBooleanTrue(c.SCATTER)){m=d.dasSource.forceMin||c.MIN||d.currentFeaturesMinScore;(o=d.dasSource.forceMax||c.MAX||d.currentFeaturesMaxScore)||(o=m<0?0:10);m||(m=0);if(1*p<1*m)p=m;if(1*p>1*o)p=o;d=(1*p-m)/(o-m);p=-1*m/(o-m);
  if(d>=p){i=Math.max(1,(d-p)*u);b=b+(1-p)*u-i}else b+=(1-p)*u;v={min:m,max:o};s=new TranslatedGlyph(s,0,b-q,u)}}else if(l==="HISTOGRAM"||l==="GRADIENT"&&p!=="undefined"){m=d.dasSource.forceMin||c.MIN||d.currentFeaturesMinScore;(o=d.dasSource.forceMax||c.MAX||d.currentFeaturesMaxScore)||(o=m<0?0:10);m||(m=0);if(1*p<1*m)p=m;if(1*p>1*o)p=o;d=(1*p-m)/(o-m);p=-1*m/(o-m);if(l==="HISTOGRAM"){if(d>=p){i=Math.max(1,(d-p)*u);b=b+(1-p)*u-i}else{i=Math.max(1,(p-d)*u);b+=(1-p)*u}v={min:m,max:o}}m=c.FGCOLOR||null;
  u=a.override_color||c.BGCOLOR||c.COLOR1||"green";p=c.ALPHA?1*c.ALPHA:null;if(c.COLOR2){l=c._gradient;if(!l){l=makeGradient(50,c.COLOR1,c.COLOR2,c.COLOR3);c._gradient=l}d=d*l.length|0;if(d<0)d=0;if(d>=l.length)d=l.length-1;u=l[d]}s=new BoxGlyph(q,b,s-q,i,u,m,p)}else if(l==="HIDDEN"){s=new PaddedGlyph(null,q,s);h=true}else if(l==="ARROW"){b=c.FGCOLOR||"purple";d=isDasBooleanTrue(c.PARALLEL);p=isDasBooleanTrue(c.SOUTHWEST);l=isDasBooleanTrue(c.NORTHEAST);s=new ArrowGlyph(q,s,i,b,d,p,l)}else if(l==="ANCHORED_ARROW"){m=
  c.FGCOLOR||"none";u=c.BGCOLOR||"green";s=new AArrowGlyph(q,s,i,u,m,r);s.bump=true}else if(l==="SPAN"){m=c.FGCOLOR||"black";s=new SpanGlyph(q,s,i,m)}else if(l==="LINE"){m=c.FGCOLOR||"black";s=new LineGlyph(q,s,i,c.STYLE||"solid",r,m)}else if(l==="PRIMERS"){m=c.FGCOLOR||"black";u=c.BGCOLOR||"red";s=new PrimersGlyph(q,s,i,u,m)}else if(l==="TEXT"){b=c.STRING||"text";u=c.FGCOLOR||"black";s=new TextGlyph(q,s,i,u,b)}else if(l==="TOOMANY"){m=c.FGCOLOR||"gray";u=c.BGCOLOR||"orange";s=new TooManyGlyph(q,s,
  i,u,m)}else if(l==="POINT"){i=d.forceHeight||c.HEIGHT||30;m=d.dasSource.forceMin||c.MIN||d.currentFeaturesMinScore||0;o=d.dasSource.forceMax||c.MAX||d.currentFeaturesMaxScore||10;v=1*i/(o-m);d=(1*p-m)/(o-m);b=(p-1*m)*v|0;v={min:m,max:o};u=a.override_color||c.FGCOLOR||c.COLOR1||"black";if(c.COLOR2){l=c._gradient;if(!l){l=makeGradient(50,c.COLOR1,c.COLOR2,c.COLOR3);c._gradient=l}d=d*l.length|0;if(d<0)d=0;if(d>=l.length)d=l.length-1;u=l[d]}s=new PointGlyph((q+s)/2,i-b,i,u)}else if(l==="__SEQUENCE"){b=
  null;if(d.currentSequence){p=d.currentSequence.start|0;l=d.currentSequence.end|0;if(p<m&&l>o)b=d.currentSequence.seq.substr(m-p,o-m+1)}s=new SequenceGlyph(q,s,i,a.seq,b)}else if(l==="__NONE")return null;else{m=c.FGCOLOR||null;u=a.override_color||c.BGCOLOR||c.COLOR1||"green";s=new BoxGlyph(q,0,s-q,i,u,m)}if(isDasBooleanTrue(c.LABEL)&&t&&!h)s=new LabelledGlyph(s,t);if(j)s.bump=true;s.feature=a;if(v)s.quant=v;if(c.ZINDEX)s.zindex=c.ZINDEX|0;return s}
  DasTier.prototype.styleForFeature=function(a){var b=a._cachedStyle;if(b)return b;b=zoomForScale(this.browser.scale);if(!this.stylesheet)return null;for(var c=null,d=this.stylesheet.styles,e=0;e<d.length;++e){var h=d[e];if(!(h.zoom&&h.zoom!=b)){var j=h._labelRE;if(!j||!j.test){j=RegExp("^"+h.label+"$");h._labelRE=j}if(!(h.label&&!j.test(a.label))){j=h._methodRE;if(!j||!j.test){j=RegExp("^"+h.method+"$");h._methodRE=j}if(!(h.method&&!j.test(a.method))){if(h.type)if(h.type=="default"){if(!c)c=h.style;
  continue}else if(h.type!=a.type)continue;return a._cachedStyle=h.style}}}}return a._cachedStyle=c};
  function makeLineGlyph(a,b,c){var d=c.browser.viewStart,e=c.browser.scale,h=c.forceHeight||b.HEIGHT||30,j=c.dasSource.forceMin||b.MIN||c.currentFeaturesMinScore||0;c=c.dasSource.forceMax||b.MAX||c.currentFeaturesMaxScore||10;var i=1*h/(c-j);b=b.FGCOLOR||b.COLOR1||"black";for(var l=[],m=0;m<a.length;++m){var o=a[m],r=h-((o.score-1*j)*i|0);l.push((((o.min|0)+(o.max|0))/2-d)*e);l.push(r)}a=new LineGraphGlyph(l,b,h);a.quant={min:j,max:c};return a}
  var MIN_TILE=100,rulerTileColors=["black","white"],baseColors={A:"green",C:"blue",G:"black",T:"red"},steps=[1,2,5];function tileSizeForScale(a,b){b||(b=MIN_TILE);for(var c=steps.length;a*steps[c%steps.length]*Math.pow(10,c/steps.length|0)<b;)++c;return steps[c%steps.length]*Math.pow(10,c/steps.length|0)}
  function drawSeqTier(a,b){var c=a.browser.scale,d=a.browser.viewStart-1E3/c|0,e=a.browser.viewEnd+2E3/c,h=a.browser.currentSeqMax,j=a.viewport.width|0;if(j<a.browser.featurePanelWidth+1950)a.viewport.width=j=(a.browser.featurePanelWidth|0)+2E3;var i=50;if(b&&b.seq)i+=25;a.viewport.height=i;a.holder.style.height=""+i+"px";a.updateHeight();i=a.viewport.getContext("2d");i.clearRect(0,0,j,a.viewport.height);i.translate(1E3,0);j=e;if(h>0&&h<e)j=h;var l=tileSizeForScale(c),m=Math.max(0,(d/l|0)*l);for(h=
  a.browser.viewStart;m<=j;){i.fillStyle=m/l%2==0?"white":"black";i.strokeStyle="black";i.fillRect((m-h)*c,8,l*c,3);i.strokeRect((m-h)*c,8,l*c,3);i.fillStyle="black";i.fillText(formatLongInt(m),(m-h)*c,22);m+=l}if(b&&b.seq)for(d=d;d<=e;++d)if(d>=b.start&&d<=b.end){j=b.seq.substr(d-b.start,1).toUpperCase();(l=baseColors[j])||(l="gray");i.fillStyle=l;c>=8?i.fillText(j,(d-h)*c,52):i.fillRect((d-h)*c,42,c,12)}a.norigin=a.browser.viewStart;a.viewport.style.left="-1000px"}
  function svgSeqTier(a,b){var c=a.browser.scale,d=a.browser.viewStart-1E3/c|0,e=a.browser.viewEnd+2E3/c,h=a.browser.currentSeqMax,j=e;if(h>0&&h<e)j=h;var i=tileSizeForScale(c),l=Math.max(0,(d/i|0)*i);h=a.browser.viewStart;for(var m=makeElementNS(NS_SVG,"g",[],{fontSize:"8pt"});l<=j;){m.appendChild(makeElementNS(NS_SVG,"rect",null,{x:(l-h)*c,y:8,width:i*c,height:3,fill:l/i%2==0?"white":"black",stroke:"black"}));m.appendChild(makeElementNS(NS_SVG,"text",formatLongInt(l),{x:(l-h)*c,y:28,fill:"black",
  stroke:"none"}));l+=i}if(b&&b.seq)for(d=d;d<=e;++d)if(d>=b.start&&d<=b.end){j=b.seq.substr(d-b.start,1).toUpperCase();(i=baseColors[j])||(i="gray");c>=8?m.appendChild(makeElementNS(NS_SVG,"text",j,{x:(d-h)*c,y:52,fill:i})):m.appendChild(makeElementNS(NS_SVG,"rect",null,{x:(d-h)*c,y:42,width:c,height:12,fill:i}))}return m}
  function sortFeatures(a){for(var b={},c={},d={},e={},h={},j=[],i,l,m,o=function(){m={};for(var z=0;z<a.currentFeatures.length;++z){var x=a.currentFeatures[z];if(x.id)m[x.id]=x}},r=function(z){var x=[];if(z.parents)for(var D=0;D<z.parents.length;++D){var C=z.parents[D],A=m[C];A&&A.typeCv=="SO:0000704"&&pushnew(x,C)}return x},p=0;p<a.currentFeatures.length;++p){var t=a.currentFeatures[p];if(!t.parts)if(!t.min||!t.max)j.push(t);else{if(t.score&&t.score!="."&&t.score!="-"){sc=1*t.score;if(!i||sc<i)i=
  sc;if(!l||sc>l)l=sc}var q=[],s=null;if(t.groups)for(var u=0;u<t.groups.length;++u){var v=t.groups[u],w=v.id;if(v.type=="gene"){s=w;d[w]=shallowCopy(v)}else if(v.type!="translation"){pusho(c,w,t);d[w]=shallowCopy(v);q.push(w)}}if(t.parents){m||o();for(u=0;u<t.parents.length;++u){v=t.parents[u];if(w=m[v]){if(!w.parts)w.parts=[t];pushnewo(c,v,w);pusho(c,v,t);d[v]||(d[v]={type:w.type,id:w.id,label:w.label||w.id});q.push(v);v=r(w);if(v.length>0){s=v[0];w=m[v[0]];d[v[0]]={type:w.type,id:w.id,label:w.label||
  w.id};if(!a.dasSource.collapseSuperGroups)a.dasSource.collapseSuperGroups=true}}}}if(q.length==0)pusho(b,t.type,t);else if(s)for(v=0;v<q.length;++v){w=q[v];pushnewo(e,s,w);h[w]=s}}}a.ungroupedFeatures=b;a.groupedFeatures=c;a.groups=d;a.superGroups=e;a.groupsToSupers=h;if(i){if(i>0)i=0;else if(l<0)l=0;a.currentFeaturesMinScore=i;a.currentFeaturesMaxScore=l}}TAGVAL_NOTE_RE=/^([A-Za-z]+)=(.+)/;Browser.prototype.addFeatureInfoPlugin=function(a){if(!this.featureInfoPlugins)this.featureInfoPlugins=[];this.featureInfoPlugins.push(a)};
  function FeatureInfo(a,b,c){var d=pick(c.type,b.type),e=pick(c.label,b.label,c.id,b.id);if(e&&e.indexOf("__dazzle")!=0)d=d+": "+e;this.hit=a;this.feature=b;this.group=c;this.title=d;this.sections=[]}FeatureInfo.prototype.setTitle=function(a){this.title=a};FeatureInfo.prototype.add=function(a,b){if(typeof b==="string")b=makeElement("span",b);this.sections.push({label:a,info:b})};
  Browser.prototype.featurePopup=function(a,b,c,d){b=c.length;var e=--b>=0?c[b]:{},h=--b>=0?c[b]:{};c=new FeatureInfo(c,e,h);b=this.featureInfoPlugins||[];for(fipi=0;fipi<b.length;++fipi)try{b[fipi](e,c)}catch(j){console.log(j.stack||j)}b=d.featureInfoPlugins||[];for(fipi=0;fipi<b.length;++fipi)try{b[fipi](e,c)}catch(i){console.log(i.stack||i)}this.removeAllPopups();d=makeElement("table",null,{className:"table table-striped table-condensed"});d.style.width="100%";d.style.margin="0px";b=0;if(e.method){var l=
  makeElement("tr",[makeElement("th","Method"),makeElement("td",e.method)]);d.appendChild(l);++b}l=h.segment?h:e;l=makeElement("tr",[makeElement("th","Location"),makeElement("td",l.segment+":"+l.min+"-"+l.max)]);l.style.backgroundColor=this.tierBackgroundColors[b%this.tierBackgroundColors.length];d.appendChild(l);++b;if(e.score!==undefined&&e.score!==null&&e.score!="-"){l=makeElement("tr",[makeElement("th","Score"),makeElement("td",""+e.score)]);d.appendChild(l);++b}if((l=maybeConcat(h.links,e.links))&&
  l.length>0){l=makeElement("tr",[makeElement("th","Links"),makeElement("td",l.map(function(r){return makeElement("div",makeElement("a",r.desc,{href:r.uri,target:"_new"}))}))]);d.appendChild(l);++b}e=maybeConcat(h.notes,e.notes);for(h=0;h<e.length;++h){l="Note";var m=e[h],o=m.match(TAGVAL_NOTE_RE);if(o){l=o[1];m=o[2]}l=makeElement("tr",[makeElement("th",l),makeElement("td",m)]);d.appendChild(l);++b}for(b=0;b<c.sections.length;++b){e=c.sections[b];d.appendChild(makeElement("tr",[makeElement("th",e.label),
  makeElement("td",e.info)]))}this.popit(a,c.title,d,{width:400})};function Karyoscape(a,b){this.browser=a;this.dsn=b;this.svg=makeElementNS(NS_SVG,"g");this.width=250}Karyoscape.prototype.update=function(a,b,c){this.start=b;this.end=c;if(!this.chr||a!=this.chr){this.chr=a;removeChildren(this.svg);var d=this;this.dsn.features(new DASSegment(a),{type:"karyotype"},function(e,h,j){d.chrLen=j&&j[a]&&j[a].max?j[a].max:null;d.karyos=e||[];d.redraw()})}else this.setThumb()};
  var karyo_palette={gneg:"white",gpos25:"rgb(200,200,200)",gpos33:"rgb(180,180,180)",gpos50:"rgb(128,128,128)",gpos66:"rgb(100,100,100)",gpos75:"rgb(64,64,64)",gpos100:"rgb(0,0,0)",gpos:"rgb(0,0,0)",gvar:"rgb(100,100,100)",acen:"rgb(100,100,100)",stalk:"rgb(100,100,100)"};
  Karyoscape.prototype.redraw=function(){removeChildren(this.svg);this.karyos=this.karyos.sort(function(r,p){return(r.min|0)-(p.min|0)});if(this.karyos.length>0){if(!this.chrLen)this.chrLen=this.karyos[this.karyos.length-1].max}else{if(!this.chrLen){alert("Warning: insufficient data to set up spatial navigator");this.chrLen=2E8}this.karyos.push({min:1,max:this.chrLen,label:"gneg"})}for(var a=null,b=0;b<this.karyos.length;++b){var c=this.karyos[b],d=1*c.min/this.chrLen*this.width,e=1*c.max/this.chrLen*
  this.width,h=karyo_palette[c.label];if(h)if(e>d){d=makeElementNS(NS_SVG,"rect",null,{x:d,y:c.label=="stalk"||c.label=="acen"?5:0,width:e-d,height:c.label=="stalk"||c.label=="acen"?5:15,stroke:"none",fill:h});if(c.label.substring(0,1)=="g"){e=new Range(c.min,c.max);a=a==null?e:union(a,e)}this.browser.makeTooltip(d,c.id);this.svg.appendChild(d)}}if(a){a=a.ranges();b="M 0 10 L 0 0";c="M 0 5 L 0 15";for(var j=h=0;j<a.length;++j){e=a[j];d=1*e.min()/this.chrLen*this.width;e=1*e.max()/this.chrLen*this.width;
  if(d-h>0.75){b+=" M "+d+" 0";c+=" M "+d+" 15"}b+=" L "+e+" 0";c+=" L "+e+" 15";h=e}if(this.width-h>0.75){b+=" M "+this.width+" 0";c+=" M "+this.width+" 15"}else{b+=" L "+this.width+" 0";c+=" L "+this.width+" 15"}b+=" L "+this.width+" 10";c+=" L "+this.width+" 5";this.svg.appendChild(makeElementNS(NS_SVG,"path",null,{d:b+" "+c,stroke:"black",strokeWidth:2,fill:"none"}))}this.thumb=makeElementNS(NS_SVG,"rect",null,{x:50,y:-5,width:8,height:25,fill:"blue",fillOpacity:0.5,stroke:"none"});this.svg.appendChild(this.thumb);
  this.setThumb();var i=this,l,m=function(r){r.stopPropagation();r.preventDefault();i.thumb.setAttribute("x",Math.max(-4,Math.min(r.clientX+l,i.width-4)))},o=function(r){r.stopPropagation();r.preventDefault();i.onchange&&i.onchange(1*((i.thumb.getAttribute("x")|0)+4)/i.width,true);document.removeEventListener("mousemove",m,true);document.removeEventListener("mouseup",o,true)};this.thumb.addEventListener("mousedown",function(r){r.stopPropagation();r.preventDefault();l=i.thumb.getAttribute("x")-r.clientX;
  document.addEventListener("mousemove",m,true);document.addEventListener("mouseup",o,true)},false)};Karyoscape.prototype.setThumb=function(){var a=1*(((this.start|0)+(this.end|0))/2)/this.chrLen*this.width;this.thumb&&this.thumb.setAttribute("x",a-4)};function FetchPool(){this.reqs=[];this.awaitedFeatures={}}FetchPool.prototype.addRequest=function(a){this.reqs.push(a)};FetchPool.prototype.abortAll=function(){for(var a=0;a<this.reqs.length;++a)this.reqs[a].abort()};
  function KSCacheBaton(a,b,c,d,e,h){this.chr=a;this.min=b;this.max=c;this.scale=d;this.features=e||[];this.status=h}KSCacheBaton.prototype.toString=function(){return this.chr+":"+this.min+".."+this.max+";scale="+this.scale};function KnownSpace(a,b,c,d,e,h){this.tierMap=a;this.chr=b;this.min=c;this.max=d;this.scale=e;this.seqSource=h||new DummySequenceSource;this.viewCount=0;this.featureCache={};this.latestViews={}}
  KnownSpace.prototype.bestCacheOverlapping=function(){var a=this.featureCache[this.tierMap[0]];return a?a:null};KnownSpace.prototype.viewFeatures=function(a,b,c,d){if(d!=d)throw"viewFeatures called with silly scale";if(a!=this.chr)throw"Can't extend Known Space to a new chromosome";if(b<1)b=1;this.min=b;this.max=c;this.scale=d;this.pool&&this.pool.abortAll();this.pool=new FetchPool;this.awaitedSeq=new Awaited;this.seqWasFetched=false;this.viewCount++;this.startFetchesForTiers(this.tierMap)};
  function filterFeatures(a,b,c){var d=[];featuresByGroup={};for(var e=0;e<a.length;++e){var h=a[e];if(!h.min||!h.max)d.push(h);else if(h.groups&&h.groups.length>0)pusho(featuresByGroup,h.groups[0].id,h);else h.min<=c&&h.max>=b&&d.push(h)}for(var j in featuresByGroup){a=featuresByGroup[j];var i=1E11,l=-100000000000;for(e=0;e<a.length;++e){h=a[e];i=Math.min(i,h.min);l=Math.max(l,h.max)}if(i<=c||l>=b)for(e=0;e<a.length;++e)d.push(a[e])}return d}
  KnownSpace.prototype.invalidate=function(a){this.featureCache[a]=null;this.startFetchesForTiers([a])};
  KnownSpace.prototype.startFetchesForTiers=function(a){for(var b=this,c=this.awaitedSeq,d=false,e=0;e<a.length;++e)try{if(this.startFetchesFor(a[e],c))d=true}catch(h){a[e].updateStatus(h);console.log("Error fetching tier source");console.log(h)}if(d&&!this.seqWasFetched){this.seqWasFetched=true;var j=this.min,i=this.max;if(this.cs)if(this.cs.start<=j&&this.cs.end>=i){a=this.cs.start==j&&this.cs.end==i?this.cs:new DASSequence(this.cs.name,j,i,this.cs.alphabet,this.cs.seq.substring(j-this.cs.start,i+
  1-this.cs.start));return c.provide(a)}this.seqSource.fetch(this.chr,j,i,this.pool,function(l,m){if(m){if(!b.cs||j<=b.cs.start&&i>=b.cs.end||j>=b.cs.end||i<=b.cs.start||i-j>b.cs.end-b.cs.start)b.cs=m;c.provide(m)}else{dlog("Noseq: "+miniJSONify(l));c.provide(null)}})}};
  KnownSpace.prototype.startFetchesFor=function(a,b){var c=this,d=this.viewCount,e=a.getSource()||new DummyFeatureSource,h=a.needsSequence(this.scale),j=c.featureCache[a],i=a.getDesiredTypes(this.scale);if(i===undefined)return false;if(j&&j.chr===this.chr&&j.min<=this.min&&j.max>=this.max){var l=j.features;if(j.min<this.min||j.max>this.max)l=filterFeatures(l,this.min,this.max);c.provision(a,j.chr,Math.max(j.min,this.min),Math.min(j.max,this.max),j.scale,i,l,j.status,h?b:null);l=e.getScales();if(j.scale<=
  this.scale||!l)return h}e.instrument&&console.log("Starting  fetch "+d+" ("+this.min+", "+this.max+")");e.fetch(this.chr,this.min,this.max,this.scale,i,this.pool,function(m,o,r){e.instrument&&console.log("Finishing fetch "+d);if(!((c.latestViews[a]||-1)>d)){if(!j||c.min<j.min||c.max>j.max)c.featureCache[a]=new KSCacheBaton(c.chr,c.min,c.max,r,o,m);c.latestViews[a]=d;c.provision(a,c.chr,c.min,c.max,r,i,o,m,h?b:null)}});return h};
  KnownSpace.prototype.provision=function(a,b,c,d,e,h,j,i,l){if(i)a.updateStatus(i);else{i=false;for(var m=a.getSource();MappedFeatureSource.prototype.isPrototypeOf(m)||CachingFeatureSource.prototype.isPrototypeOf(m)||OverlayFeatureSource.prototype.isPrototypeOf(m);)m=OverlayFeatureSource.prototype.isPrototypeOf(m)?m.sources[0]:m.source;if(BWGFeatureSource.prototype.isPrototypeOf(m)||BAMFeatureSource.prototype.isPrototypeOf(m))i=true;if(!m.opts||!m.opts.forceReduction&&!m.opts.noDownsample)if(e<this.scale/
  2&&j.length>200||i&&h&&h.length==1&&h.indexOf("density")>=0)j=downsample(j,this.scale);l?l.await(function(o){a.viewFeatures(b,c,d,e,j,o)}):a.viewFeatures(b,c,d,e,j)}};var VALID_BOUND_RE=/^-?[0-9]+(\.[0-9]+)?$/;
  Browser.prototype.makeQuantConfigButton=function(a,b){var c=this;a.addEventListener("mousedown",function(d){d.stopPropagation();d.preventDefault();c.removeAllPopups();var e=makeElement("table"),h=makeElement("input","",{value:b.min});e.appendChild(makeElement("tr",[makeElement("td","Min:"),makeElement("td",h)]));var j=makeElement("input","",{value:b.max});e.appendChild(makeElement("tr",[makeElement("td","Max:"),makeElement("td",j)]));var i=makeElement("div","Update");i.style.backgroundColor="rgb(230,230,250)";
  i.style.borderStyle="solid";i.style.borderColor="blue";i.style.borderWidth="3px";i.style.padding="2px";i.style.margin="10px";i.style.width="150px";i.addEventListener("mousedown",function(l){l.stopPropagation();l.preventDefault();if(VALID_BOUND_RE.test(h.value))if(VALID_BOUND_RE.test(j.value)){b.dasSource.forceMin=h.value;b.dasSource.forceMax=j.value;c.removeAllPopups();b.draw();c.storeStatus()}else alert("Don't understand "+j.value);else alert("Don't understand "+h.value)},false);c.popit(d,"Configure: "+
  b.dasSource.name,[e,i])},false)};var __DS_SCALES=[1,2,5];function ds_scale(a){return __DS_SCALES[a%__DS_SCALES.length]*Math.pow(10,a/__DS_SCALES.length|0)}function DSBin(a,b,c){this.scale=a;this.cnt=this.tot=0;this.hasScore=false;this.min=b;this.max=c;this.lap=0;this.covered=null}DSBin.prototype.score=function(){return this.cnt==0?0:this.hasScore?this.tot/this.cnt:this.lap/coverage(this.covered)};
  DSBin.prototype.feature=function(a){if(a.score){this.tot+=a.score;this.hasScore=true}var b=a.max|0;a=Math.max(this.min,a.min|0);b=Math.min(this.max,b);this.lap+=1*(b-a+1);++this.cnt;b=new Range(a,b);this.covered=this.covered?union(this.covered,b):b};
  function downsample(a,b){Date.now();for(var c=0;ds_scale(c+1)<b;)++c;c=ds_scale(c);for(var d=[],e=-10000000000,h=1E10,j=0;j<a.length;++j){var i=a[j];if(i.groups&&i.groups.length>0)return a;var l=i.min/c|0,m=i.max/c|0;e=Math.max(e,m);h=Math.min(h,l);for(l=l;l<=m;++l){var o=d[l];if(!o){o=new DSBin(c,l*c,(l+1)*c-1);d[l]=o}o.feature(i)}}j=[];for(l=h;l<=e;++l)if(o=d[l]){i=new DASFeature;i.segment=a[0].segment;i.min=l*c+1;i.max=(l+1)*c;i.score=o.score();i.type="density";j.push(i)}Date.now();return j}
  var hexcase=0,b64pad="";function hex_sha1(a){return rstr2hex(rstr_sha1(str2rstr_utf8(a)))}function b64_sha1(a){return rstr2b64(rstr_sha1(str2rstr_utf8(a)))}function any_sha1(a,b){return rstr2any(rstr_sha1(str2rstr_utf8(a)),b)}function hex_hmac_sha1(a,b){return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)))}function b64_hmac_sha1(a,b){return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)))}
  function any_hmac_sha1(a,b,c){return rstr2any(rstr_hmac_sha1(str2rstr_utf8(a),str2rstr_utf8(b)),c)}function sha1_vm_test(){return hex_sha1("abc").toLowerCase()=="a9993e364706816aba3e25717850c26c9cd0d89d"}function rstr_sha1(a){return binb2rstr(binb_sha1(rstr2binb(a),a.length*8))}
  function rstr_hmac_sha1(a,b){var c=rstr2binb(a);if(c.length>16)c=binb_sha1(c,a.length*8);for(var d=Array(16),e=Array(16),h=0;h<16;h++){d[h]=c[h]^909522486;e[h]=c[h]^1549556828}c=binb_sha1(d.concat(rstr2binb(b)),512+b.length*8);return binb2rstr(binb_sha1(e.concat(c),672))}function rstr2hex(a){for(var b=hexcase?"0123456789ABCDEF":"0123456789abcdef",c="",d,e=0;e<a.length;e++){d=a.charCodeAt(e);c+=b.charAt(d>>>4&15)+b.charAt(d&15)}return c}
  function rstr2b64(a){for(var b="",c=a.length,d=0;d<c;d+=3)for(var e=a.charCodeAt(d)<<16|(d+1<c?a.charCodeAt(d+1)<<8:0)|(d+2<c?a.charCodeAt(d+2):0),h=0;h<4;h++)b+=d*8+h*6>a.length*8?b64pad:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e>>>6*(3-h)&63);return b}
  function rstr2any(a,b){var c=b.length,d=[],e,h,j,i,l=Array(Math.ceil(a.length/2));for(e=0;e<l.length;e++)l[e]=a.charCodeAt(e*2)<<8|a.charCodeAt(e*2+1);for(;l.length>0;){i=[];for(e=j=0;e<l.length;e++){j=(j<<16)+l[e];h=Math.floor(j/c);j-=h*c;if(i.length>0||h>0)i[i.length]=h}d[d.length]=j;l=i}c="";for(e=d.length-1;e>=0;e--)c+=b.charAt(d[e]);d=Math.ceil(a.length*8/(Math.log(b.length)/Math.log(2)));for(e=c.length;e<d;e++)c=b[0]+c;return c}
  function str2rstr_utf8(a){for(var b="",c=-1,d,e;++c<a.length;){d=a.charCodeAt(c);e=c+1<a.length?a.charCodeAt(c+1):0;if(55296<=d&&d<=56319&&56320<=e&&e<=57343){d=65536+((d&1023)<<10)+(e&1023);c++}if(d<=127)b+=String.fromCharCode(d);else if(d<=2047)b+=String.fromCharCode(192|d>>>6&31,128|d&63);else if(d<=65535)b+=String.fromCharCode(224|d>>>12&15,128|d>>>6&63,128|d&63);else if(d<=2097151)b+=String.fromCharCode(240|d>>>18&7,128|d>>>12&63,128|d>>>6&63,128|d&63)}return b}
  function str2rstr_utf16le(a){for(var b="",c=0;c<a.length;c++)b+=String.fromCharCode(a.charCodeAt(c)&255,a.charCodeAt(c)>>>8&255);return b}function str2rstr_utf16be(a){for(var b="",c=0;c<a.length;c++)b+=String.fromCharCode(a.charCodeAt(c)>>>8&255,a.charCodeAt(c)&255);return b}function rstr2binb(a){for(var b=Array(a.length>>2),c=0;c<b.length;c++)b[c]=0;for(c=0;c<a.length*8;c+=8)b[c>>5]|=(a.charCodeAt(c/8)&255)<<24-c%32;return b}
  function binb2rstr(a){for(var b="",c=0;c<a.length*32;c+=8)b+=String.fromCharCode(a[c>>5]>>>24-c%32&255);return b}
  function binb_sha1(a,b){a[b>>5]|=128<<24-b%32;a[(b+64>>9<<4)+15]=b;for(var c=Array(80),d=1732584193,e=-271733879,h=-1732584194,j=271733878,i=-1009589776,l=0;l<a.length;l+=16){for(var m=d,o=e,r=h,p=j,t=i,q=0;q<80;q++){c[q]=q<16?a[l+q]:bit_rol(c[q-3]^c[q-8]^c[q-14]^c[q-16],1);var s=safe_add(safe_add(bit_rol(d,5),sha1_ft(q,e,h,j)),safe_add(safe_add(i,c[q]),sha1_kt(q)));i=j;j=h;h=bit_rol(e,30);e=d;d=s}d=safe_add(d,m);e=safe_add(e,o);h=safe_add(h,r);j=safe_add(j,p);i=safe_add(i,t)}return Array(d,e,h,j,
  i)}function sha1_ft(a,b,c,d){if(a<20)return b&c|~b&d;if(a<40)return b^c^d;if(a<60)return b&c|b&d|c&d;return b^c^d}function sha1_kt(a){return a<20?1518500249:a<40?1859775393:a<60?-1894007588:-899497514}function safe_add(a,b){var c=(a&65535)+(b&65535);return(a>>16)+(b>>16)+(c>>16)<<16|c&65535}function bit_rol(a,b){return a<<b|a>>>32-b}
  Browser.prototype.saveSVG=function(){var a=this,b=document.implementation.createDocument(NS_SVG,"svg",null),c=makeElementNS(NS_SVG,"g",null,{fontFamily:"helvetica",fontSize:"8pt"});b.documentElement.appendChild(c);var d=makeElementNS(NS_SVG,"a",makeElementNS(NS_SVG,"text","Graphics from Dalliance "+VERSION,{x:(a.featurePanelWidth+200+20)/2,y:30,strokeWidth:0,fill:"black",fontSize:"12pt",textAnchor:"middle",fill:"blue"}));d.setAttribute("xmlns:xlink",NS_XLINK);d.setAttribute("xlink:href","http://www.biodalliance.org/");
  c.appendChild(d);d=makeElementNS(NS_SVG,"rect",null,{x:200,y:50,width:a.featurePanelWidth,height:1E5});d=makeElementNS(NS_SVG,"clipPath",d,{id:"featureClip"});c.appendChild(d);d=70;for(var e=makeElementNS(NS_SVG,"g",null,{}),h=0;h<a.tiers.length;++h){var j=a.tiers[h],i=makeElementNS(NS_SVG,"g",null,{clipPath:"url(#featureClip)",clipRule:"nonzero"}),l=makeElementNS(NS_SVG,"g"),m=d,o=makeElementNS(NS_SVG,"rect",null,{x:0,y:m,width:"10000",height:50,fill:j.background});i.appendChild(o);if(j.dasSource.tier_type===
  "sequence"){var r=svgSeqTier(j,j.currentSequence);i.appendChild(makeElementNS(NS_SVG,"g",r,{transform:"translate(200, "+d+")"}));d+=80}else{if(!j.subtiers)continue;r=(j.glyphCacheOrigin-a.viewStart)*a.scale;for(var p=0;p<j.subtiers.length;++p){for(var t=j.subtiers[p],q=[],s=0;s<t.glyphs.length;++s)q.push(t.glyphs[s].toSVG());i.appendChild(makeElementNS(NS_SVG,"g",q,{transform:"translate("+(200+r)+", "+d+")"}));if(t.quant){q=t.quant;s=new SVGPath;s.moveTo(205,d);s.lineTo(200,d);s.lineTo(200,d+t.height);
  s.lineTo(205,d+t.height);l.appendChild(makeElementNS(NS_SVG,"path",null,{d:s.toPathData(),fill:"none",stroke:"black",strokeWidth:"2px"}));l.appendChild(makeElementNS(NS_SVG,"text",formatQuantLabel(q.max),{x:197,y:d+8,textAnchor:"end"}));l.appendChild(makeElementNS(NS_SVG,"text",formatQuantLabel(q.min),{x:197,y:d+t.height-3,textAnchor:"end"}))}d+=t.height+3}d+=10}l.appendChild(makeElementNS(NS_SVG,"text",j.dasSource.name,{x:188,y:(d+m+5)/2,fontSize:"12pt",textAnchor:"end"}));o.setAttribute("height",
  d-m);e.appendChild(makeElementNS(NS_SVG,"g",[i,l]))}c.appendChild(e);b.documentElement.setAttribute("width",a.featurePanelWidth+20+200);b.documentElement.setAttribute("height",d+50);b=new Blob([(new XMLSerializer).serializeToString(b)]);c=new FileReader;c.onload=function(u){window.open("data:image/svg+xml;"+u.target.result.substring(6),"Dalliance graphics","width="+(a.featurePanelWidth+20+200+"px"))};c.readAsDataURL(b)};function Range(a,b){this._min=a|0;this._max=b|0}Range.prototype.min=function(){return this._min};
  Range.prototype.max=function(){return this._max};Range.prototype.contains=function(a){return a>=this._min&&a<=this._max};Range.prototype.isContiguous=function(){return true};Range.prototype.ranges=function(){return[this]};Range.prototype.toString=function(){return"["+this._min+"-"+this._max+"]"};function _Compound(a){this._ranges=a}_Compound.prototype.min=function(){return this._ranges[0].min()};_Compound.prototype.max=function(){return this._ranges[this._ranges.length-1].max()};
  _Compound.prototype.contains=function(a){for(var b=0;b<this._ranges.length;++b)if(this._ranges[b].contains(a))return true;return false};_Compound.prototype.isContiguous=function(){return this._ranges.length>1};_Compound.prototype.ranges=function(){return this._ranges};_Compound.prototype.toString=function(){for(var a="",b=0;b<this._ranges.length;++b){if(b>0)a+=",";a+=this._ranges[b].toString()}return a};
  function union(a,b){for(var c=a.ranges().concat(b.ranges()).sort(rangeOrder),d=[],e=c[0],h=1;h<c.length;++h){var j=c[h];if(j.min()>e.max()+1){d.push(e);e=j}else if(j.max()>e.max())e=new Range(e.min(),j.max())}d.push(e);return d.length==1?d[0]:new _Compound(d)}
  function intersection(a,b){for(var c=a.ranges(),d=b.ranges(),e=c.length,h=d.length,j=0,i=0,l=[];j<e&&i<h;){a=c[j];b=d[i];var m=Math.max(a.min(),b.min()),o=Math.min(a.max(),b.max());o>=m&&l.push(new Range(m,o));if(a.max()>b.max())++i;else++j}return l.length==0?null:l.length==1?l[0]:new _Compound(l)}function coverage(a){var b=0;a=a.ranges();for(var c=0;c<a.length;++c){var d=a[c];b+=d.max()-d.min()+1}return b}
  function rangeOrder(a,b){return a.min()<b.min()?-1:a.min()>b.min()?1:a.max()<b.max()?-1:b.max()>a.max()?1:0}var THUB_STANZA_REGEXP=/\n\s*\n/,THUB_PARSE_REGEXP=/(\w+) +(.+)\n?/,THUB_SUBGROUP_REGEXP=/subGroup[1-9]/,THUB_PENNANT_PREFIX="http://genome.ucsc.edu/images/";function TrackHub(a){this.genomes={};this.url=a}function TrackHubTrack(){}TrackHubTrack.prototype.get=function(a){if(this[a])return this[a];else if(this._parent)return this._parent.get(a)};function TrackHubDB(){}
  TrackHubDB.prototype.getTracks=function(a){var b=this;if(this._tracks)return a(this._tracks);textXHR(this.absURL,function(c,d){if(d)return a(null,d);c=c.replace("\\\n"," ");var e=[],h={};stanzas=c.split(THUB_STANZA_REGEXP);for(var j=0;j<stanzas.length;++j){var i=stanzas[j].split(THUB_PARSE_REGEXP),l=new TrackHubTrack;l._db=b;for(var m=0;m<i.length-2;m+=3){var o=i[m+1],r=i[m+2];if(o.match(THUB_SUBGROUP_REGEXP)){if(!l.subgroups)l.subgroups={};o=r.split(/\s/);r=o[0];for(var p={name:o[1],tags:[],titles:[]},
  t=2;t<o.length;++t){var q=o[t].split(/=/);p.tags.push(q[0]);p.titles.push(q[1])}l.subgroups[r]=p}else if(o==="subGroups"){o=r.split(/(\w+)=(\w+)/);l.sgm={};for(t=0;t<o.length-2;t+=3)l.sgm[o[t+1]]=o[t+2]}else l[i[m+1]]=i[m+2]}if(l.track&&(l.type||l.container)){e.push(l);h[l.track]=l}}j=[];for(i=0;i<e.length;++i){l=e[i];m=true;if(l.parent){ptoks=l.parent.split(/\s+/);if(o=h[ptoks[0]]){l._parent=o;if(!o.children)o.children=[];o.children.push(l);if(o&&(!o.compositeTrack||o.view))m=false;if(o.container==
  "multiWig")m=false}}if(l.compositeTrack&&!l.view)m=false;m&&j.push(l)}b._tracks=j;return a(b._tracks,null)})};
  function connectTrackHub(a,b){textXHR(a,function(c,d){if(d)return b(null,d);for(var e=c.split(THUB_PARSE_REGEXP),h=new TrackHub(a),j=0;j<e.length-2;j+=3)h[e[j+1]]=e[j+2];if(h.genomesFile){var i=relativeURL(a,h.genomesFile);textXHR(i,function(l,m){if(m)return b(null,m);stanzas=l.split(THUB_STANZA_REGEXP);for(var o=0;o<stanzas.length;++o){for(var r=stanzas[o].split(THUB_PARSE_REGEXP),p=new TrackHubDB,t=0;t<r.length-2;t+=3)p[r[t+1]]=r[t+2];if(p.genome&&p.trackDb){p.absURL=relativeURL(i,p.trackDb);h.genomes[p.genome]=
  p}}b(h)})}else b(null,"No genomesFile")})}
  TrackHubTrack.prototype.toDallianceSource=function(){var a={name:this.shortLabel,desc:this.longLabel},b=this.get("pennantIcon");if(b){b=b.split(/\s+/);a.pennant=THUB_PENNANT_PREFIX+b[0]}if(this.container=="multiWig"){a.merge="concat";a.overlay=[];b=this.children||[];a.style=[];a.noDownsample=true;for(var c=0;c<b.length;++c){var d=b[c],e=d.toDallianceSource();a.overlay.push(e);if(e.style)for(var h=0;h<e.style.length;++h){var j=e.style[h];j.method=d.shortLabel;if(this.aggregate=="transparentOverlay")j.style.ALPHA=
  0.5;a.style.push(j)}}return a}else{typeToks=this.type.split(/\s+/);if(typeToks[0]=="bigBed"){a.bwgURI=relativeURL(this._db.absURL,this.bigDataUrl);a.style=this.bigbedStyles();return a}else if(typeToks[0]=="bigWig"){a.bwgURI=relativeURL(this._db.absURL,this.bigDataUrl);a.style=this.bigwigStyles();a.noDownsample=true;if(this.yLineOnOff&&this.yLineOnOff=="on")a.quantLeapThreshold=this.yLineMark!==undefined?1*this.yLineMark:0;return a}else if(typeToks[0]=="bam"){a.bamURI=relativeURL(this._db.absURL,this.bigDataUrl);
  return a}else console.log("Unsupported "+this.type)}};
  TrackHubTrack.prototype.bigwigStyles=function(){var a,b;if(typeToks.length>=3){a=1*typeToks[1];b=1*typeToks[2]}var c;if(this.maxHeightPixels){var d=this.maxHeightPixels.split(/:/);if(d.length==3)c=d[1]|0;else console.log("maxHeightPixels should be of the form max:default:min")}d="bars";if(this.graphTypeDefault)d=this.graphTypeDefault;var e="black",h=null;if(this.color)e="rgb("+this.color+")";if(this.altColor)h="rgb("+this.altColor+")";var j=new DASStylesheet,i=new DASStyle;i.glyph=d=="points"?"POINT":
  "HISTOGRAM";if(h){i.COLOR1=e;i.COLOR2=h}else i.BGCOLOR=e;i.HEIGHT=c||30;if(a||b){i.MIN=a;i.MAX=b}j.pushStyle({type:"default"},null,i);return j.styles};
  TrackHubTrack.prototype.bigbedStyles=function(){var a=this.get("visibility")||"full",b=this.get("color");b=b?"rgb("+b+")":"blue";var c=new DASStylesheet,d=new DASStyle;d.glyph="BOX";d.FGCOLOR="black";d.BGCOLOR=b;d.HEIGHT=a=="full"||a=="pack"?12:8;d.BUMP=a=="full"||a=="pack";d.LABEL=a=="full"||a=="pack";d.ZINDEX=20;c.pushStyle({type:"bigwig"},null,d);a=new DASStyle;a.glyph="BOX";a.FGCOLOR="black";a.BGCOLOR="red";a.HEIGHT=10;a.BUMP=true;a.ZINDEX=20;c.pushStyle({type:"bb-translation"},null,a);a=new DASStyle;
  a.glyph="BOX";a.FGCOLOR="black";a.BGCOLOR="white";a.HEIGHT=10;a.ZINDEX=10;a.BUMP=true;a.LABEL=true;c.pushStyle({type:"bb-transcript"},null,a);return c.styles};var __tier_idSeed=0;
  function DasTier(a,b,c,d,e,h,j){this.id="tier"+ ++__tier_idSeed;this.browser=a;this.dasSource=new DASSource(b);this.viewport=c;this.holder=d;this.overlay=e;this.placard=h;this.placardContent=j;this.req=null;this.layoutHeight=25;this.bumped=true;if(b.quantLeapThreshold)this.quantLeapThreshold=b.quantLeapThreshold;if(this.dasSource.collapseSuperGroups)this.bumped=false;this.y=0;this.layoutWasDone=false;b.featureInfoPlugin&&this.addFeatureInfoPlugin(b.featureInfoPlugin);this.initSources()}
  DasTier.prototype.toString=function(){return this.id};DasTier.prototype.addFeatureInfoPlugin=function(a){if(!this.featureInfoPlugins)this.featureInfoPlugins=[];this.featureInfoPlugins.push(a)};
  DasTier.prototype.init=function(){var a=this;if(a.dasSource.style){this.stylesheet={styles:a.dasSource.style};this.browser.refreshTier(this)}else{var b;b=a.dasSource.stylesheet_uri?new DASFeatureSource(a.dasSource):a.getSource();a.status="Fetching stylesheet";b.getStyleSheet(function(c,d){if(d){a.error="No stylesheet";a.stylesheet=new DASStylesheet;var e=new DASStyle;e.glyph="BOX";e.BGCOLOR="blue";e.FGCOLOR="black";a.stylesheet.pushStyle({type:"default"},null,e)}else a.stylesheet=c;a.browser.refreshTier(a)})}};
  DasTier.prototype.styles=function(){return this.stylesheet==null?null:this.browser.scale>0.2?this.stylesheet.highZoomStyles:this.browser.scale>0.01?this.stylesheet.mediumZoomStyles:this.stylesheet.lowZoomStyles};DasTier.prototype.getSource=function(){return this.featureSource};
  DasTier.prototype.getDesiredTypes=function(){var a=[],b=false,c=zoomForScale(this.browser.scale);if(this.stylesheet){for(var d=this.stylesheet.styles,e=0;e<d.length;++e){var h=d[e];if(!h.zoom||h.zoom==c)if(!h.type||h.type=="default"){b=true;break}else pushnew(a,h.type)}return b?null:a}};DasTier.prototype.needsSequence=function(a){if(this.dasSource.tier_type==="sequence"&&a<5)return true;else if((this.dasSource.bamURI||this.dasSource.bamBlob)&&a<20)return true;return false};
  DasTier.prototype.setStatus=function(a){dlog(a)};DasTier.prototype.viewFeatures=function(a,b,c,d,e,h){this.currentFeatures=e;this.currentSequence=h;this.knownChr=a;this.knownStart=b;this.knownEnd=c;this.error=this.status=null;this.draw()};
  DasTier.prototype.updateStatus=function(a){if(a){this.currentFeatures=[];this.currentSequence=null;this.error=a;this.placardContent.innerText=a;this.placard.style.display="block";this.holder.style.display="none"}else{this.placard.style.display="none";this.holder.style.display="block"}this.updateHeight()};DasTier.prototype.draw=function(){var a=this.currentSequence;this.dasSource.tier_type==="sequence"?drawSeqTier(this,a):drawFeatureTier(this);this.paint();this.originHaxx=0;this.browser.arrangeTiers()};
  function zoomForScale(a){return a>0.2?"high":a>0.01?"medium":"low"}
  DasTier.prototype.findNextFeature=function(a,b,c,d,e){if(this.quantLeapThreshold){b=b+(this.browser.viewEnd-this.browser.viewStart+1)*c/2|0;this.featureSource.quantFindNextFeature(a,b,c,this.quantLeapThreshold,e)}else{if(this.knownStart&&b>=this.knownStart&&b<=this.knownEnd)if(this.currentFeatures){for(var h=null,j=0;j<this.currentFeatures.length;++j){var i=this.currentFeatures[j];if(i.min&&i.max)if(!(i.parents&&i.parents.length>0))if(c<0)if(d==1&&i.max>=b&&i.min<b){if(!h||i.min>h.min||i.min==h.min&&
  i.max<h.max)h=i}else{if(i.max<b)if(!h||i.max>h.max||i.max==h.max&&i.min<h.min||i.min==h.mmin&&h.max>=b)h=i}else if(d==1&&i.min<=b&&i.max>b){if(!h||i.max<h.max||i.max==h.max&&i.min>h.min)h=i}else if(i.min>b)if(!h||i.min<h.min||i.min==h.min&&i.max>h.max||i.max==h.max&&h.min<=b)h=i}if(h)return e(h);b=c<0?this.knownStart:this.knownEnd}this.featureSource.findNextFeature(a,b,c,e)}};
  DasTier.prototype.updateLabel=function(){this.bumpButton.className=this.bumped?"icon-minus-sign":"icon-plus-sign";this.bumpButton.style.display=this.dasSource.collapseSuperGroups?"inline-block":"none"};DasTier.prototype.updateHeight=function(){this.currentHeight=Math.max(this.holder.clientHeight,this.label.clientHeight+4);if(this.placard.style.display!=="none")this.currentHeight=Math.max(this.currentHeight,this.placard.clientHeight+2);this.row.style.height=""+this.currentHeight+"px";this.browser.updateHeight()};
  DasTier.prototype.drawOverlay=function(){var a=this.browser,b=this.overlay.getContext("2d");this.overlay.height=this.viewport.height;for(var c=a.viewStart-1E3/a.scale,d=a.viewStart-1E3/a.scale,e=a.viewEnd+1E3/a.scale,h=0;h<a.highlights.length;++h){var j=a.highlights[h];if(j.chr==a.chr&&j.min<e&&j.max>d){b.globalAlpha=0.3;b.fillStyle="red";b.fillRect((j.min-c)*a.scale,0,(j.max-j.min)*a.scale,this.overlay.height)}}this.oorigin=a.viewStart;this.overlay.style.left="-1000px"};
  Browser.prototype.currentlyActive=function(a){for(var b=0;b<this.tiers.length;++b)if(sourcesAreEqual(this.tiers[b].dasSource,a))return true;return false};Browser.prototype.makeButton=function(a,b){var c=makeElement("a",a,{href:"#"});b&&this.makeTooltip(c,b);return makeElement("li",c)};function activateButton(a,b){for(var c=0;c<a.length;++c){var d=a[c];d===b?d.classList.add("active"):d.classList.remove("active")}}
  Browser.prototype.showTrackAdder=function(){function a(y){function K(){for(var Z=0;Z<X.length;++Z){var ha=X[Z];ha.checked=m.currentlyActive(ha.dalliance_source)}}ba.style.display="none";O.style.display="none";ca.style.display="none";J=false;removeChildren(F);for(var M=makeElement("div",null,{},{width:"100%"}),N=[],H=0;H<y.length;++H)N.push(y[H]);N.sort(function(Z,ha){return Z.shortLabel.toLowerCase().trim().localeCompare(ha.shortLabel.toLowerCase().trim())});y=[];var Q=[];for(H=0;H<N.length;++H){var I=
  N[H];I.children&&I.children.length>0&&I.container!="multiWig"?y.push(I):Q.push(I)}Q.length>0&&y.push({shortLabel:"Others",children:Q});var X=[];for(N=0;N<y.length;++N){I=Q=y[N];if(!I.dimensions&&I._parent&&I._parent.dimensions)I=I._parent;H={};if(I.dimensions)for(var Y=I.dimensions.split(/(\w+)=(\w+)/),T=0;T<Y.length-2;T+=3)H[Y[T+1]]=Y[T+2];if(H.dimX&&H.dimY){var V=H.dimX,U=H.dimY;H=I.subgroups[V];Y=I.subgroups[U];T={};for(var $=0;$<Q.children.length;++$){var ea=Q.children[$];I=ea.sgm[V];var da=ea.sgm[U];
  T[I]||(T[I]={});T[I][da]=ea}U=makeElement("table",null,{className:"table table-striped table-condensed"},{tableLayout:"fixed"});I=makeElement("tr");I.appendChild(makeElement("th",null,{},{width:"150px",height:"100px"}));for(da=0;da<H.titles.length;++da){V=makeElement("th",makeElement("div",H.titles[da],{},{transform:"rotate(-60deg)",transformOrigin:"0% 100%",webkitTransform:"rotate(-60deg) translate(20px,10px)",webkitTransformOrigin:"0% 100%",textAlign:"left"}),{},{width:"35px",height:"100px",verticalAlign:"bottom"});
  I.appendChild(V)}U.appendChild(I);for(var ma=makeElement("tbody",null,{className:"table table-striped table-condensed"}),ia=0;ia<Y.titles.length;++ia){da=Y.tags[ia];var ka=makeElement("tr");ka.appendChild(makeElement("th",Y.titles[ia]),{});for(var la=0;la<H.titles.length;++la){I=H.tags[la];var na=makeElement("td");if(T[I]&&T[I][da]){I=T[I][da];$=I.toDallianceSource();if(!$)continue;V=makeElement("tr");ea=makeElement("td");ea.style.textAlign="center";var aa=makeElement("input");aa.type="checkbox";
  aa.dalliance_source=$;if(L)aa.dalliance_mapping=L;X.push(aa);na.appendChild(aa);aa.addEventListener("change",function(Z){Z.target.checked?m.addTier(Z.target.dalliance_source):m.removeTier(Z.target.dalliance_source)})}ka.appendChild(na)}ma.appendChild(ka)}U.appendChild(ma);M.appendChild(makeTreeTableSection(Q.shortLabel,U,N==0))}else{Y=makeElement("tbody",null,{className:"table table-striped table-condensed"});T=makeElement("table",Y,{className:"table table-striped table-condensed"},{width:"100%",
  tableLayout:"fixed"});for(H=da=0;H<Q.children.length;++H){I=Q.children[H];if($=I.toDallianceSource()){V=makeElement("tr");ea=makeElement("td",null,{},{width:"30px"});ea.style.textAlign="center";aa=makeElement("input");aa.type="checkbox";aa.dalliance_source=$;if(L)aa.dalliance_mapping=L;X.push(aa);ea.appendChild(aa);aa.addEventListener("change",function(Z){Z.target.checked?m.addTier(Z.target.dalliance_source):m.removeTier(Z.target.dalliance_source)});V.appendChild(ea);U=makeElement("td");U.appendChild(document.createTextNode(I.shortLabel));
  I.longLabel&&I.longLabel.length>0&&m.makeTooltip(U,I.longLabel);V.appendChild(U);Y.appendChild(V);++da}}M.appendChild(makeTreeTableSection(Q.shortLabel,T,N==0))}}K();m.addTierListener(function(){K()});F.appendChild(M)}function b(){activateButton(r,z);J="bin";ba.style.display="none";O.style.display="inline";ca.style.display="none";removeChildren(F);if(m.supportsBinary){var y=makeElement("div",null,{},{paddingLeft:"10px",paddingRight:"10px"});y.appendChild(makeElement("h3","Add custom URL-based data"));
  y.appendChild(makeElement("p",["You can add indexed binary data hosted on an web server that supports CORS (",makeElement("a","full details",{href:"http://www.biodalliance.org/bin.html"}),").  Currently supported formats are bigwig, bigbed, and indexed BAM."]));y.appendChild(makeElement("br"));y.appendChild(document.createTextNode("URL: "));C=makeElement("input","",{size:80,value:"http://www.biodalliance.org/datasets/ensGene.bb"},{width:"100%"});y.appendChild(C);y.appendChild(makeElement("br"));y.appendChild(makeElement("b",
  "- or -"));y.appendChild(makeElement("br"));y.appendChild(document.createTextNode("File: "));E=makeElement("input",null,{type:"file"});y.appendChild(E);y.appendChild(makeElement("p",'Clicking the "Add" button below will initiate a series of test queries.'));F.appendChild(y);C.focus()}else{F.appendChild(makeElement("h2","Your browser does not support binary data"));F.appendChild(makeElement("p","Browsers currently known to support this feature include Google Chrome 9 or later and Mozilla Firefox 4 or later."))}}
  function c(){activateButton(r,x);ba.style.display="none";O.style.display="inline";ca.style.display="none";J="hub-connect";ba.style.visibility="hidden";removeChildren(F);var y=makeElement("div",null,{},{paddingLeft:"10px",paddingRight:"10px"});y.appendChild(makeElement("h3","Connect to a track hub."));y.appendChild(makeElement("p",['Enter the top-level URL (usually points to a file called "hub.txt" of a UCSC-style track hub']));C=makeElement("input","",{size:120,value:"http://www.biodalliance.org/datasets/testhub/hub.txt"},
  {width:"100%"});y.appendChild(C);F.appendChild(y);C.focus()}function d(){activateButton(r,w);ba.style.display="none";O.style.display="inline";ca.style.display="none";J="das";removeChildren(F);var y=makeElement("div",null,{},{paddingLeft:"10px",paddingRight:"10px"});y.appendChild(makeElement("h3","Add custom DAS data"));y.appendChild(makeElement("p","This interface is intended for adding custom or lab-specific data.  Public data can be added more easily via the registry interface."));y.appendChild(document.createTextNode("URL: "));
  y.appendChild(makeElement("br"));C=makeElement("input","",{size:80,value:"http://www.derkholm.net:8080/das/medipseq_reads/"},{width:"100%"});y.appendChild(C);y.appendChild(makeElement("p",'Clicking the "Add" button below will initiate a series of test queries.  If the source is password-protected, you may be prompted to enter credentials.'));F.appendChild(y);C.focus()}function e(){if(J)if(J==="das"){var y=C.value.trim();/^.+:\/\//.exec(y)||(y="http://"+y);var K=new DASSource({name:"temporary",uri:y});
  W(K)}else if(J==="bin"){K={name:"temporary"};var M=E.files;if(M&&M.length>0&&M[0]){K.bwgBlob=M[0];K.noPersist=true}else{y=C.value.trim();/^.+:\/\//.exec(y)||(y="http://"+y);K.bwgURI=y}K=new DASSource(K);ja(K)}else if(J==="reset")d();else if(J==="reset-bin")b();else if(J==="reset-hub")c();else if(J==="prompt-bai")if((M=E.files)&&M.length>0&&M[0]){S.baiBlob=M[0];i(S)}else j(S);else if(J==="finalize"){S.name=A.value;K=B.value;S.mapping=K!="__default__"?K:undefined;if(G)S.maxbins=G.checked;if(P.value.length>
  1&&R.value.length>1){dlog("password");S.xUser=P.value;S.xPass=R.value}m.addTier(S);d()}else{if(J==="hub-connect"){y=C.value.trim();/^.+:\/\//.exec(y)||(y="http://"+y);console.log("hub: "+y);connectTrackHub(y,function(N,H){if(H){removeChildren(F);F.appendChild(makeElement("h2","Error connecting to track hub"));F.appendChild(makeElement("p",H));J="reset-hub"}else if(m.coordSystem.ucscName&&N.genomes[m.coordSystem.ucscName]){m.hubs.push(y);m.hubObjects.push(N);var Q=u(N);D.appendChild(Q);activateButton(r,
  Q);N.genomes[m.coordSystem.ucscName].getTracks(function(I){a(I)})}else{removeChildren(F);F.appendChild(makeElement("h2","No data for this genome"));F.appendChild(makeElement("p","This URL appears to be a valid track-hub, but it doesn't contain any data for the coordinate system of this browser"));F.appendChild(makeElement("p","coordSystem.ucscName = "+m.coordSystem.ucscName));J="reset-hub"}})}}else m.removeAllPopups()}function h(y,K){var M=y.uri;if(K){var N=/(.+)\/[^\/]+\/?/.exec(M);if(N)M=N[1]+"/sources"}(new DASRegistry(M,
  {credentials:y.credentials})).sources(function(H){if(!H||H.length==0)return K?ga(y):h(y,true);var Q=null;if(H.length==1)Q=H[0];else for(var I=0;I<H.length;++I)if(H[I].uri===y.uri){Q=H[I];break}I=H=false;if(Q){y.name=Q.name;y.desc=Q.desc;y.maxbins=Q.maxbins?true:false;if(Q.capabilities)y.capabilities=Q.capabilities;I=true;if(Q.coords&&Q.coords.length==1){Q=Q.coords[0];if(coordsMatch(Q,m.coordSystem))H=true;else if(m.chains)for(var X in m.chains)if(coordsMatch(Q,m.chains[X].coords)){y.mapping=X;H=true}}}return ga(y,
  H,I)},function(){return K?ga(y):h(y,true)})}function j(y){ba.style.display="none";O.style.display="inline";ca.style.display="inline";removeChildren(F);J="prompt-bai";F.appendChild(makeElement("h2","Select an index file"));F.appendChild(makeElement("p","Dalliance requires a BAM index (.bai) file when displaying BAM data.  These normally accompany BAM files.  For security reasons, web applications like Dalliance can only access local files which you have explicity selected.  Please use the file chooser below to select the appropriate BAI file"));
  F.appendChild(document.createTextNode("Index file: "));E=makeElement("input",null,{type:"file"});F.appendChild(E);S=y}function i(y){(y.baiBlob?new BlobFetchable(y.baiBlob):new URLFetchable(y.bwgURI+".bai")).slice(0,256).fetch(function(K){var M=false;if(K){K=new Uint8Array(K);M=readInt(K,0)==BAI_MAGIC}if(M){if(K=/\/?([^\/]+?)(.bam)?$/.exec(y.bwgURI||y.bwgBlob.name))y.name=K[1];y.bamURI=y.bwgURI;y.bamBlob=y.bwgBlob;y.bwgURI=undefined;y.bwgBlob=undefined;return ga(y,false,false,true)}else return l("You have selected a valid BAM file, but a corresponding index (.bai) file was not found.  Please index your BAM (samtools index) and place the BAI file in the same directory")})}
  function l(y){ba.style.display="none";O.style.display="inline";ca.style.display="inline";removeChildren(F);y=y||"Custom data format not recognized";F.appendChild(makeElement("h2","Error adding custom data"));F.appendChild(makeElement("p",y));F.appendChild(makeElement("p","Currently supported formats are bigBed, bigWig, and BAM."));J="reset-bin"}if(this.uiMode==="add"){this.hideToolPanel();this.setUiMode("none")}else{var m=this,o=makeElement("div",null,{className:"dalliance"},{width:"100%",display:"inline-block",
  boxSizing:"border-box",MozBoxSizing:"border-box",verticalAlign:"top"}),r=[],p,t,q=this.makeButton("Registry","Browse compatible datasources from the DAS registry");r.push(q);for(var s in this.mappableSources)(function(y){var K=m.makeButton(m.chains[y].srcTag,"Browse datasources mapped from "+m.chains[y].srcTag);r.push(K);K.addEventListener("click",function(M){M.preventDefault();M.stopPropagation();activateButton(r,K);p(m.mappableSources[y],y)},false)})(s);var u=function(y){if(m.coordSystem.ucscName&&
  y.genomes[m.coordSystem.ucscName]){var K=makeElement("i",null,{className:"icon-remove"}),M=makeElement("span",[y.shortLabel," ",K]),N=m.makeButton(M,y.longLabel);r.push(N);N.addEventListener("click",function(H){H.preventDefault();H.stopPropagation();y.genomes[m.coordSystem.ucscName].getTracks(function(Q,I){I&&console.log(I);activateButton(r,N);a(Q)})},false);K.addEventListener("click",function(H){H.preventDefault();H.stopPropagation();for(H=0;H<m.hubs.length;++H)if(m.hubs[H]==y.url){console.log("index "+
  H);m.hubs.splice(H,1);break}for(H=0;H<m.hubObjects.length;++H)if(m.hubObjects[H].url==y.url){m.hubObjects.splice(H,1);break}D.removeChild(N);activateButton(r,x);c()},false);return N}},v=this.makeButton("Defaults","Browse the default set of data for this browser");r.push(v);var w=this.makeButton("Custom","Add arbitrary DAS data");r.push(w);var z=this.makeButton("Binary","Add data in bigwig or bigbed format");r.push(z);for(s=0;s<this.hubObjects.length;++s)u(this.hubObjects[s]);var x=this.makeButton("+",
  "Connect to a new track-hub");r.push(x);activateButton(r,q);var D=makeElement("ul",r,{className:"nav nav-tabs"},{marginBottom:"0px"});o.appendChild(D);var C,A,B,G,E,P,R,J=false,S=null;s=makeElement("form",null,{},{display:"inline-block",width:"100%"});s.addEventListener("submit",function(y){y.stopPropagation();y.preventDefault();e();return false},true);var F=makeElement("div");F.style.position="relative";F.style.overflow="scroll";s.appendChild(F);var L,fa;p=function(y,K){ba.style.display="none";O.style.display=
  "none";ca.style.display="none";fa&&fa.removeListener(t);L=K;fa=y;fa.addListenerAndFire(t)};t=function(y){function K(){for(var U=0;U<M.length;++U){var $=M[U];$.checked=m.currentlyActive($.dalliance_source)}}J=false;var M=[];removeChildren(F);if(y){for(var N=makeElement("tbody",null,{className:"table table-striped table-condensed"},{width:"100%"}),H=makeElement("table",N,{className:"table table-striped table-condensed"},{width:"100%",tableLayout:"fixed"}),Q=0,I=[],X=0;X<y.length;++X)I.push(y[X]);I.sort(function(U,
  $){return U.name.toLowerCase().trim().localeCompare($.name.toLowerCase().trim())});for(X=0;X<I.length;++X){y=I[X];var Y=makeElement("tr"),T=makeElement("td",null,{},{width:"30px"});T.style.textAlign="center";if(!y.props||y.props.cors){var V=makeElement("input");V.type="checkbox";V.dalliance_source=y;if(L)V.dalliance_mapping=L;T.appendChild(V);M.push(V);V.addEventListener("change",function(U){U.target.checked?m.addTier(U.target.dalliance_source):m.removeTier(U.target.dalliance_source)})}else{T.appendChild(document.createTextNode("!"));
  m.makeTooltip(T,makeElement("span",["This data source isn't accessible because it doesn't support ",makeElement("a","CORS",{href:"http://www.w3.org/TR/cors/"}),"."]))}Y.appendChild(T);T=makeElement("td");T.appendChild(document.createTextNode(y.name));y.desc&&y.desc.length>0&&m.makeTooltip(T,y.desc);Y.appendChild(T);N.appendChild(Y);++Q}K();m.addTierListener(function(){K()});F.appendChild(H)}else F.appendChild(makeElement("p","Dalliance was unable to retrieve data source information from the DAS registry, please try again later"))};
  q.addEventListener("click",function(y){y.preventDefault();y.stopPropagation();activateButton(r,q);p(m.availableSources)},false);v.addEventListener("click",function(y){y.preventDefault();y.stopPropagation();activateButton(r,v);p(new Observed(m.defaultSources))},false);z.addEventListener("click",function(y){y.preventDefault();y.stopPropagation();b()},false);x.addEventListener("click",function(y){y.preventDefault();y.stopPropagation();c()},false);w.addEventListener("click",function(y){y.preventDefault();
  y.stopPropagation();d()},false);var O=makeElement("button","Add",{className:"btn btn-primary"});O.addEventListener("click",function(y){y.stopPropagation();y.preventDefault();e()},false);var W=function(y,K){var M=m.knownSpace;if(M){var N=Math.max(M.min,(M.min+M.max-100)/2)|0;M=new DASSegment(M.chr,N,Math.min(N+99,M.max));y.features(M,{},function(H,Q){if(Q)if(K){removeChildren(F);F.appendChild(makeElement("h2","Custom data not found"));F.appendChild(makeElement("p","DAS uri: "+y.uri+" is not answering features requests"));
  J="reset"}else{dlog("retrying with credentials");y.credentials=true;W(y,true)}else{var I=/\/([^\/]+)\/?$/.exec(y.uri);if(I)y.name=I[1];h(y)}})}else alert("Can't confirm track-addition to an uninit browser.")},ja=function(y){(y.bwgURI?new URLFetchable(y.bwgURI):new BlobFetchable(y.bwgBlob)).slice(0,65536).fetch(function(K,M){if(K){var N=new Uint8Array(K),H=readInt(N,0);if(H==BIG_WIG_MAGIC||H==BIG_BED_MAGIC){if(N=/\/?([^\/]+?)(.bw|.bb|.bigWig|.bigBed)?$/.exec(y.bwgURI||y.bwgBlob.name))y.name=N[1];return ga(y,
  false,false,true)}else{if(N[0]!=31||N[1]!=139)return l();N=unbgzf(K);N=new Uint8Array(N);H=readInt(N,0);return H==BAM_MAGIC?y.bwgBlob?j(y):i(y):l()}}else{removeChildren(F);F.appendChild(makeElement("h2","Custom data not found"));y.bwgURI?F.appendChild(makeElement("p","Data URI: "+y.bwgURI+" is not accessible.")):F.appendChild(makeElement("p","File access failed, are you using an up-to-date browser?"));M&&F.appendChild(makeElement("p",""+M));F.appendChild(makeElement("p","If in doubt, please check that the server where the file is hosted supports CORS."));
  J="reset-bin"}})},ga=function(y,K,M,N){ba.style.display="none";O.style.display="inline";ca.style.display="inline";removeChildren(F);F.appendChild(makeElement("h2","Add custom data: step 2"));F.appendChild(document.createTextNode("Label: "));A=makeElement("input","",{value:y.name});F.appendChild(A);P=makeElement("input","");R=makeElement("input","");F.appendChild(makeElement("br"));F.appendChild(makeElement("br"));F.appendChild(makeElement("h4","Coordinate system: "));B=makeElement("select",null);
  B.appendChild(makeElement("option",m.coordSystem.auth+m.coordSystem.version,{value:"__default__"}));if(m.chains)for(var H in m.chains){var Q=m.chains[H].coords;B.appendChild(makeElement("option",Q.auth+Q.version,{value:H}))}B.value=y.mapping||"__default__";F.appendChild(B);if(K)F.appendChild(makeElement("p","(Based on server response, probably doesn't need changing.)"));else{F.appendChild(makeElement("p",[makeElement("b","Warning: "),"unable to determine the correct value from server responses.  Please check carefully."]));
  F.appendChild(makeElement("p","If you don't see the mapping you're looking for, please contact thomas@biodalliance.org"))}if(!N){F.appendChild(document.createTextNode("Quantitative: "));G=makeElement("input",null,{type:"checkbox",checked:true});if(typeof y.maxbins!=="undefined")G.checked=y.maxbins;F.appendChild(G);M?F.appendChild(makeElement("p","(Based on server response, probably doesn't need changing.)")):F.appendChild(makeElement("p",[makeElement("b","Warning: "),"unable to determine correct value.  If in doubt, leave checked."]))}y.bwgBlob&&
  F.appendChild(makeElement("p",[makeElement("b","Warning: "),"data added from local file.  Due to the browser security model, the track will disappear if you reload Dalliance."]));A.focus();J="finalize";S=y},ca=makeElement("button","Cancel",{className:"btn"});ca.addEventListener("click",function(y){y.stopPropagation();y.preventDefault();b()},false);var ba=makeElement("button","Refresh",{className:"btn"});ba.addEventListener("click",function(y){y.stopPropagation();y.preventDefault();m.queryRegistry(L)},
  false);this.makeTooltip(ba,"Click to re-fetch data from the DAS registry");var oa=makeElement("div",[O," ",ca," ",ba]);oa.style.margin="10px";s.appendChild(oa);o.appendChild(s);p(m.availableSources);this.showToolPanel(o);this.setUiMode("add")}};var TWOBIT_MAGIC=440477507;function TwoBitFile(){}
  function makeTwoBit(a,b){var c=new TwoBitFile;c.data=a;c.data.slice(0,1024).fetch(function(d){if(!d)return b(null,"Couldn't access data");d=new Uint8Array(d);if(readInt(d,0)!=TWOBIT_MAGIC)return b(null,"Not a .2bit fie");var e=readInt(d,4);if(e!=0)return b(null,"Unsupported version "+e);c.seqCount=readInt(d,8);c.seqDict={};e=16;for(var h=0;h<c.seqCount;++h){for(var j=d[e++],i="",l=1;l<=j;++l)i+=String.fromCharCode(d[e++]);j=readInt(d,e);e+=4;c.seqDict[i]=new TwoBitSeq(c,j)}return b(c)})}
  TwoBitFile.prototype.getSeq=function(a){var b=this.seqDict[a];b||(b=this.seqDict["chr"+a]);return b};TwoBitFile.prototype.fetch=function(a,b,c,d){var e=this.getSeq(a);if(e)e.fetch(b,c,d);else return d(null,"Couldn't find "+a)};function TwoBitSeq(a,b){this.tbf=a;this.offset=b}
  TwoBitSeq.prototype.init=function(a){if(this.seqOffset)return a();var b=this;b.tbf.data.slice(b.offset,8).fetch(function(c){if(!c)return a("Fetch failed");c=new Uint8Array(c);b._length=readInt(c,0);b.nBlockCnt=readInt(c,4);b.tbf.data.slice(b.offset+8,b.nBlockCnt*8+4).fetch(function(d){if(!d)return a("Fetch failed");d=new Uint8Array(d);for(var e=null,h=0;h<b.nBlockCnt;++h){var j=readInt(d,h*4),i=readInt(d,(h+b.nBlockCnt)*4);j=new Range(j,j+i-1);e=e?union(e,j):j}b.nBlocks=e;b.mBlockCnt=readInt(d,b.nBlockCnt*
  8);b.seqLength=(b._length+3)/4|0;b.seqOffset=b.offset+16+(b.nBlockCnt+b.mBlockCnt)*8;return a()})})};var TWOBIT_TABLE=["T","C","A","G"];
  TwoBitSeq.prototype.fetch=function(a,b,c){--a;--b;var d=this;this.init(function(e){if(e)return c(null,e);var h=a>>2;e=b+3>>2;if(h<0||e>d.seqLength)return c("Coordinates out of bounds: "+a+":"+b);d.tbf.data.slice(d.seqOffset+h,e-h).fetch(function(j){function i(t){for(;r<=t;){var q=r&3,s=l[(r>>2)-h];o+=TWOBIT_TABLE[q==0?s>>6&3:q==1?s>>4&3:q==2?s>>2&3:s&3];++r}}if(j==null)return c("SeqFetch failed");var l=new Uint8Array(j);j=[];if(d.nBlocks){var m=intersection(new Range(a,b),d.nBlocks);if(m)j=m.ranges()}var o=
  "",r=a;for(m=0;m<j.length;++m){var p=j[m];if(r>p.min())throw"N mismatch...";for(r<p.min()&&i(p.min()-1);r<p.max();){o+="N";++r}}r<b&&i(b);return c(o)})})};TwoBitSeq.prototype.length=function(a){var b=this;this.init(function(c){return c?a(null,c):a(b._length)})};var NUM_REGEXP=/[0-9]+/;function stringToNumbersArray(a){for(var b=[],c;c=NUM_REGEXP.exec(a);){b.push(c[0]);a=a.substring(c.index+c[0].length)}return b}var STRICT_NUM_REGEXP=/^[0-9]+$/;
  function stringToInt(a){a=a.replace(RegExp(",","g"),"");if(!STRICT_NUM_REGEXP.test(a))return null;return a|0}function pushnew(a,b){for(var c=0;c<a.length;++c)if(a[c]==b)return;a.push(b)}function pusho(a,b,c){if(a[b])a[b].push(c);else a[b]=[c]}function pushnewo(a,b,c){var d=a[b];if(d){for(a=0;a<d.length;++a)if(d[a]==c)return;d.push(c)}else a[b]=[c]}function pick(a,b,c,d){if(a)return a;else if(b)return b;else if(c)return c;else if(d)return d}
  function pushnew(a,b){for(var c=0;c<a.length;++c)if(a[c]==b)return;a.push(b)}function maybeConcat(a,b){var c=[];if(a)for(var d=0;d<a.length;++d)pushnew(c,a[d]);if(b)for(d=0;d<b.length;++d)pushnew(c,b[d]);return c}function arrayIndexOf(a,b){if(!a)return-1;for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}function arrayRemove(a,b){var c=arrayIndexOf(a,b);if(c>=0){a.splice(c,1);return true}return false}
  function makeElement(a,b,c,d){a=document.createElement(a);if(b){b instanceof Array||(b=[b]);for(var e=0;e<b.length;++e){var h=b[e];if(typeof h=="string")h=document.createTextNode(h);a.appendChild(h)}}if(c)for(var j in c)a[j]=c[j];if(d)for(j in d)a.style[j]=d[j];return a}function makeElementNS(a,b,c,d){a=document.createElementNS(a,b);if(c){c instanceof Array||(c=[c]);for(b=0;b<c.length;++b){var e=c[b];if(typeof e=="string")e=document.createTextNode(e);a.appendChild(e)}}setAttrs(a,d);return a}
  var attr_name_cache={};function setAttr(a,b,c){var d=attr_name_cache[b];if(!d){d="";for(var e=0;e<b.length;++e){var h=b.substring(e,e+1),j=h.toLowerCase();d=j!=h?d+"-"+j:d+h}d=attr_name_cache[b]=d}a.setAttribute(d,c)}function setAttrs(a,b){if(b)for(var c in b)setAttr(a,c,b[c])}function removeChildren(a){if(a&&a.childNodes)for(;a.childNodes.length>0;)a.removeChild(a.firstChild)}
  function miniJSONify(a,b){if(typeof a==="undefined")return"undefined";else if(a==null)return"null";else if(typeof a=="string")return"'"+a+"'";else if(typeof a=="number")return""+a;else if(typeof a=="boolean")return""+a;else if(typeof a=="object")if(a instanceof Array){for(var c=null,d=0;d<a.length;++d)c=(c==null?"":c+", ")+miniJSONify(a[d],b);return"["+(c?c:"")+"]"}else{b=b||{};c=null;for(d in a)if(!b[d])if(d!=undefined&&typeof a[d]!="function")c=(c==null?"":c+", ")+d+": "+miniJSONify(a[d],b);return"{"+
  (c?c:"")+"}"}else return typeof a}function shallowCopy(a){n={};for(k in a)n[k]=a[k];return n}function Observed(a){this.value=a;this.listeners=[]}Observed.prototype.addListener=function(a){this.listeners.push(a)};Observed.prototype.addListenerAndFire=function(a){this.listeners.push(a);a(this.value)};Observed.prototype.removeListener=function(a){arrayRemove(this.listeners,a)};Observed.prototype.get=function(){return this.value};Observed.prototype.set=function(a){this.value=a;for(var b=0;b<this.listeners.length;++b)this.listeners[b](a)};
  function Awaited(){this.queue=[]}Awaited.prototype.provide=function(a){if(this.res!==undefined)throw"Resource has already been provided.";this.res=a;for(var b=0;b<this.queue.length;++b)this.queue[b](a)};Awaited.prototype.await=function(a){if(this.res!==undefined){a(this.res);return this.res}else this.queue.push(a)};
  function textXHR(a,b){var c=new XMLHttpRequest;c.onreadystatechange=function(){if(c.readyState==4)c.status>=300?b(null,"Error code "+c.status):b(c.responseText)};c.open("GET",a,true);c.responseType="text";c.send("")}function relativeURL(a,b){if(b.indexOf("http:")==0||b.indexOf("https:")==0)return b;var c=a.lastIndexOf("/");return c>=0?a.substr(0,c+1)+b:b}if(!("trim"in String.prototype))String.prototype.trim=function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")};
  var VERSION={CONFIG:3,MAJOR:0,MINOR:10,MICRO:5,PATCH:"",BRANCH:""};VERSION.toString=function(){var a=""+this.MAJOR+"."+this.MINOR+"."+this.MICRO;if(this.PATCH)a+=this.PATCH;if(this.BRANCH&&this.BRANCH!="")a=a+"-"+this.BRANCH;return a};function formatLongInt(a){return(a|0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}function parseLocCardinal(a,b){var c=a.replace(/,/g,"");return b==="k"||b==="K"?c*1E3:b=="m"||b==="M"?c*1E6:c}
  Browser.prototype.initUI=function(a,b){document.head.appendChild(makeElement("link","",{rel:"stylesheet",href:this.uiPrefix+"css/bootstrap-scoped.css"}));document.head.appendChild(makeElement("link","",{rel:"stylesheet",href:this.uiPrefix+"css/dalliance-scoped.css"}));var c=this,d=/([\d+,\w,\.,\_,\-]+):([0-9,]+)([KkMmGg])?([\-,\,.]+([0-9,]+)([KkMmGg])?)?/;c.disableDefaultFeaturePopup||this.addFeatureListener(function(x,D,C,A){c.featurePopup(x,D,C,A)});a.classList.add("dalliance");var e=makeElement("div",
  null,{className:"btn-toolbar toolbar"}),h=c.coordSystem.speciesName+" "+c.coordSystem.auth+c.coordSystem.version;if(this.setDocumentTitle)document.title=h+" :: dalliance";var j=makeElement("input","",{className:"loc-field"});c.makeTooltip(j,"Enter a genomic location or gene name");var i=makeElement("p","",{className:"loc-status"}),l=makeElement("a",[makeElement("i",null,{className:"icon-zoom-in"})],{className:"btn"}),m=makeElement("input","",{type:"range",min:100,max:250},{className:"zoom-slider"}),
  o=makeElement("a",[makeElement("i",null,{className:"icon-zoom-out"})],{className:"btn"}),r=makeElement("a",[makeElement("i",null,{className:"icon-plus"})],{className:"btn"}),p=makeElement("a",[makeElement("i",null,{className:"icon-bookmark"})],{className:"btn"}),t=makeElement("a",[makeElement("i",null,{className:"icon-print"})],{className:"btn"}),q=makeElement("a",[makeElement("i",null,{className:"icon-refresh"})],{className:"btn"}),s=makeElement("div",[makeElement("i",null,{className:"icon-cog"})],
  {className:"btn"}),u=makeElement("div",[makeElement("i",null,{className:"icon-info-sign"})],{className:"btn"}),v=makeElement("div",[r,s,u],{className:"btn-group pull-right"});this.setUiMode=function(x){this.uiMode=x;var D={help:u,add:r,opts:s};for(var C in D)C==x?D[C].classList.add("active"):D[C].classList.remove("active")};e.appendChild(v);this.noTitle||e.appendChild(makeElement("div",makeElement("h4",h,{},{margin:"0px"}),{className:"btn-group title"}));e.appendChild(makeElement("div",[j,i],{className:"btn-group loc-group"}));
  e.appendChild(makeElement("div",[l,makeElement("span",m,{className:"btn"}),o],{className:"btn-group"}));e.appendChild(makeElement("div",[t,q],{className:"btn-group"}));a.appendChild(e);a.appendChild(b);this.addViewListener(function(x,D,C,A,B){j.value="";j.placeholder="chr"+x+":"+formatLongInt(D)+".."+formatLongInt(C);m.min=B.min;m.max=B.max;m.value=B.current;c.storeStatus&&c.storeViewStatus()});this.addTierListener(function(){c.storeStatus&&c.storeTierStatus()});j.addEventListener("keydown",function(x){if(x.keyCode==
  40){x.preventDefault();x.stopPropagation();c.setSelectedTier(0)}if(x.keyCode==10||x.keyCode==13){x.preventDefault();var D=j.value,C=d.exec(D),A=function(E){i.innerText=E?""+E:""};if(C){x=C[1];var B;if(C[5]){B=parseLocCardinal(C[2],C[3]);C=parseLocCardinal(C[5],C[6])}else{var G=c.viewEnd-c.viewStart+1;B=parseLocCardinal(C[2],C[3])-G/2|0;C=B+G-1}c.setLocation(x,B,C,A)}else{if(!D||D.length==0)return false;c.searchEndpoint.features(null,{group:D,type:"transcript"},function(E){E||(E=[]);for(var P=5E8,
  R=-100000000,J=null,S=0;S<E.length;++S){var F=E[S];if(F.label.toLowerCase()==D.toLowerCase()){if(J==null)J=F.segment;P=Math.min(P,F.min);R=Math.max(R,F.max)}}if(J){c.highlightRegion(J,P,R);E=Math.max(2500,0.3*(R-P+1)|0);c.setLocation(J,P-E,R+E,A)}else i.innerText="no match for '"+D+"' (search should improve soon!)"},false)}}},false);this.addRegionSelectListener(function(){});this.addTierListener(function(){c.storeStatus&&c.storeStatus()});var w;r.addEventListener("click",function(x){if(w&&w.displayed)c.removeAllPopups();
  else w=c.showTrackAdder(x)},false);c.makeTooltip(r,"Add a new track from the registry or an indexed file.");l.addEventListener("click",function(x){x.stopPropagation();x.preventDefault();c.zoomStep(-10)},false);c.makeTooltip(l,"Zoom in");o.addEventListener("click",function(x){x.stopPropagation();x.preventDefault();c.zoomStep(10)},false);c.makeTooltip(o,"Zoom out");m.addEventListener("change",function(){c.zoomSliderValue=1*m.value;c.zoom(Math.exp(1*m.value/c.zoomExpt))},false);m.min=c.zoomMin;m.max=
  c.zoomMax;p.addEventListener("click",function(x){x.stopPropagation();x.preventDefault()},false);c.makeTooltip(p,"Favourite regions");t.addEventListener("click",function(x){x.stopPropagation();x.preventDefault();c.saveSVG()},false);c.makeTooltip(t,"Export publication-quality SVG.");q.addEventListener("click",function(x){x.stopPropagation();x.preventDefault();for(x=c.tiers.length-1;x>=0;--x)c.removeTier({index:x});for(x=0;x<c.defaultSources.length;++x)c.addTier(c.defaultSources[x]);c.setLocation(c.defaultChr,
  c.defaultStart,c.defaultEnd)},false);c.makeTooltip(q,"Reset to default tracks and view.");s.addEventListener("click",function(x){x.stopPropagation();x.preventDefault();c.toggleOptsPopup(x)},false);c.makeTooltip(s,"Configure options.");u.addEventListener("click",function(x){x.stopPropagation();x.preventDefault();c.toggleHelpPopup(x)});c.makeTooltip(u,"Help; Keyboard shortcuts.");c.addTierSelectionWrapListener(function(x){if(x<0){c.setSelectedTier(null);j.focus()}});var z=function(x){if(x.keyCode==
  65||x.keyCode==97){x.preventDefault();x.stopPropagation();c.showTrackAdder()}else if(x.keyCode==72||x.keyCode==104){x.stopPropagation();x.preventDefault();c.toggleHelpPopup(x)}};a.addEventListener("focus",function(){a.addEventListener("keydown",z,false)},false);a.addEventListener("blur",function(){a.removeEventListener("keydown",z,false)},false)};
  Browser.prototype.showToolPanel=function(a,b){this.activeToolPanel&&this.svgHolder.removeChild(this.activeToolPanel);var c;c=b?a:makeElement("div",a,{},{overflowY:"auto",width:"100%"});this.activeToolPanel=makeElement("div",[makeElement("div",null,{className:"tool-divider"}),c],{className:"tool-holder"});this.svgHolder.appendChild(this.activeToolPanel);this.resizeViewer()};
  Browser.prototype.hideToolPanel=function(){this.svgHolder.removeChild(this.activeToolPanel);this.svgHolder.style.width="100%";this.activeToolPanel=null;this.resizeViewer()};Browser.prototype.toggleHelpPopup=function(){if(this.uiMode==="help"){this.hideToolPanel();this.setUiMode("none")}else{this.showToolPanel(makeElement("iframe",null,{scrolling:"yes",seamless:"seamless",src:this.uiPrefix+"help/index.html",seamless:"seamless",className:"help-panel"}),true);this.setUiMode("help")}};
  Browser.prototype.toggleOptsPopup=function(){var a=this;if(this.uiMode==="opts"){this.hideToolPanel();this.setUiMode("none")}else{var b=makeElement("div",null,{className:"form-horizontal"},{boxSizing:"border-box",MozBoxSizing:"border-box",display:"inline-block",verticalAlign:"top"}),c=makeElement("table");c.cellPadding=5;var d=makeElement("input","",{type:"checkbox",checked:a.reverseScrolling});d.addEventListener("change",function(){a.reverseScrolling=d.checked},false);c.appendChild(makeElement("tr",
  [makeElement("td","Reverse trackpad scrolling",{align:"right"}),makeElement("td",d)]));var e=makeElement("select");e.appendChild(makeElement("option","Left",{value:"left"}));e.appendChild(makeElement("option","Center",{value:"center"}));e.appendChild(makeElement("option","Right",{value:"right"}));e.appendChild(makeElement("option","None",{value:"none"}));e.value=a.rulerLocation;e.addEventListener("change",function(){a.rulerLocation=e.value;a.positionRuler();for(var h=0;h<a.tiers.length;++h)a.tiers[h].paintQuant()},
  false);c.appendChild(makeElement("tr",[makeElement("td","Vertical guideline",{align:"right"}),makeElement("td",e)]));b.appendChild(c);this.showToolPanel(b);this.setUiMode("opts")}};function BoxGlyph(a,b,c,d,e,h,j,i){this.x=a;this.y=b;this._width=c;this._height=d;this.fill=e;this.stroke=h;this._alpha=j;this._radius=i||0}
  BoxGlyph.prototype.draw=function(a){var b=this._radius;a.beginPath();if(b>0){a.moveTo(this.x+b,this.y);a.lineTo(this.x+this._width-b,this.y);a.arcTo(this.x+this._width,this.y,this.x+this._width,this.y+b,b);a.lineTo(this.x+this._width,this.y+this._height-b);a.arcTo(this.x+this._width,this.y+this._height,this.x+this._width-b,this.y+this._height,b);a.lineTo(this.x+b,this.y+this._height);a.arcTo(this.x,this.y+this._height,this.x,this.y+this._height-b,b);a.lineTo(this.x,this.y+b);a.arcTo(this.x,this.y,
  this.x+b,this.y,b)}else{a.lineJoin="miter";a.lineCap="square";a.moveTo(this.x,this.y);a.lineTo(this.x+this._width,this.y);a.lineTo(this.x+this._width,this.y+this._height);a.lineTo(this.x,this.y+this._height);a.lineTo(this.x,this.y)}a.closePath();if(this._alpha!=null){a.save();a.globalAlpha=this._alpha}if(this.fill){a.fillStyle=this.fill;a.fill()}if(this.stroke){a.strokeStyle=this.stroke;a.lineWidth=0.5;a.stroke()}this._alpha!=null&&a.restore()};
  BoxGlyph.prototype.toSVG=function(){var a=makeElementNS(NS_SVG,"rect",null,{x:this.x,y:this.y,width:this._width,height:this._height,stroke:this.stroke||"none",strokeWidth:0.5,fill:this.fill||"none"});this._alpha!=null&&a.setAttribute("opacity",this._alpha);return a};BoxGlyph.prototype.min=function(){return this.x};BoxGlyph.prototype.max=function(){return this.x+this._width};BoxGlyph.prototype.height=function(){return this.y+this._height};
  function GroupGlyph(a,b){this.glyphs=a;this.connector=b;this.h=a[0].height();var c=new Range(a[0].min(),a[0].max());for(g=1;g<a.length;++g){var d=a[g];c=union(c,new Range(d.min(),d.max()));this.h=Math.max(this.h,d.height())}this.coverage=c}
  GroupGlyph.prototype.draw=function(a){for(var b=0;b<this.glyphs.length;++b){var c=this.glyphs[b];c.draw(a)}b=this.coverage.ranges();for(var d=1;d<b.length;++d){c=b[d];var e=b[d-1];if(e&&c.min()>e.max()){e=e.max();c=c.min();var h=(e+c)/2;a.beginPath();if(this.connector==="hat+"){a.moveTo(e,this.h/2);a.lineTo(h,0);a.lineTo(c,this.h/2)}else if(this.connector==="hat-"){a.moveTo(e,this.h/2);a.lineTo(h,this.h);a.lineTo(c,this.h/2)}else if(this.connector==="collapsed+"){a.moveTo(e,this.h/2);a.lineTo(c,this.h/
  2);if(c-e>4){a.moveTo(h-2,this.h/2-5);a.lineTo(h+2,this.h/2);a.lineTo(h-2,this.h/2+5)}}else if(this.connector==="collapsed-"){a.moveTo(e,this.h/2);a.lineTo(c,this.h/2);if(c-e>4){a.moveTo(h+2,this.h/2-5);a.lineTo(h-2,this.h/2);a.lineTo(h+2,this.h/2+5)}}else{a.moveTo(e,this.h/2);a.lineTo(c,this.h/2)}a.stroke()}}};function SVGPath(){this.ops=[]}SVGPath.prototype.moveTo=function(a,b){this.ops.push("M "+a+" "+b)};SVGPath.prototype.lineTo=function(a,b){this.ops.push("L "+a+" "+b)};
  SVGPath.prototype.closePath=function(){this.ops.push("Z")};SVGPath.prototype.toPathData=function(){return this.ops.join(" ")};
  GroupGlyph.prototype.toSVG=function(){for(var a=makeElementNS(NS_SVG,"g"),b=0;b<this.glyphs.length;++b)a.appendChild(this.glyphs[b].toSVG());b=this.coverage.ranges();for(var c=1;c<b.length;++c){var d=b[c],e=b[c-1];if(e&&d.min()>e.max()){e=e.max();d=d.min();var h=(e+d)/2,j=new SVGPath;if(this.connector==="hat+"){j.moveTo(e,this.h/2);j.lineTo(h,0);j.lineTo(d,this.h/2)}else if(this.connector==="hat-"){j.moveTo(e,this.h/2);j.lineTo(h,this.h);j.lineTo(d,this.h/2)}else if(this.connector==="collapsed+"){j.moveTo(e,
  this.h/2);j.lineTo(d,this.h/2);if(d-e>4){j.moveTo(h-2,this.h/2-5);j.lineTo(h+2,this.h/2);j.lineTo(h-2,this.h/2+5)}}else if(this.connector==="collapsed-"){j.moveTo(e,this.h/2);j.lineTo(d,this.h/2);if(d-e>4){j.moveTo(h+2,this.h/2-5);j.lineTo(h-2,this.h/2);j.lineTo(h+2,this.h/2+5)}}else{j.moveTo(e,this.h/2);j.lineTo(d,this.h/2)}e=makeElementNS(NS_SVG,"path",null,{d:j.toPathData(),fill:"none",stroke:"black",strokeWidth:0.5});a.appendChild(e)}}return a};GroupGlyph.prototype.min=function(){return this.coverage.min()};
  GroupGlyph.prototype.max=function(){return this.coverage.max()};GroupGlyph.prototype.height=function(){return this.h};function LineGraphGlyph(a,b,c){this.points=a;this.color=b;this._height=c||50}LineGraphGlyph.prototype.min=function(){return this.points[0]};LineGraphGlyph.prototype.max=function(){return this.points[this.points.length-2]};LineGraphGlyph.prototype.height=function(){return this._height};
  LineGraphGlyph.prototype.draw=function(a){a.save();a.strokeStyle=this.color;a.lineWidth=2;a.beginPath();for(var b=0;b<this.points.length;b+=2){var c=this.points[b],d=this.points[b+1];b==0?a.moveTo(c,d):a.lineTo(c,d)}a.stroke();a.restore()};LineGraphGlyph.prototype.toSVG=function(){for(var a=new SVGPath,b=0;b<this.points.length;b+=2){var c=this.points[b],d=this.points[b+1];b==0?a.moveTo(c,d):a.lineTo(c,d)}return makeElementNS(NS_SVG,"path",null,{d:a.toPathData(),fill:"none",stroke:this.color,strokeWidth:"2px"})};
  function LabelledGlyph(a,b){this.glyph=a;this.text=b;this.textLen=GLOBAL_GC.measureText(b).width+10;this.bump=a.bump}LabelledGlyph.prototype.toSVG=function(){return makeElementNS(NS_SVG,"g",[this.glyph.toSVG(),makeElementNS(NS_SVG,"text",this.text,{x:this.glyph.min(),y:this.glyph.height()+15})])};LabelledGlyph.prototype.min=function(){return this.glyph.min()};LabelledGlyph.prototype.max=function(){return Math.max(this.glyph.max(),1*this.glyph.min()+this.textLen)};
  LabelledGlyph.prototype.height=function(){return this.glyph.height()+20};LabelledGlyph.prototype.draw=function(a){this.glyph.draw(a);a.fillStyle="black";a.fillText(this.text,this.glyph.min(),this.glyph.height()+15)};function CrossGlyph(a,b,c){this._x=a;this._height=b;this._stroke=c}CrossGlyph.prototype.draw=function(a){var b=this._height/2;a.beginPath();a.moveTo(this._x,0);a.lineTo(this._x,this._height);a.moveTo(this._x-b,b);a.lineTo(this._x+b,b);a.strokeStyle=this._stroke;a.lineWidth=1;a.stroke()};
  CrossGlyph.prototype.toSVG=function(){var a=this._height/2,b=new SVGPath;b.moveTo(this._x,0);b.lineTo(this._x,this._height);b.moveTo(this._x-a,a);b.lineTo(this._x+a,a);return makeElementNS(NS_SVG,"path",null,{d:b.toPathData(),fill:"none",stroke:this._stroke,strokeWidth:"1px"})};CrossGlyph.prototype.min=function(){return this._x-this._height/2};CrossGlyph.prototype.max=function(){return this._x+this._height/2};CrossGlyph.prototype.height=function(){return this._height};
  function ExGlyph(a,b,c){this._x=a;this._height=b;this._stroke=c}ExGlyph.prototype.draw=function(a){var b=this._height/2;a.beginPath();a.moveTo(this._x-b,0);a.lineTo(this._x+b,this._height);a.moveTo(this._x-b,this._height);a.lineTo(this._x+b,0);a.strokeStyle=this._stroke;a.lineWidth=1;a.stroke()};
  ExGlyph.prototype.toSVG=function(){var a=this._height/2,b=new SVGPath;b.moveTo(this._x-a,0);b.lineTo(this._x+a,this._height);b.moveTo(this._x-a,this._height);b.lineTo(this._x+a,0);return makeElementNS(NS_SVG,"path",null,{d:b.toPathData(),fill:"none",stroke:this._stroke,strokeWidth:"1px"})};ExGlyph.prototype.min=function(){return this._x-this._height/2};ExGlyph.prototype.max=function(){return this._x+this._height/2};ExGlyph.prototype.height=function(){return this._height};
  function TriangleGlyph(a,b,c,d,e){this._x=a;this._height=b;this._dir=c;this._width=d;this._stroke=e}
  TriangleGlyph.prototype.drawPath=function(a){var b=this._height/2,c=this._width/2;if(this._dir==="S"){a.moveTo(this._x,this._height);a.lineTo(this._x-c,0);a.lineTo(this._x+c,0)}else if(this._dir==="W"){a.moveTo(this._x+c,b);a.lineTo(this._x-c,0);a.lineTo(this._x-c,this._height)}else if(this._dir==="E"){a.moveTo(this._x-c,b);a.lineTo(this._x+c,0);a.lineTo(this._x+c,this._height)}else{a.moveTo(this._x,0);a.lineTo(this._x+c,this._height);a.lineTo(this._x-c,this._height)}a.closePath()};
  TriangleGlyph.prototype.draw=function(a){a.beginPath();this.drawPath(a);a.fillStyle=this._stroke;a.fill()};TriangleGlyph.prototype.toSVG=function(){var a=new SVGPath;this.drawPath(a);return makeElementNS(NS_SVG,"path",null,{d:a.toPathData(),fill:this._stroke})};TriangleGlyph.prototype.min=function(){return this._x-this._height/2};TriangleGlyph.prototype.max=function(){return this._x+this._height/2};TriangleGlyph.prototype.height=function(){return this._height};
  function DotGlyph(a,b,c){this._x=a;this._height=b;this._stroke=c}DotGlyph.prototype.draw=function(a){var b=this._height/2;a.fillStyle=this._stroke;a.beginPath();a.arc(this._x,b,b,0,6.29);a.fill()};DotGlyph.prototype.toSVG=function(){var a=this._height/2;return makeElementNS(NS_SVG,"circle",null,{cx:this._x,cy:a,r:a,fill:this._stroke,strokeWidth:"1px"})};DotGlyph.prototype.min=function(){return this._x-this._height/2};DotGlyph.prototype.max=function(){return this._x+this._height/2};
  DotGlyph.prototype.height=function(){return this._height};function PaddedGlyph(a,b,c){this.glyph=a;this._min=b;this._max=c;if(a)this.bump=a.bump}PaddedGlyph.prototype.draw=function(a){this.glyph&&this.glyph.draw(a)};PaddedGlyph.prototype.toSVG=function(){return this.glyph?this.glyph.toSVG():makeElementNS(NS_SVG,"g")};PaddedGlyph.prototype.min=function(){return this._min};PaddedGlyph.prototype.max=function(){return this._max};
  PaddedGlyph.prototype.height=function(){return this.glyph?this.glyph.height():1};function AArrowGlyph(a,b,c,d,e,h){this._min=a;this._max=b;this._height=c;this._fill=d;this._stroke=e;this._ori=h}AArrowGlyph.prototype.min=function(){return this._min};AArrowGlyph.prototype.max=function(){return this._max};AArrowGlyph.prototype.height=function(){return this._height};
  AArrowGlyph.prototype.makePath=function(a){var b=this._max,c=this._min,d=this._height,e=0,h=0,j=this._height+2,i=0.333333*this._height;if(this._ori)if(this._ori==="+")h=0.5*this._height;else if(this._ori==="-")e=0.5*this._height;if(b-c<j){c=(b+c-j)/2;b=c+j}a.moveTo(c+e,0+i);a.lineTo(b-h,0+i);a.lineTo(b-h,0);a.lineTo(b,0+this._height/2);a.lineTo(b-h,0+d);a.lineTo(b-h,0+i+i);a.lineTo(c+e,0+i+i);a.lineTo(c+e,0+d);a.lineTo(c,0+d/2);a.lineTo(c+e,0);a.lineTo(c+e,0+i)};
  AArrowGlyph.prototype.draw=function(a){a.beginPath();this.makePath(a);if(this._fill){a.fillStyle=this._fill;a.fill()}if(this._stroke){a.strokeStyle=this._stroke;a.stroke()}};AArrowGlyph.prototype.toSVG=function(){var a=new SVGPath;this.makePath(a);return makeElementNS(NS_SVG,"path",null,{d:a.toPathData(),fill:this._fill||"none",stroke:this._stroke||"none"})};function SpanGlyph(a,b,c,d){this._min=a;this._max=b;this._height=c;this._stroke=d}SpanGlyph.prototype.min=function(){return this._min};
  SpanGlyph.prototype.max=function(){return this._max};SpanGlyph.prototype.height=function(){return this._height};SpanGlyph.prototype.drawPath=function(a){var b=this._min,c=this._max,d=this._height,e=d/2;a.moveTo(b,e);a.lineTo(c,e);a.moveTo(b,0);a.lineTo(b,d);a.moveTo(c,0);a.lineTo(c,d)};SpanGlyph.prototype.draw=function(a){a.beginPath();this.drawPath(a);a.strokeStyle=this._stroke;a.stroke()};
  SpanGlyph.prototype.toSVG=function(){var a=new SVGPath;this.drawPath(a);return makeElementNS(NS_SVG,"path",null,{d:a.toPathData(),stroke:this._stroke||"none"})};function LineGlyph(a,b,c,d,e,h){this._min=a;this._max=b;this._height=c;this._style=d;this._strand=e;this._stroke=h}LineGlyph.prototype.min=function(){return this._min};LineGlyph.prototype.max=function(){return this._max};LineGlyph.prototype.height=function(){return this._height};
  LineGlyph.prototype.drawPath=function(a){var b=this._min,c=this._max,d=this._height,e=d/2;if(this._style==="hat"){a.moveTo(b,e);a.lineTo((b+c)/2,this._strand==="-"?d:0)}else a.moveTo(b,e);a.lineTo(c,e)};LineGlyph.prototype.draw=function(a){a.beginPath();this.drawPath(a);a.strokeStyle=this._stroke;if(this._style==="dashed"&&a.setLineDash){a.save();a.setLineDash([3]);a.stroke();a.restore()}else a.stroke()};
  LineGlyph.prototype.toSVG=function(){var a=new SVGPath;this.drawPath(a);a={d:a.toPathData(),stroke:this._stroke||"none"};if(this._style==="dashed")a.strokeDasharray="3";return makeElementNS(NS_SVG,"path",null,a)};function PrimersGlyph(a,b,c,d,e){this._min=a;this._max=b;this._height=c;this._fill=d;this._stroke=e}PrimersGlyph.prototype.min=function(){return this._min};PrimersGlyph.prototype.max=function(){return this._max};PrimersGlyph.prototype.height=function(){return this._height};
  PrimersGlyph.prototype.drawStemPath=function(a){var b=this._max,c=this._height/2;a.moveTo(this._min,c);a.lineTo(b,c)};PrimersGlyph.prototype.drawTrigsPath=function(a){var b=this._min,c=this._max,d=this._height,e=d/2;a.moveTo(b,0);a.lineTo(b+d,e);a.lineTo(b,d);a.lineTo(b,0);a.moveTo(c,0);a.lineTo(c-d,e);a.lineTo(c,d);a.lineTo(c,0)};
  PrimersGlyph.prototype.draw=function(a){a.beginPath();this.drawStemPath(a);a.strokeStyle=this._stroke;a.stroke();a.beginPath();this.drawTrigsPath(a);a.fillStyle=this._fill;a.fill()};PrimersGlyph.prototype.toSVG=function(){var a=new SVGPath;this.drawStemPath(a);var b=new SVGPath;this.drawTrigsPath(b);return makeElementNS(NS_SVG,"g",[makeElementNS(NS_SVG,"path",null,{d:a.toPathData(),stroke:this._stroke||"none"}),makeElementNS(NS_SVG,"path",null,{d:b.toPathData(),fill:this._fill||"none"})])};
  function ArrowGlyph(a,b,c,d,e,h,j){this._min=a;this._max=b;this._height=c;this._color=d;this._parallel=e;this._sw=h;this._ne=j}ArrowGlyph.prototype.min=function(){return this._min};ArrowGlyph.prototype.max=function(){return this._max};ArrowGlyph.prototype.height=function(){return this._height};
  ArrowGlyph.prototype.drawPath=function(a){var b=this._min,c=this._max,d=this._height;if(this._parallel){var e=d/2,h=0.4*d;if(this._sw){a.moveTo(b+e,d-h);a.lineTo(b+e,d);a.lineTo(b,e);a.lineTo(b+e,0);a.lineTo(b+e,h)}else{a.moveTo(b,d-h);a.lineTo(b,h)}if(this._ne){a.lineTo(c-e,h);a.lineTo(c-e,0);a.lineTo(c,e);a.lineTo(c-e,d);a.lineTo(c-e,d-h)}else{a.lineTo(c,h);a.lineTo(c,d-h)}}else{e=(b+c)/2;h=0.4*(c-b);var j=d/3;if(this._ne){a.moveTo(b+h,j);a.lineTo(b,j);a.lineTo(e,0);a.lineTo(c,j);a.lineTo(c-h,j)}else{a.moveTo(b+
  h,0);a.lineTo(c-h,0)}if(this._sw){a.lineTo(c-h,d-j);a.lineTo(c,d-j);a.lineTo(e,d);a.lineTo(b,d-j);a.lineTo(b+h,d-j)}else{a.lineTo(c-h,d);a.lineTo(b+h,d)}}a.closePath()};ArrowGlyph.prototype.draw=function(a){a.beginPath();this.drawPath(a);a.fillStyle=this._color;a.fill()};ArrowGlyph.prototype.toSVG=function(){var a=new SVGPath;this.drawPath(a);return makeElementNS(NS_SVG,"path",null,{d:a.toPathData(),fill:this._color})};
  function TooManyGlyph(a,b,c,d,e){this._min=a;this._max=b;this._height=c;this._fill=d;this._stroke=e}TooManyGlyph.prototype.min=function(){return this._min};TooManyGlyph.prototype.max=function(){return this._max};TooManyGlyph.prototype.height=function(){return this._height};TooManyGlyph.prototype.toSVG=function(){return makeElementNS(NS_SVG,"rect",null,{x:this._min,y:0,width:this._max-this._min,height:this._height,stroke:this._stroke||"none",fill:this._fill||"none"})};
  TooManyGlyph.prototype.draw=function(a){if(this._fill){a.fillStyle=this._fill;a.fillRect(this._min,0,this._max-this._min,this._height)}if(this._stroke){a.strokeStyle=this._stroke;a.strokeRect(this._min,0,this._max-this._min,this._height);a.beginPath();for(var b=2;b<this._height;b+=3){a.moveTo(this._min,b);a.lineTo(this._max,b)}a.stroke()}};function TextGlyph(a,b,c,d,e){this._min=a;this._max=b;this._height=c;this._fill=d;this._string=e;this._textLen=GLOBAL_GC.measureText(e).width}
  TextGlyph.prototype.min=function(){return this._min};TextGlyph.prototype.max=function(){return Math.max(this._max,this._min+this._textLen)};TextGlyph.prototype.height=function(){return this._height};TextGlyph.prototype.draw=function(a){a.fillStyle=this._fill;a.fillText(this._string,this._min,this._height-4)};TextGlyph.prototype.toSVG=function(){return makeElementNS(NS_SVG,"text",this._string,{x:this._min,y:this._height-4})};
  function SequenceGlyph(a,b,c,d,e){this._min=a;this._max=b;this._height=c;this._seq=d;this._ref=e}SequenceGlyph.prototype.min=function(){return this._min};SequenceGlyph.prototype.max=function(){return this._max};SequenceGlyph.prototype.height=function(){return this._height};
  SequenceGlyph.prototype.draw=function(a){for(var b=this._seq,c=(this._max-this._min+1)/this._seq.length,d=0;d<b.length;++d){var e=b.substr(d,1).toUpperCase(),h=baseColors[e];h||(h="gray");a.fillStyle=h;c>=8?a.fillText(e,this._min+d*c,8):a.fillRect(this._min+d*c,0,c,this._height)}};
  SequenceGlyph.prototype.toSVG=function(){for(var a=this._seq,b=(this._max-this._min+1)/this._seq.length,c=makeElementNS(NS_SVG,"g"),d=0;d<a.length;++d){var e=a.substr(d,1).toUpperCase(),h=baseColors[e];h||(h="gray");b>=8?c.appendChild(makeElementNS(NS_SVG,"text",e,{x:this._min+d*b,y:8,fill:h})):c.appendChild(makeElementNS(NS_SVG,"rect",null,{x:this._min+d*b,y:0,width:b,height:this._height,fill:h}))}return c};function TranslatedGlyph(a,b,c,d){this.glyph=a;this._height=d;this._x=b;this._y=c}
  TranslatedGlyph.prototype.height=function(){return this._height};TranslatedGlyph.prototype.min=function(){return this.glyph.min()+this._x};TranslatedGlyph.prototype.max=function(){return this.glyph.max()+this._x};TranslatedGlyph.prototype.draw=function(a){a.save();a.translate(this._x,this._y);this.glyph.draw(a);a.restore()};TranslatedGlyph.prototype.toSVG=function(){var a=this.glyph.toSVG();a.setAttribute("transform","translate("+this._x+","+this._y+")");return a};
  function PointGlyph(a,b,c,d){this._x=a;this._y=b;this._height=c;this._fill=d}PointGlyph.prototype.min=function(){return this._x-2};PointGlyph.prototype.max=function(){return this._x+2};PointGlyph.prototype.height=function(){return this._height};PointGlyph.prototype.draw=function(a){a.save();a.globalAlpha=0.3;a.fillStyle=this._fill;a.beginPath();a.arc(this._x,this._y,1.5,0,6.29);a.fill();a.restore()};
  PointGlyph.prototype.toSVG=function(){return makeElementNS(NS_SVG,"circle",null,{cx:this._x,cy:this._y,r:2,fill:this._fill,stroke:"none"})};function GridGlyph(a){this._height=a||50}GridGlyph.prototype.notSelectable=true;GridGlyph.prototype.min=function(){return-100000};GridGlyph.prototype.max=function(){return 1E5};GridGlyph.prototype.height=function(){return this._height};
  GridGlyph.prototype.draw=function(a){a.save();a.strokeStyle="black";a.lineWidth=0.1;a.beginPath();for(var b=0;b<=this._height;b+=10){a.moveTo(-5000,b);a.lineTo(5E3,b)}a.stroke();a.restore()};GridGlyph.prototype.toSVG=function(){for(var a=new SVGPath,b=0;b<=this._height;b+=10){a.moveTo(-5000,b);a.lineTo(5E3,b)}return makeElementNS(NS_SVG,"path",null,{d:a.toPathData(),fill:"none",stroke:"black",strokeWidth:"0.1px"})};
  function StarGlyph(a,b,c,d,e){this._x=a;this._r=b;this._points=c;this._fill=d;this._stroke=e}StarGlyph.prototype.min=function(){return this._x-this._r};StarGlyph.prototype.max=function(){return this._x+this._r};StarGlyph.prototype.height=function(){return 2*this._r};
  StarGlyph.prototype.drawPath=function(a){for(var b=this._x,c=this._r,d=this._r,e=0;e<this._points;++e){var h=e*6.28/this._points,j=b+d*Math.sin(h);h=c-d*Math.cos(h);e==0?a.moveTo(j,h):a.lineTo(j,h);h=(e+0.5)*6.28/this._points;j=b+0.4*d*Math.sin(h);h=c-0.4*d*Math.cos(h);a.lineTo(j,h)}a.closePath()};StarGlyph.prototype.draw=function(a){a.beginPath();this.drawPath(a);a.fillStyle=this._fill;a.fill()};
  StarGlyph.prototype.toSVG=function(){var a=new SVGPath;this.drawPath(a);return makeElementNS(NS_SVG,"path",null,{d:a.toPathData(),fill:this._fill})};
  Browser.prototype.nukeStatus=function(){delete localStorage["dalliance."+this.cookieKey+".view-chr"];delete localStorage["dalliance."+this.cookieKey+".view-start"];delete localStorage["dalliance."+this.cookieKey+".view-end"];delete localStorage["dalliance."+this.cookieKey+".sources"];delete localStorage["dalliance."+this.cookieKey+".version"];delete localStorage["dalliance."+this.cookieKey+".reverse-scrolling"];delete localStorage["dalliance."+this.cookieKey+".ruler-location"]};
  Browser.prototype.storeStatus=function(){this.storeViewStatus();this.storeTierStatus()};Browser.prototype.storeViewStatus=function(){if(!(!this.cookieKey||this.noPersist)){localStorage["dalliance."+this.cookieKey+".view-chr"]=this.chr;localStorage["dalliance."+this.cookieKey+".view-start"]=this.viewStart|0;localStorage["dalliance."+this.cookieKey+".view-end"]=this.viewEnd|0;if(this.currentSeqMax)localStorage["dalliance."+this.cookieKey+".current-seq-length"]=this.currentSeqMax}};
  Browser.prototype.storeTierStatus=function(){if(!(!this.cookieKey||this.noPersist)){for(var a=[],b=0;b<this.tiers.length;++b)this.tiers[b].dasSource.noPersist||a.push(this.tiers[b].dasSource);localStorage["dalliance."+this.cookieKey+".sources"]=JSON.stringify(a);localStorage["dalliance."+this.cookieKey+".hubs"]=JSON.stringify(this.hubs);localStorage["dalliance."+this.cookieKey+".reverse-scrolling"]=this.reverseScrolling;localStorage["dalliance."+this.cookieKey+".ruler-location"]=this.rulerLocation;
  localStorage["dalliance."+this.cookieKey+".version"]=VERSION.CONFIG}};
  Browser.prototype.restoreStatus=function(){if(!this.noPersist){var a=localStorage["dalliance."+this.cookieKey+".version"];a=a?a|0:-100;if(VERSION.CONFIG==a){a=localStorage["dalliance."+this.cookieKey+".configHash"]||"";var b=hex_sha1(miniJSONify({sources:this.sources,hubs:this.hubs}));if(b!=a)localStorage["dalliance."+this.cookieKey+".configHash"]=b;else{a={};for(b=0;b<this.sources.length;++b){var c=this.sources[b];a[hex_sha1(miniJSONify(c))]=c}b=localStorage["dalliance."+this.cookieKey+".view-chr"];
  c=localStorage["dalliance."+this.cookieKey+".view-start"]|0;var d=localStorage["dalliance."+this.cookieKey+".view-end"]|0;if(b&&c&&d){this.chr=b;this.viewStart=c;this.viewEnd=d;if(b=localStorage["dalliance."+this.cookieKey+".current-seq-length"])this.currentSeqMax=b|0}this.reverseScrolling=(b=localStorage["dalliance."+this.cookieKey+".reverse-scrolling"])&&b=="true";if(b=localStorage["dalliance."+this.cookieKey+".ruler-location"])this.rulerLocation=b;if(b=localStorage["dalliance."+this.cookieKey+
  ".sources"]){this.sources=JSON.parse(b);for(b=0;b<this.sources.length;++b){c=this.sources[b];d=hex_sha1(miniJSONify(c,{props:true,coords:true}));if(d=a[d])if(d.featureInfoPlugin)c.featureInfoPlugin=d.featureInfoPlugin}}if(a=localStorage["dalliance."+this.cookieKey+".hubs"])this.hubs=JSON.parse(a)}}}};
  DasTier.prototype.initSources=function(){var a=new DummyFeatureSource,b;if(this.dasSource.tier_type=="sequence")b=this.dasSource.twoBitURI?new TwoBitSequenceSource(this.dasSource):new DASSequenceSource(this.dasSource);else a=this.browser.createFeatureSource(this.dasSource);this.featureSource=a;this.sequenceSource=b};
  Browser.prototype.createFeatureSource=function(a){var b=this.sourceCache.get(a);if(b)return b;if(a.bwgURI||a.bwgBlob)b=new BWGFeatureSource(a);else if(a.bamURI||a.bamBlob)b=new BAMFeatureSource(a);else if(a.bamblrURI)b=new BamblrFeatureSource(a);else if(a.jbURI)b=new JBrowseFeatureSource(a);else if(a.tier_type=="ensembl")b=new EnsemblFeatureSource(a);else if(a.uri||a.features_uri)b=new DASFeatureSource(a);if(a.overlay){var c=[];b&&c.push(b);for(b=0;b<a.overlay.length;++b)c.push(this.createFeatureSource(a.overlay[b]));
  b=new OverlayFeatureSource(c,a)}if(a.mapping)b=new MappedFeatureSource(b,this.chains[a.mapping]);if(a.name&&!b.name)b.name=a.name;if(b!=null){b=new CachingFeatureSource(b);this.sourceCache.put(a,b)}return b};function SourceCache(){this.sourcesByURI={}}SourceCache.prototype.get=function(a){var b=this.sourcesByURI[sourceDataURI(a)];if(b)for(var c=0;c<b.configs.length;++c)if(sourcesAreEqual(b.configs[c],a))return b.sources[c]};
  SourceCache.prototype.put=function(a,b){var c=sourceDataURI(a),d=this.sourcesByURI[c];if(!d){d={configs:[],sources:[]};this.sourcesByURI[c]=d}d.configs.push(a);d.sources.push(b)};var __cfs_id_seed=0;function CachingFeatureSource(a){this.source=a;this.cfsid="cfs"+ ++__cfs_id_seed;if(a.name)this.name=a.name}CachingFeatureSource.prototype.getStyleSheet=function(a){this.source.getStyleSheet(a)};CachingFeatureSource.prototype.getScales=function(){return this.source.getScales()};
  CachingFeatureSource.prototype.addActivityListener=function(a){this.source.addActivityListener&&this.source.addActivityListener(a)};CachingFeatureSource.prototype.findNextFeature=function(a,b,c,d){this.source.findNextFeature(a,b,c,d)};CachingFeatureSource.prototype.quantFindNextFeature=function(a,b,c,d,e){this.source.quantFindNextFeature(a,b,c,d,e)};CachingFeatureSource.prototype.capabilities=function(){return this.source.capabilities?this.source.capabilities():{}};
  CachingFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){var i=h.awaitedFeatures[this.cfsid];if(!i){i=new Awaited;h.awaitedFeatures[this.cfsid]=i;this.source.fetch(a,b,c,d,e,h,function(l,m,o){i.res||i.provide({status:l,features:m,scale:o})})}i.await(function(l){j(l.status,l.features,l.scale)})};function DASFeatureSource(a){this.dasSource=a;this.busy=0;this.activityListeners=[]}DASFeatureSource.prototype.addActivityListener=function(a){this.activityListeners.push(a)};
  DASFeatureSource.prototype.notifyActivity=function(){for(var a=0;a<this.activityListeners.length;++a)try{this.activityListeners[a](this.busy)}catch(b){console.log(b)}};DASFeatureSource.prototype.getStyleSheet=function(a){this.dasSource.stylesheet(function(b){a(b)},function(){a(null,"Couldn't fetch DAS stylesheet")})};
  DASFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){if(e&&e.length==0)j(null,[],d);else if(this.dasSource.uri||this.dasSource.features_uri){if(this.dasSource.dasStaticFeatures&&this.cachedStaticFeatures)return j(null,this.cachedStaticFeatures,this.cachedStaticScale);var i=this.dasSource.maxbins!==false;e={type:e};if(i)e.maxbins=1+((c-b)/d|0);var l=this;l.busy++;l.notifyActivity();this.dasSource.features(new DASSegment(a,b,c),e,function(m,o){l.busy--;l.notifyActivity();var r=d;i||(r=0.1);if(!o&&
  l.dasSource.dasStaticFeatures){l.cachedStaticFeatures=m;l.cachedStaticScale=r}j(o,m,r)})}};
  DASFeatureSource.prototype.findNextFeature=this.sourceFindNextFeature=function(a,b,c,d){if(this.dasSource.capabilities&&arrayIndexOf(this.dasSource.capabilities,"das1:adjacent-feature")>=0){var e=this;if(this.dasAdjLock)return dlog("Already looking for a next feature, be patient!");this.dasAdjLock=true;a={adjacent:a+":"+(b|0)+":"+(c>0?"F":"B")};if(b=thisTier.getDesiredTypes(thisTier.browser.scale))a.types=b;thisTier.dasSource.features(null,a,function(h){e.dasAdjLock=false;if(h.length>0&&h[0]!=null){dlog("DAS adjacent seems to be working...");
  d(h[0])}})}};function DASSequenceSource(a){this.dasSource=a;this.awaitedEntryPoints=new Awaited;var b=this;this.dasSource.entryPoints(function(c){b.awaitedEntryPoints.provide(c)})}DASSequenceSource.prototype.fetch=function(a,b,c,d,e){this.dasSource.sequence(new DASSegment(a,b,c),function(h){return h.length==1?e(null,h[0]):e("Didn't get sequence")})};
  DASSequenceSource.prototype.getSeqInfo=function(a,b){this.awaitedEntryPoints.await(function(c){for(var d=0;d<c.length;++d)if(c[d].name==a)return b({length:c[d].end});return b()})};function TwoBitSequenceSource(a){var b=this;this.source=a;this.twoBit=new Awaited;makeTwoBit(new URLFetchable(a.twoBitURI),function(c,d){d?dlog(d):b.twoBit.provide(c)})}
  TwoBitSequenceSource.prototype.fetch=function(a,b,c,d,e){this.twoBit.await(function(h){h.fetch(a,b,c,function(j,i){if(i)return e(i,null);else{var l=new DASSequence(a,b,c,"DNA",j);return e(null,l)}})})};TwoBitSequenceSource.prototype.getSeqInfo=function(a,b){this.twoBit.await(function(c){c.getSeq(a)?c.getSeq(a).length(function(d){b({length:d})}):b()})};DASFeatureSource.prototype.getScales=function(){return[]};var bwg_preflights={};
  function BWGFeatureSource(a){var b=this;this.bwgSource=this.opts=a;b.bwgHolder=new Awaited;this.busy=0;this.activityListeners=[];if(this.opts.preflight){var c=bwg_preflights[this.opts.preflight];if(!c){c=new Awaited;bwg_preflights[this.opts.preflight]=c;var d=new XMLHttpRequest;d.onreadystatechange=function(){if(d.readyState==4)d.status==200?c.provide("success"):c.provide("failure")};d.open("get",this.opts.preflight+"?"+hex_sha1("salt"+Date.now()),true);if(this.opts.credentials)d.withCredentials=
  true;d.send("")}c.await(function(e){e==="success"&&b.init()})}else b.init()}BWGFeatureSource.prototype.addActivityListener=function(a){this.activityListeners.push(a)};BWGFeatureSource.prototype.notifyActivity=function(){for(var a=0;a<this.activityListeners.length;++a)try{this.activityListeners[a](this.busy)}catch(b){console.log(b)}};
  BWGFeatureSource.prototype.init=function(){var a=this,b,c;if(this.bwgSource.bwgURI){b=makeBwgFromURL;c=this.bwgSource.bwgURI}else{b=makeBwgFromFile;c=this.bwgSource.bwgBlob}b(c,function(d){a.bwgHolder.provide(d)},this.opts.credentials)};BWGFeatureSource.prototype.capabilities=function(){var a={leap:true};if(this.bwgHolder.res&&this.bwgHolder.res.type=="bigwig")a.quantLeap=true;return a};
  BWGFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){var i=this;this.bwgHolder.await(function(l){if(l==null)return j("Can't access binary file",null,null);var m;m=!e||e.length==0||arrayIndexOf(e,"density")>=0;if(i.opts.clientBin)m=false;if(l.type=="bigwig"||m||typeof i.opts.forceReduction!=="undefined"){m=-1;for(var o=0;o<l.zoomLevels.length;++o)if(l.zoomLevels[o].reduction<=d)m=o;else break;if(typeof i.opts.forceReduction!=="undefined")m=i.opts.forceReduction;m=m<0?l.getUnzoomedView():l.getZoomedView(m)}else m=
  l.getUnzoomedView();i.busy++;i.notifyActivity();m.readWigData(a,b,c,function(r){i.busy--;i.notifyActivity();var p=1E9;if(l.type==="bigwig"){var t=(c-b)/r.length/2;if(t<p)p=t}if(i.opts.link)for(t=0;t<r.length;++t){var q=r[t];if(q.label)q.links=[new DASLink("Link",i.opts.link.replace(/\$\$/,q.label))]}j(null,r,p)})})};
  BWGFeatureSource.prototype.quantFindNextFeature=function(a,b,c,d,e){var h=this;h.busy++;h.notifyActivity();this.bwgHolder.res.thresholdSearch(a,b,c,d,function(j,i){h.busy--;h.notifyActivity();return e(j,i)})};BWGFeatureSource.prototype.findNextFeature=function(a,b,c,d){var e=this;e.busy++;e.notifyActivity();this.bwgHolder.res.getUnzoomedView().getFirstAdjacent(a,b,c,function(h){e.busy--;e.notifyActivity();h.length>0&&h[0]!=null&&d(h[0])})};
  BWGFeatureSource.prototype.getScales=function(){var a=this.bwgHolder.res;if(a){for(var b=[1],c=0;c<a.zoomLevels.length;++c)b.push(a.zoomLevels[c].reduction);return b}else return null};
  BWGFeatureSource.prototype.getStyleSheet=function(a){this.bwgHolder.await(function(b){if(!b)return a(null,"bbi error");var c=new DASStylesheet;if(b.type=="bigbed"){b=new DASStyle;b.glyph="BOX";b.FGCOLOR="black";b.BGCOLOR="blue";b.HEIGHT=8;b.BUMP=true;b.LABEL=true;b.ZINDEX=20;c.pushStyle({type:"bigwig"},null,b);b.glyph="BOX";b.FGCOLOR="black";b.BGCOLOR="red";b.HEIGHT=10;b.BUMP=true;b.ZINDEX=20;c.pushStyle({type:"bb-translation"},null,b);b=new DASStyle;b.glyph="BOX";b.FGCOLOR="black";b.BGCOLOR="white";
  b.HEIGHT=10;b.ZINDEX=10;b.BUMP=true;b.LABEL=true;c.pushStyle({type:"bb-transcript"},null,b);b=new DASStyle;b.glyph="HISTOGRAM";b.COLOR1="white";b.COLOR2="black";b.HEIGHT=30;c.pushStyle({type:"density"},null,b)}else{b=new DASStyle;b.glyph="HISTOGRAM";b.COLOR1="white";b.COLOR2="black";b.HEIGHT=30;c.pushStyle({type:"default"},null,b)}return a(c)})};function BamblrFeatureSource(a){this.bamblr=a.bamblrURI}BamblrFeatureSource.prototype.getScales=function(){return[]};
  BamblrFeatureSource.prototype.getStyleSheet=function(a){var b=new DASStylesheet,c=new DASStyle;c.glyph="HISTOGRAM";c.COLOR1="black";c.COLOR2="red";c.HEIGHT=30;b.pushStyle({type:"default"},null,c);return a(b)};
  BamblrFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){var i=d|0;if(i<1)i=1;(new URLFetchable(this.bamblr+"?seq="+a+"&min="+b+"&max="+c+"&rez="+i)).fetch(function(l){if(l==null)dlog("failing bamblr");else{l=new Int32Array(l);for(var m=[],o=0;o<l.length;++o){var r=new DASFeature;r.min=b+o*i;r.max=r.min+i-1;r.segment=a;r.type="bamblr";r.score=l[o];m.push(r)}j(null,m,i)}})};
  function BAMFeatureSource(a){var b=this;this.bamSource=a;this.opts={credentials:a.credentials,preflight:a.preflight};this.bamHolder=new Awaited;this.busy=0;this.activityListeners=[];if(this.opts.preflight){var c=bwg_preflights[this.opts.preflight];if(!c){c=new Awaited;bwg_preflights[this.opts.preflight]=c;var d=new XMLHttpRequest;d.onreadystatechange=function(){if(d.readyState==4)d.status==200?c.provide("success"):c.provide("failure")};d.open("get",this.opts.preflight+"?"+hex_sha1("salt"+Date.now()),
  true);if(this.opts.credentials)d.withCredentials="true";d.send("")}c.await(function(e){e==="success"&&b.init()})}else b.init()}BAMFeatureSource.prototype.addActivityListener=function(a){this.activityListeners.push(a)};BAMFeatureSource.prototype.notifyActivity=function(){for(var a=0;a<this.activityListeners.length;++a)try{this.activityListeners[a](this.busy)}catch(b){console.log(b)}};
  BAMFeatureSource.prototype.init=function(){var a=this,b,c;if(this.bamSource.bamBlob){b=new BlobFetchable(this.bamSource.bamBlob);c=new BlobFetchable(this.bamSource.baiBlob)}else{b=new URLFetchable(this.bamSource.bamURI,{credentials:this.opts.credentials});c=new URLFetchable(this.bamSource.baiURI||this.bamSource.bamURI+".bai",{credentials:this.opts.credentials})}makeBam(b,c,function(d){a.bamHolder.provide(d)})};
  BAMFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){var i=this;i.busy++;i.notifyActivity();this.bamHolder.await(function(l){l.fetch(a,b,c,function(m,o){i.busy--;i.notifyActivity();if(o)j(o,null,null);else{for(var r=[],p=0;p<m.length;++p){var t=m[p],q=new DASFeature;q.min=t.pos+1;q.max=t.pos+t.seq.length;q.segment=t.segment;q.type="bam";q.id=t.readName;q.notes=["Sequence="+t.seq,"CIGAR="+t.cigar,"MQ="+t.mq];q.seq=t.seq;r.push(q)}j(null,r,1E9)}})})};BAMFeatureSource.prototype.getScales=function(){return 1E9};
  BAMFeatureSource.prototype.getStyleSheet=function(a){this.bamHolder.await(function(){var b=new DASStylesheet,c=new DASStyle;c.glyph="HISTOGRAM";c.COLOR1="black";c.COLOR2="red";c.HEIGHT=30;b.pushStyle({type:"density"},"low",c);b.pushStyle({type:"density"},"medium",c);c=new DASStyle;c.glyph="__SEQUENCE";c.FGCOLOR="black";c.BGCOLOR="blue";c.HEIGHT=8;c.BUMP=true;c.LABEL=false;c.ZINDEX=20;b.pushStyle({type:"bam"},"high",c);return a(b)})};
  function MappedFeatureSource(a,b){this.source=a;this.mapping=b;this.activityListeners=[];this.busy=0}MappedFeatureSource.prototype.addActivityListener=function(a){this.activityListeners.push(a)};MappedFeatureSource.prototype.notifyActivity=function(){for(var a=0;a<this.activityListeners.length;++a)try{this.activityListeners[a](this.busy)}catch(b){console.log(b)}};MappedFeatureSource.prototype.getStyleSheet=function(a){return this.source.getStyleSheet(a)};MappedFeatureSource.prototype.getScales=function(){return this.source.getScales()};
  MappedFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){var i=this;i.busy++;i.notifyActivity();this.mapping.sourceBlocksForRange(a,b,c,function(l){if(l.length==0){i.busy--;i.notifyActivity();j("No mapping available for this regions",[],d)}else{l=l[0];i.source.fetch(l.name,l.start,l.end,d,e,h,function(m,o,r){i.busy--;i.notifyActivity();var p=[];if(o)for(var t=0;t<o.length;++t){var q=o[t],s=q.segment;if(s.indexOf("chr")==0)s=s.substr(3);var u=i.mapping.mapPoint(s,q.min);s=i.mapping.mapPoint(s,q.max);
  if(!u||!s||u.seq!=s.seq||u.seq!=a)q.parts&&q.parts.length>0&&p.push(q);else{q.segment=u.seq;q.min=u.pos;q.max=s.pos;if(q.min>q.max){s=q.max;q.max=q.min;q.min=s}if(u.flipped)if(q.orientation=="-")q.orientation="+";else if(q.orientation=="+")q.orientation="-";p.push(q)}}j(m,p,r)})}})};function DummyFeatureSource(){}DummyFeatureSource.prototype.getScales=function(){return null};DummyFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){return j(null,[],1E9)};
  DummyFeatureSource.prototype.getStyleSheet=function(a){var b=new DASStylesheet,c=new DASStyle;c.glyph="BOX";c.BGCOLOR="blue";c.FGCOLOR="black";b.pushStyle({type:"default"},null,c);return a(b)};function DummySequenceSource(){}DummySequenceSource.prototype.fetch=function(a,b,c,d,e){return e(null,null)};function JBrowseFeatureSource(a){this.store=new JBrowseStore(a.jbURI,a.jbQuery)}JBrowseFeatureSource.prototype.getScales=function(){return null};
  JBrowseFeatureSource.prototype.getStyleSheet=function(a){var b=new DASStylesheet,c=new DASStyle;c.glyph="BOX";c.FGCOLOR="black";c.BGCOLOR="green";c.HEIGHT=8;c.BUMP=true;c.LABEL=true;c.ZINDEX=20;b.pushStyle({type:"default"},null,c);return a(b)};JBrowseFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){e&&e.length==0?j(null,[],d):this.store.features(new DASSegment(a,b,c),{},function(i,l){j(l,i,1E5)})};function sourceAdapterIsCapable(a,b){return a.capabilities?a.capabilities()[b]:false}
  function JBrowseStore(a,b){this.base=a;this.query=b}var topLevelResp;
  JBrowseStore.prototype.features=function(a,b,c){b=b||{};url=this.base+"/features/"+a.name;b=[];this.query&&b.push(this.query);if(a.isBounded){b.push("start="+a.start);b.push("end="+a.end)}if(b.length>0)url=url+"?"+b.join("&");var d=new XMLHttpRequest;d.onreadystatechange=function(){if(d.readyState==4)if(d.status>=300)c(null,"Error code "+d.status);else{var e=JSON.parse(d.response).features,h=[];for(fi=0;fi<e.length;++fi){var j=e[fi],i=new DASFeature;i.segment=a;i.min=(j.start|0)+1;i.max=j.end|0;if(j.name)i.label=
  j.name;i.type=j.type||"unknown";h.push(i)}c(h)}};d.open("GET",url,true);d.responseType="text";d.send("")};function EnsemblFeatureSource(a){this.source=a;this.base=a.uri||"http://beta.rest.ensembl.org";this.species=a.species||"human";this.activityListeners=[];this.busy=0;this.type=typeof a.type==="string"?[a.type]:a.type||["regulatory"]}EnsemblFeatureSource.prototype.addActivityListener=function(a){this.activityListeners.push(a)};
  EnsemblFeatureSource.prototype.notifyActivity=function(){for(var a=0;a<this.activityListeners.length;++a)try{this.activityListeners[a](this.busy)}catch(b){console.log(b)}};
  EnsemblFeatureSource.prototype.getStyleSheet=function(a){var b=new DASStylesheet,c=new DASStyle;c.glyph="__NONE";this.type.indexOf("exon")>=0&&b.pushStyle({type:"transcript"},null,c);if(this.type.indexOf("exon")>=0||this.type.indexOf("transcript")>=0)b.pushStyle({type:"gene"},null,c);c=new DASStyle;c.glyph="BOX";c.FGCOLOR="black";c.BGCOLOR="red";c.HEIGHT=8;c.BUMP=true;c.LABEL=true;c.ZINDEX=10;b.pushStyle({type:"cds"},null,c);c=new DASStyle;c.glyph="BOX";c.FGCOLOR="black";c.BGCOLOR="orange";c.HEIGHT=
  8;c.BUMP=true;c.LABEL=true;c.ZINDEX=20;b.pushStyle({type:"default"},null,c);return a(b)};EnsemblFeatureSource.prototype.getScales=function(){return[]};
  EnsemblFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){var i=this;url=this.base+"/feature/region/"+this.species+"/"+a+":"+b+"-"+c;b=[];for(c=0;c<this.type.length;++c)b.push("feature="+this.type[c]);b.push("content-type=application/json");url=url+"?"+b.join(";");var l=new XMLHttpRequest;l.onreadystatechange=function(){i.busy--;i.notifyActivity();if(l.readyState==4)if(l.status>=300)j("Error code "+l.status,null);else{var m=JSON.parse(l.response),o=[];for(fi=0;fi<m.length;++fi){var r=m[fi],p=new DASFeature;
  p.segment=a;p.min=r.start|0;p.max=r.end|0;p.type=r.feature_type||"unknown";p.id=r.ID;if(r.Parent){var t=new DASGroup;t.id=r.Parent;p.groups=[t]}if(r.strand)if(r.strand<0)p.orientation="-";else if(r.strand>0)p.orientation="+";o.push(p)}j(null,o)}};i.busy++;i.notifyActivity();l.open("GET",url,true);l.responseType="text";l.send("")};
  function OverlayFeatureSource(a,b){this.sources=a;this.opts=b||{};this.activityListeners=[];this.business=[];for(var c=0;c<this.sources.length;++c)this.initN(c);this.merge=b.merge=="concat"?OverlayFeatureSource_merge_concat:OverlayFeatureSource_merge_byKey}OverlayFeatureSource.prototype.initN=function(a){var b=this.sources[a],c=this;this.business[a]=0;b.addActivityListener&&b.addActivityListener(function(d){c.business[a]=d;c.notifyActivity()})};OverlayFeatureSource.prototype.addActivityListener=function(a){this.activityListeners.push(a)};
  OverlayFeatureSource.prototype.notifyActivity=function(){for(var a=0,b=0;b<this.business.length;++b)a+=this.business[b];for(b=0;b<this.activityListeners.length;++b)try{this.activityListeners[b](a)}catch(c){console.log(c)}};OverlayFeatureSource.prototype.getScales=function(){return this.sources[0].getScales()};OverlayFeatureSource.prototype.getStyleSheet=function(a){return this.sources[0].getStyleSheet(a)};
  OverlayFeatureSource.prototype.capabilities=function(){var a=this.sources[0];if(a.capabilities)return a.capabilities();return{}};OverlayFeatureSource.prototype.fetch=function(a,b,c,d,e,h,j){j=new OverlayBaton(this,j,this.sources.length);for(var i=0;i<this.sources.length;++i)this.fetchN(j,i,a,b,c,d,e,h)};OverlayFeatureSource.prototype.fetchN=function(a,b,c,d,e,h,j,i){this.sources[b].fetch(c,d,e,h,j,i,function(l,m,o){return a.completed(b,l,m,o)})};
  OverlayFeatureSource.prototype.quantFindNextFeature=function(a,b,c,d,e){return this.sources[0].quantFindNextFeature(a,b,c,d,e)};OverlayFeatureSource.prototype.findNextFeature=function(a,b,c,d){return this.sources[0].findNextFeature(a,b,c,d)};function OverlayBaton(a,b,c){this.source=a;this.callback=b;this.count=c;this.statusCount=this.returnCount=0;this.returns=[];this.features=[];this.statuses=[];this.scale=null}
  OverlayBaton.prototype.completed=function(a,b,c,d){if(this.scale==null||a==0)this.scale=d;if(this.returns[a])throw"Multiple returns for source "+a;this.returns[a]=true;this.returnCount++;this.features[a]=c;if(b){this.statuses[a]=b;this.statusCount++}if(this.returnCount==this.count)if(this.statusCount>0){a="";for(b=0;b<this.count;++b){c=this.statuses[b];if(c!=0){if(a.length>0)a+=", ";a+=c}}return this.callback(a,null,this.scale)}else this.callback(null,this.source.merge(this.features),this.scale)};
  OverlayFeatureSource.prototype.keyForFeature=function(a){return""+a.min+".."+a.max};function OverlayFeatureSource_merge_byKey(a){for(var b={},c=a[1],d=0;d<c.length;++d)b[this.keyForFeature(c[d])]=c[d];var e=[];a=a[0];for(d=0;d<a.length;++d){var h=a[d];if(c=b[this.keyForFeature(h)]){if(c.id)h.id=c.id;if(c.label)h.label=c.label}e.push(h)}return e}
  function OverlayFeatureSource_merge_concat(a){for(var b=[],c=0;c<a.length;++c)for(var d=a[c],e=this.sources[c].name,h=0;h<d.length;++h){var j=d[h];j.method=e;b.push(j)}return b}Browser.prototype.mergeSelectedTiers=function(){for(var a=[],b=0;b<this.selectedTiers.length;++b)a.push(shallowCopy(this.tiers[this.selectedTiers[b]].dasSource));this.addTier({name:"Merged",merge:"concat",overlay:a,noDownsample:true});this.setSelectedTier(this.tiers.length-1)};
  var MAX_WBITS=15,DEF_WBITS=MAX_WBITS,MAX_MEM_LEVEL=9,MANY=1440,BMAX=15,PRESET_DICT=32,Z_NO_FLUSH=0,Z_PARTIAL_FLUSH=1,Z_SYNC_FLUSH=2,Z_FULL_FLUSH=3,Z_FINISH=4,Z_DEFLATED=8,Z_OK=0,Z_STREAM_END=1,Z_NEED_DICT=2,Z_ERRNO=-1,Z_STREAM_ERROR=-2,Z_DATA_ERROR=-3,Z_MEM_ERROR=-4,Z_BUF_ERROR=-5,Z_VERSION_ERROR=-6,METHOD=0,FLAG=1,DICT4=2,DICT3=3,DICT2=4,DICT1=5,DICT0=6,BLOCKS=7,CHECK4=8,CHECK3=9,CHECK2=10,CHECK1=11,DONE=12,BAD=13,inflate_mask=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],
  IB_TYPE=0,IB_LENS=1,IB_STORED=2,IB_TABLE=3,IB_BTREE=4,IB_DTREE=5,IB_CODES=6,IB_DRY=7,IB_DONE=8,IB_BAD=9,fixed_bl=9,fixed_bd=5,fixed_tl=[96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,192,80,7,10,0,8,96,0,8,32,0,9,160,0,8,0,0,8,128,0,8,64,0,9,224,80,7,6,0,8,88,0,8,24,0,9,144,83,7,59,0,8,120,0,8,56,0,9,208,81,7,17,0,8,104,0,8,40,0,9,176,0,8,8,0,8,136,0,8,72,0,9,240,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,200,81,7,13,0,8,100,0,8,36,0,9,168,0,8,4,0,8,132,0,8,68,0,9,232,80,
  7,8,0,8,92,0,8,28,0,9,152,84,7,83,0,8,124,0,8,60,0,9,216,82,7,23,0,8,108,0,8,44,0,9,184,0,8,12,0,8,140,0,8,76,0,9,248,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,196,81,7,11,0,8,98,0,8,34,0,9,164,0,8,2,0,8,130,0,8,66,0,9,228,80,7,7,0,8,90,0,8,26,0,9,148,84,7,67,0,8,122,0,8,58,0,9,212,82,7,19,0,8,106,0,8,42,0,9,180,0,8,10,0,8,138,0,8,74,0,9,244,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,204,81,7,15,0,8,102,0,8,38,0,9,172,0,8,6,0,8,134,0,8,70,0,9,236,80,7,9,0,8,94,0,8,30,0,
  9,156,84,7,99,0,8,126,0,8,62,0,9,220,82,7,27,0,8,110,0,8,46,0,9,188,0,8,14,0,8,142,0,8,78,0,9,252,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,194,80,7,10,0,8,97,0,8,33,0,9,162,0,8,1,0,8,129,0,8,65,0,9,226,80,7,6,0,8,89,0,8,25,0,9,146,83,7,59,0,8,121,0,8,57,0,9,210,81,7,17,0,8,105,0,8,41,0,9,178,0,8,9,0,8,137,0,8,73,0,9,242,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,202,81,7,13,0,8,101,0,8,37,0,9,170,0,8,5,0,8,133,0,8,69,0,9,234,80,7,8,0,8,93,0,8,29,0,9,154,84,7,83,0,8,
  125,0,8,61,0,9,218,82,7,23,0,8,109,0,8,45,0,9,186,0,8,13,0,8,141,0,8,77,0,9,250,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,198,81,7,11,0,8,99,0,8,35,0,9,166,0,8,3,0,8,131,0,8,67,0,9,230,80,7,7,0,8,91,0,8,27,0,9,150,84,7,67,0,8,123,0,8,59,0,9,214,82,7,19,0,8,107,0,8,43,0,9,182,0,8,11,0,8,139,0,8,75,0,9,246,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,206,81,7,15,0,8,103,0,8,39,0,9,174,0,8,7,0,8,135,0,8,71,0,9,238,80,7,9,0,8,95,0,8,31,0,9,158,84,7,99,0,8,127,0,8,63,0,9,222,
  82,7,27,0,8,111,0,8,47,0,9,190,0,8,15,0,8,143,0,8,79,0,9,254,96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,193,80,7,10,0,8,96,0,8,32,0,9,161,0,8,0,0,8,128,0,8,64,0,9,225,80,7,6,0,8,88,0,8,24,0,9,145,83,7,59,0,8,120,0,8,56,0,9,209,81,7,17,0,8,104,0,8,40,0,9,177,0,8,8,0,8,136,0,8,72,0,9,241,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,201,81,7,13,0,8,100,0,8,36,0,9,169,0,8,4,0,8,132,0,8,68,0,9,233,80,7,8,0,8,92,0,8,28,0,9,153,84,7,83,0,8,124,0,8,60,0,9,217,82,7,23,0,8,108,0,
  8,44,0,9,185,0,8,12,0,8,140,0,8,76,0,9,249,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,197,81,7,11,0,8,98,0,8,34,0,9,165,0,8,2,0,8,130,0,8,66,0,9,229,80,7,7,0,8,90,0,8,26,0,9,149,84,7,67,0,8,122,0,8,58,0,9,213,82,7,19,0,8,106,0,8,42,0,9,181,0,8,10,0,8,138,0,8,74,0,9,245,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,205,81,7,15,0,8,102,0,8,38,0,9,173,0,8,6,0,8,134,0,8,70,0,9,237,80,7,9,0,8,94,0,8,30,0,9,157,84,7,99,0,8,126,0,8,62,0,9,221,82,7,27,0,8,110,0,8,46,0,9,189,0,8,14,
  0,8,142,0,8,78,0,9,253,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,195,80,7,10,0,8,97,0,8,33,0,9,163,0,8,1,0,8,129,0,8,65,0,9,227,80,7,6,0,8,89,0,8,25,0,9,147,83,7,59,0,8,121,0,8,57,0,9,211,81,7,17,0,8,105,0,8,41,0,9,179,0,8,9,0,8,137,0,8,73,0,9,243,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,203,81,7,13,0,8,101,0,8,37,0,9,171,0,8,5,0,8,133,0,8,69,0,9,235,80,7,8,0,8,93,0,8,29,0,9,155,84,7,83,0,8,125,0,8,61,0,9,219,82,7,23,0,8,109,0,8,45,0,9,187,0,8,13,0,8,141,0,8,77,0,
  9,251,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,199,81,7,11,0,8,99,0,8,35,0,9,167,0,8,3,0,8,131,0,8,67,0,9,231,80,7,7,0,8,91,0,8,27,0,9,151,84,7,67,0,8,123,0,8,59,0,9,215,82,7,19,0,8,107,0,8,43,0,9,183,0,8,11,0,8,139,0,8,75,0,9,247,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,207,81,7,15,0,8,103,0,8,39,0,9,175,0,8,7,0,8,135,0,8,71,0,9,239,80,7,9,0,8,95,0,8,31,0,9,159,84,7,99,0,8,127,0,8,63,0,9,223,82,7,27,0,8,111,0,8,47,0,9,191,0,8,15,0,8,143,0,8,79,0,9,255],fixed_td=[80,
  5,1,87,5,257,83,5,17,91,5,4097,81,5,5,89,5,1025,85,5,65,93,5,16385,80,5,3,88,5,513,84,5,33,92,5,8193,82,5,9,90,5,2049,86,5,129,192,5,24577,80,5,2,87,5,385,83,5,25,91,5,6145,81,5,7,89,5,1537,85,5,97,93,5,24577,80,5,4,88,5,769,84,5,49,92,5,12289,82,5,13,90,5,3073,86,5,193,192,5,24577],cplens=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],cplext=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,112,112],cpdist=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,
  129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],cpdext=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];function ZStream(){}ZStream.prototype.inflateInit=function(a,b){a||(a=DEF_WBITS);if(b)b=false;this.istate=new Inflate;return this.istate.inflateInit(this,b?-a:a)};ZStream.prototype.inflate=function(a){if(this.istate==null)return Z_STREAM_ERROR;return this.istate.inflate(this,a)};
  ZStream.prototype.inflateEnd=function(){if(this.istate==null)return Z_STREAM_ERROR;var a=istate.inflateEnd(this);this.istate=null;return a};ZStream.prototype.inflateSync=function(){return istate.inflateSync(this)};ZStream.prototype.inflateSetDictionary=function(a,b){return istate.inflateSetDictionary(this,a,b)};function Inflate(){this.was=[0]}
  Inflate.prototype.inflateReset=function(a){if(a==null||a.istate==null)return Z_STREAM_ERROR;a.total_in=a.total_out=0;a.msg=null;a.istate.mode=a.istate.nowrap!=0?BLOCKS:METHOD;a.istate.blocks.reset(a,null);return Z_OK};Inflate.prototype.inflateEnd=function(a){this.blocks!=null&&this.blocks.free(a);this.blocks=null;return Z_OK};
  Inflate.prototype.inflateInit=function(a,b){this.blocks=a.msg=null;nowrap=0;if(b<0){b=-b;nowrap=1}if(b<8||b>15){this.inflateEnd(a);return Z_STREAM_ERROR}this.wbits=b;a.istate.blocks=new InfBlocks(a,a.istate.nowrap!=0?null:this,1<<b);this.inflateReset(a);return Z_OK};
  Inflate.prototype.inflate=function(a,b){var c,d;if(a==null||a.istate==null||a.next_in==null)return Z_STREAM_ERROR;b=b==Z_FINISH?Z_BUF_ERROR:Z_OK;for(c=Z_BUF_ERROR;;)switch(a.istate.mode){case METHOD:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;if(((a.istate.method=a.next_in[a.next_in_index++])&15)!=Z_DEFLATED){a.istate.mode=BAD;a.msg="unknown compression method";a.istate.marker=5;break}if((a.istate.method>>4)+8>a.istate.wbits){a.istate.mode=BAD;a.msg="invalid window size";a.istate.marker=
  5;break}a.istate.mode=FLAG;case FLAG:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;d=a.next_in[a.next_in_index++]&255;if(((a.istate.method<<8)+d)%31!=0){a.istate.mode=BAD;a.msg="incorrect header check";a.istate.marker=5;break}if((d&PRESET_DICT)==0){a.istate.mode=BLOCKS;break}a.istate.mode=DICT4;case DICT4:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need=(a.next_in[a.next_in_index++]&255)<<24&4278190080;a.istate.mode=DICT3;case DICT3:if(a.avail_in==0)return c;c=b;a.avail_in--;
  a.total_in++;a.istate.need+=(a.next_in[a.next_in_index++]&255)<<16&16711680;a.istate.mode=DICT2;case DICT2:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.next_in[a.next_in_index++]&255)<<8&65280;a.istate.mode=DICT1;case DICT1:if(a.avail_in==0)return c;a.avail_in--;a.total_in++;a.istate.need+=a.next_in[a.next_in_index++]&255;a.adler=a.istate.need;a.istate.mode=DICT0;return Z_NEED_DICT;case DICT0:a.istate.mode=BAD;a.msg="need dictionary";a.istate.marker=0;return Z_STREAM_ERROR;
  case BLOCKS:c=a.istate.blocks.proc(a,c);if(c==Z_DATA_ERROR){a.istate.mode=BAD;a.istate.marker=0;break}if(c==Z_OK)c=b;if(c!=Z_STREAM_END)return c;c=b;a.istate.blocks.reset(a,a.istate.was);if(a.istate.nowrap!=0){a.istate.mode=DONE;break}a.istate.mode=CHECK4;case CHECK4:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need=(a.next_in[a.next_in_index++]&255)<<24&4278190080;a.istate.mode=CHECK3;case CHECK3:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.next_in[a.next_in_index++]&
  255)<<16&16711680;a.istate.mode=CHECK2;case CHECK2:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=(a.next_in[a.next_in_index++]&255)<<8&65280;a.istate.mode=CHECK1;case CHECK1:if(a.avail_in==0)return c;c=b;a.avail_in--;a.total_in++;a.istate.need+=a.next_in[a.next_in_index++]&255;if(a.istate.was[0]!=a.istate.need){a.istate.mode=BAD;a.msg="incorrect data check";a.istate.marker=5;break}a.istate.mode=DONE;case DONE:return Z_STREAM_END;case BAD:return Z_DATA_ERROR;default:return Z_STREAM_ERROR}};
  Inflate.prototype.inflateSetDictionary=function(a,b,c){var d=0,e=c;if(a==null||a.istate==null||a.istate.mode!=DICT0)return Z_STREAM_ERROR;if(a._adler.adler32(1,b,0,c)!=a.adler)return Z_DATA_ERROR;a.adler=a._adler.adler32(0,null,0,0);if(e>=1<<a.istate.wbits){e=(1<<a.istate.wbits)-1;d=c-e}a.istate.blocks.set_dictionary(b,d,e);a.istate.mode=BLOCKS;return Z_OK};var mark=[0,0,255,255];
  Inflate.prototype.inflateSync=function(a){var b,c,d;if(a==null||a.istate==null)return Z_STREAM_ERROR;if(a.istate.mode!=BAD){a.istate.mode=BAD;a.istate.marker=0}if((b=a.avail_in)==0)return Z_BUF_ERROR;c=a.next_in_index;for(d=a.istate.marker;b!=0&&d<4;){if(a.next_in[c]==mark[d])d++;else d=a.next_in[c]!=0?0:4-d;c++;b--}a.total_in+=c-a.next_in_index;a.next_in_index=c;a.avail_in=b;a.istate.marker=d;if(d!=4)return Z_DATA_ERROR;b=a.total_in;c=a.total_out;this.inflateReset(a);a.total_in=b;a.total_out=c;a.istate.mode=
  BLOCKS;return Z_OK};Inflate.prototype.inflateSyncPoint=function(a){if(a==null||a.istate==null||a.istate.blocks==null)return Z_STREAM_ERROR;return a.istate.blocks.sync_point()};var INFBLOCKS_BORDER=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
  function InfBlocks(a,b,c){this.hufts=new Int32Array(MANY*3);this.window=new Uint8Array(c);this.end=c;this.checkfn=b;this.mode=IB_TYPE;this.reset(a,null);this.index=this.table=this.left=0;this.blens=null;this.bb=new Int32Array(1);this.tb=new Int32Array(1);this.codes=new InfCodes;this.check=this.write=this.read=this.bitb=this.bitk=this.last=0;this.inftree=new InfTree}
  InfBlocks.prototype.reset=function(a,b){if(b)b[0]=this.check;this.mode==IB_CODES&&this.codes.free(a);this.mode=IB_TYPE;this.read=this.write=this.bitb=this.bitk=0;if(this.checkfn)a.adler=this.check=a._adler.adler32(0,null,0,0)};
  InfBlocks.prototype.proc=function(a,b){var c,d,e,h,j,i,l;h=a.next_in_index;j=a.avail_in;d=this.bitb;e=this.bitk;i=this.write;for(l=i<this.read?this.read-i-1:this.end-i;;)switch(this.mode){case IB_TYPE:for(;e<3;){if(j!=0)b=Z_OK;else{this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}j--;d|=(a.next_in[h++]&255)<<e;e+=8}c=d&7;this.last=c&1;switch(c>>>1){case 0:d>>>=3;e-=3;c=e&7;d>>>=c;e-=c;this.mode=IB_LENS;break;case 1:var m=
  new Int32Array(1),o=new Int32Array(1),r=[],p=[];inflate_trees_fixed(m,o,r,p,a);this.codes.init(m[0],o[0],r[0],0,p[0],0,a);d>>>=3;e-=3;this.mode=IB_CODES;break;case 2:d>>>=3;e-=3;this.mode=IB_TABLE;break;case 3:d>>>=3;e-=3;this.mode=BAD;a.msg="invalid block type";b=Z_DATA_ERROR;this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}break;case IB_LENS:for(;e<32;){if(j!=0)b=Z_OK;else{this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=
  h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}j--;d|=(a.next_in[h++]&255)<<e;e+=8}if((~d>>>16&65535)!=(d&65535)){this.mode=BAD;a.msg="invalid stored block lengths";b=Z_DATA_ERROR;this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}this.left=d&65535;d=e=0;this.mode=left!=0?IB_STORED:this.last!=0?IB_DRY:IB_TYPE;break;case IB_STORED:if(j==0){this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=
  h-a.next_in_index;a.next_in_index=h;write=i;return this.inflate_flush(a,b)}if(l==0){if(i==end&&read!=0){i=0;l=i<this.read?this.read-i-1:this.end-i}if(l==0){this.write=i;b=this.inflate_flush(a,b);i=this.write;l=i<this.read?this.read-i-1:this.end-i;if(i==this.end&&this.read!=0){i=0;l=i<this.read?this.read-i-1:this.end-i}if(l==0){this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}}}b=Z_OK;c=this.left;if(c>j)c=j;if(c>l)c=l;
  arrayCopy(a.next_in,h,window,i,c);h+=c;j-=c;i+=c;l-=c;if((this.left-=c)!=0)break;this.mode=this.last!=0?IB_DRY:IB_TYPE;break;case IB_TABLE:for(;e<14;){if(j!=0)b=Z_OK;else{this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}j--;d|=(a.next_in[h++]&255)<<e;e+=8}this.table=c=d&16383;if((c&31)>29||(c>>5&31)>29){this.mode=IB_BAD;a.msg="too many length or distance symbols";b=Z_DATA_ERROR;this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=
  h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}c=258+(c&31)+(c>>5&31);if(this.blens==null||this.blens.length<c)this.blens=new Int32Array(c);else for(l=0;l<c;l++)this.blens[l]=0;d>>>=14;e-=14;this.index=0;mode=IB_BTREE;case IB_BTREE:for(;this.index<4+(this.table>>>10);){for(;e<3;){if(j!=0)b=Z_OK;else{this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}j--;d|=(a.next_in[h++]&255)<<e;e+=8}this.blens[INFBLOCKS_BORDER[this.index++]]=
  d&7;d>>>=3;e-=3}for(;this.index<19;)this.blens[INFBLOCKS_BORDER[this.index++]]=0;this.bb[0]=7;c=this.inftree.inflate_trees_bits(this.blens,this.bb,this.tb,this.hufts,a);if(c!=Z_OK){b=c;if(b==Z_DATA_ERROR){this.blens=null;this.mode=IB_BAD}this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;write=i;return this.inflate_flush(a,b)}this.index=0;this.mode=IB_DTREE;case IB_DTREE:for(;;){c=this.table;if(!(this.index<258+(c&31)+(c>>5&31)))break;for(c=this.bb[0];e<c;){if(j!=
  0)b=Z_OK;else{this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}j--;d|=(a.next_in[h++]&255)<<e;e+=8}c=this.hufts[(this.tb[0]+(d&inflate_mask[c]))*3+1];o=this.hufts[(this.tb[0]+(d&inflate_mask[c]))*3+2];if(o<16){d>>>=c;e-=c;this.blens[this.index++]=o}else{l=o==18?7:o-14;for(m=o==18?11:3;e<c+l;){if(j!=0)b=Z_OK;else{this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,
  b)}j--;d|=(a.next_in[h++]&255)<<e;e+=8}d>>>=c;e-=c;m+=d&inflate_mask[l];d>>>=l;e-=l;l=this.index;c=this.table;if(l+m>258+(c&31)+(c>>5&31)||o==16&&l<1){this.blens=null;this.mode=IB_BAD;a.msg="invalid bit length repeat";b=Z_DATA_ERROR;this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}o=o==16?this.blens[l-1]:0;do this.blens[l++]=o;while(--m!=0);this.index=l}}this.tb[0]=-1;m=new Int32Array(1);o=new Int32Array(1);r=new Int32Array(1);
  p=new Int32Array(1);m[0]=9;o[0]=6;c=this.table;c=this.inftree.inflate_trees_dynamic(257+(c&31),1+(c>>5&31),this.blens,m,o,r,p,this.hufts,a);if(c!=Z_OK){if(c==Z_DATA_ERROR){this.blens=null;this.mode=BAD}b=c;this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}this.codes.init(m[0],o[0],this.hufts,r[0],this.hufts,p[0],a);this.mode=IB_CODES;case IB_CODES:this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=
  h;this.write=i;if((b=this.codes.proc(this,a,b))!=Z_STREAM_END)return this.inflate_flush(a,b);b=Z_OK;this.codes.free(a);h=a.next_in_index;j=a.avail_in;d=this.bitb;e=this.bitk;i=this.write;l=i<this.read?this.read-i-1:this.end-i;if(this.last==0){this.mode=IB_TYPE;break}this.mode=IB_DRY;case IB_DRY:this.write=i;b=this.inflate_flush(a,b);i=this.write;if(this.read!=this.write){this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}mode=
  DONE;case IB_DONE:b=Z_STREAM_END;this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b);case IB_BAD:b=Z_DATA_ERROR;this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b);default:b=Z_STREAM_ERROR;this.bitb=d;this.bitk=e;a.avail_in=j;a.total_in+=h-a.next_in_index;a.next_in_index=h;this.write=i;return this.inflate_flush(a,b)}};
  InfBlocks.prototype.free=function(a){this.reset(a,null);this.hufts=this.window=null};InfBlocks.prototype.set_dictionary=function(a,b,c){arrayCopy(a,b,window,0,c);this.read=this.write=c};InfBlocks.prototype.sync_point=function(){return this.mode==IB_LENS};
  InfBlocks.prototype.inflate_flush=function(a,b){var c,d,e;d=a.next_out_index;e=this.read;c=(e<=this.write?this.write:this.end)-e;if(c>a.avail_out)c=a.avail_out;if(c!=0&&b==Z_BUF_ERROR)b=Z_OK;a.avail_out-=c;a.total_out+=c;if(this.checkfn!=null)a.adler=this.check=a._adler.adler32(this.check,this.window,e,c);arrayCopy(this.window,e,a.next_out,d,c);d+=c;e+=c;if(e==this.end){e=0;if(this.write==this.end)this.write=0;c=this.write-e;if(c>a.avail_out)c=a.avail_out;if(c!=0&&b==Z_BUF_ERROR)b=Z_OK;a.avail_out-=
  c;a.total_out+=c;if(this.checkfn!=null)a.adler=this.check=a._adler.adler32(this.check,this.window,e,c);arrayCopy(this.window,e,a.next_out,d,c);d+=c;e+=c}a.next_out_index=d;this.read=e;return b};var IC_START=0,IC_LEN=1,IC_LENEXT=2,IC_DIST=3,IC_DISTEXT=4,IC_COPY=5,IC_LIT=6,IC_WASH=7,IC_END=8,IC_BADCODE=9;function InfCodes(){}InfCodes.prototype.init=function(a,b,c,d,e,h){this.mode=IC_START;this.lbits=a;this.dbits=b;this.ltree=c;this.ltree_index=d;this.dtree=e;this.dtree_index=h;this.tree=null};
  InfCodes.prototype.proc=function(a,b,c){var d,e,h=0,j=0,i=0,l,m,o;i=b.next_in_index;l=b.avail_in;h=a.bitb;j=a.bitk;m=a.write;for(o=m<a.read?a.read-m-1:a.end-m;;)switch(this.mode){case IC_START:if(o>=258&&l>=10){a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;c=this.inflate_fast(this.lbits,this.dbits,this.ltree,this.ltree_index,this.dtree,this.dtree_index,a,b);i=b.next_in_index;l=b.avail_in;h=a.bitb;j=a.bitk;m=a.write;o=m<a.read?a.read-m-1:a.end-m;if(c!=Z_OK){this.mode=
  c==Z_STREAM_END?IC_WASH:IC_BADCODE;break}}this.need=this.lbits;this.tree=this.ltree;this.tree_index=this.ltree_index;this.mode=IC_LEN;case IC_LEN:for(d=this.need;j<d;){if(l!=0)c=Z_OK;else{a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c)}l--;h|=(b.next_in[i++]&255)<<j;j+=8}d=(this.tree_index+(h&inflate_mask[d]))*3;h>>>=this.tree[d+1];j-=this.tree[d+1];e=this.tree[d];if(e==0){this.lit=this.tree[d+2];this.mode=IC_LIT;break}if((e&16)!=
  0){this.get=e&15;this.len=this.tree[d+2];this.mode=IC_LENEXT;break}if((e&64)==0){this.need=e;this.tree_index=d/3+this.tree[d+2];break}if((e&32)!=0){this.mode=IC_WASH;break}this.mode=IC_BADCODE;b.msg="invalid literal/length code";c=Z_DATA_ERROR;a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c);case IC_LENEXT:for(d=this.get;j<d;){if(l!=0)c=Z_OK;else{a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=
  m;return a.inflate_flush(b,c)}l--;h|=(b.next_in[i++]&255)<<j;j+=8}this.len+=h&inflate_mask[d];h>>=d;j-=d;this.need=this.dbits;this.tree=this.dtree;this.tree_index=this.dtree_index;this.mode=IC_DIST;case IC_DIST:for(d=this.need;j<d;){if(l!=0)c=Z_OK;else{a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c)}l--;h|=(b.next_in[i++]&255)<<j;j+=8}d=(this.tree_index+(h&inflate_mask[d]))*3;h>>=this.tree[d+1];j-=this.tree[d+1];e=this.tree[d];if((e&
  16)!=0){this.get=e&15;this.dist=this.tree[d+2];this.mode=IC_DISTEXT;break}if((e&64)==0){this.need=e;this.tree_index=d/3+this.tree[d+2];break}this.mode=IC_BADCODE;b.msg="invalid distance code";c=Z_DATA_ERROR;a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c);case IC_DISTEXT:for(d=this.get;j<d;){if(l!=0)c=Z_OK;else{a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c)}l--;
  h|=(b.next_in[i++]&255)<<j;j+=8}this.dist+=h&inflate_mask[d];h>>=d;j-=d;this.mode=IC_COPY;case IC_COPY:for(d=m-this.dist;d<0;)d+=a.end;for(;this.len!=0;){if(o==0){if(m==a.end&&a.read!=0){m=0;o=m<a.read?a.read-m-1:a.end-m}if(o==0){a.write=m;c=a.inflate_flush(b,c);m=a.write;o=m<a.read?a.read-m-1:a.end-m;if(m==a.end&&a.read!=0){m=0;o=m<a.read?a.read-m-1:a.end-m}if(o==0){a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c)}}}a.window[m++]=
  a.window[d++];o--;if(d==a.end)d=0;this.len--}this.mode=IC_START;break;case IC_LIT:if(o==0){if(m==a.end&&a.read!=0){m=0;o=m<a.read?a.read-m-1:a.end-m}if(o==0){a.write=m;c=a.inflate_flush(b,c);m=a.write;o=m<a.read?a.read-m-1:a.end-m;if(m==a.end&&a.read!=0){m=0;o=m<a.read?a.read-m-1:a.end-m}if(o==0){a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c)}}}c=Z_OK;a.window[m++]=this.lit;o--;this.mode=IC_START;break;case IC_WASH:if(j>7){j-=8;
  l++;i--}a.write=m;c=a.inflate_flush(b,c);m=a.write;if(a.read!=a.write){a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c)}this.mode=IC_END;case IC_END:c=Z_STREAM_END;a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c);case IC_BADCODE:c=Z_DATA_ERROR;a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c);default:c=
  Z_STREAM_ERROR;a.bitb=h;a.bitk=j;b.avail_in=l;b.total_in+=i-b.next_in_index;b.next_in_index=i;a.write=m;return a.inflate_flush(b,c)}};InfCodes.prototype.free=function(){};
  InfCodes.prototype.inflate_fast=function(a,b,c,d,e,h,j,i){var l,m,o,r,p,t,q,s,u,v,w,z;t=i.next_in_index;q=i.avail_in;r=j.bitb;p=j.bitk;s=j.write;u=s<j.read?j.read-s-1:j.end-s;a=inflate_mask[a];v=inflate_mask[b];do{for(;p<20;){q--;r|=(i.next_in[t++]&255)<<p;p+=8}l=r&a;m=c;o=d;z=(o+l)*3;if((b=m[z])==0){r>>=m[z+1];p-=m[z+1];j.window[s++]=m[z+2];u--}else{do{r>>=m[z+1];p-=m[z+1];if((b&16)!=0){b&=15;w=m[z+2]+(r&inflate_mask[b]);r>>=b;for(p-=b;p<15;){q--;r|=(i.next_in[t++]&255)<<p;p+=8}l=r&v;m=e;o=h;z=(o+
  l)*3;b=m[z];do{r>>=m[z+1];p-=m[z+1];if((b&16)!=0){for(b&=15;p<b;){q--;r|=(i.next_in[t++]&255)<<p;p+=8}l=m[z+2]+(r&inflate_mask[b]);r>>=b;p-=b;u-=w;if(s>=l){l=s-l;j.window[s++]=j.window[l++];j.window[s++]=j.window[l++];w-=2}else{l=s-l;do l+=j.end;while(l<0);b=j.end-l;if(w>b){w-=b;if(s-l>0&&b>s-l){do j.window[s++]=j.window[l++];while(--b!=0)}else{arrayCopy(j.window,l,j.window,s,b);s+=b}l=0}}do j.window[s++]=j.window[l++];while(--w!=0);break}else if((b&64)==0){l+=m[z+2];l+=r&inflate_mask[b];z=(o+l)*
  3;b=m[z]}else{i.msg="invalid distance code";w=i.avail_in-q;w=p>>3<w?p>>3:w;q+=w;t-=w;p-=w<<3;j.bitb=r;j.bitk=p;i.avail_in=q;i.total_in+=t-i.next_in_index;i.next_in_index=t;j.write=s;return Z_DATA_ERROR}}while(1);break}if((b&64)==0){l+=m[z+2];l+=r&inflate_mask[b];z=(o+l)*3;if((b=m[z])==0){r>>=m[z+1];p-=m[z+1];j.window[s++]=m[z+2];u--;break}}else if((b&32)!=0){w=i.avail_in-q;w=p>>3<w?p>>3:w;q+=w;t-=w;p-=w<<3;j.bitb=r;j.bitk=p;i.avail_in=q;i.total_in+=t-i.next_in_index;i.next_in_index=t;j.write=s;return Z_STREAM_END}else{i.msg=
  "invalid literal/length code";w=i.avail_in-q;w=p>>3<w?p>>3:w;q+=w;t-=w;p-=w<<3;j.bitb=r;j.bitk=p;i.avail_in=q;i.total_in+=t-i.next_in_index;i.next_in_index=t;j.write=s;return Z_DATA_ERROR}}while(1)}}while(u>=258&&q>=10);w=i.avail_in-q;w=p>>3<w?p>>3:w;q+=w;t-=w;p-=w<<3;j.bitb=r;j.bitk=p;i.avail_in=q;i.total_in+=t-i.next_in_index;i.next_in_index=t;j.write=s;return Z_OK};function InfTree(){}
  InfTree.prototype.huft_build=function(a,b,c,d,e,h,j,i,l,m,o){var r,p,t,q,s,u,v,w,z;u=0;p=c;do{this.c[a[b+u]]++;u++;p--}while(p!=0);if(this.c[0]==c){j[0]=-1;i[0]=0;return Z_OK}s=i[0];for(t=1;t<=BMAX;t++)if(this.c[t]!=0)break;q=t;if(s<t)s=t;for(p=BMAX;p!=0;p--)if(this.c[p]!=0)break;m=p;if(s>p)s=p;i[0]=s;for(i=1<<t;t<p;t++,i<<=1)if((i-=this.c[t])<0)return Z_DATA_ERROR;if((i-=this.c[p])<0)return Z_DATA_ERROR;this.c[p]+=i;this.x[1]=t=0;u=1;for(v=2;--p!=0;){this.x[v]=t+=this.c[u];v++;u++}u=p=0;do{if((t=
  a[b+u])!=0)this.v[this.x[t]++]=p;u++}while(++p<c);c=this.x[m];u=this.x[0]=p=0;b=-1;w=-s;for(z=v=this.u[0]=0;q<=m;q++)for(a=this.c[q];a--!=0;){for(;q>w+s;){b++;w+=s;z=m-w;z=z>s?s:z;if((r=1<<(t=q-w))>a+1){r-=a+1;v=q;if(t<z)for(;++t<z;){if((r<<=1)<=this.c[++v])break;r-=this.c[v]}}z=1<<t;if(this.hn[0]+z>MANY)return Z_DATA_ERROR;this.u[b]=v=this.hn[0];this.hn[0]+=z;if(b!=0){this.x[b]=p;this.r[0]=t;this.r[1]=s;t=p>>>w-s;this.r[2]=v-this.u[b-1]-t;arrayCopy(this.r,0,l,(this.u[b-1]+t)*3,3)}else j[0]=v}this.r[1]=
  q-w;if(u>=c)this.r[0]=192;else if(o[u]<d){this.r[0]=this.v[u]<256?0:96;this.r[2]=this.v[u++]}else{this.r[0]=h[this.v[u]-d]+16+64;this.r[2]=e[this.v[u++]-d]}r=1<<q-w;for(t=p>>>w;t<z;t+=r)arrayCopy(this.r,0,l,(v+t)*3,3);for(t=1<<q-1;(p&t)!=0;t>>>=1)p^=t;p^=t;for(t=(1<<w)-1;(p&t)!=this.x[b];){b--;w-=s;t=(1<<w)-1}}return i!=0&&m!=1?Z_BUF_ERROR:Z_OK};
  InfTree.prototype.inflate_trees_bits=function(a,b,c,d,e){this.initWorkArea(19);this.hn[0]=0;a=this.huft_build(a,0,19,19,null,null,c,b,d,this.hn,this.v);if(a==Z_DATA_ERROR)e.msg="oversubscribed dynamic bit lengths tree";else if(a==Z_BUF_ERROR||b[0]==0){e.msg="incomplete dynamic bit lengths tree";a=Z_DATA_ERROR}return a};
  InfTree.prototype.inflate_trees_dynamic=function(a,b,c,d,e,h,j,i,l){this.initWorkArea(288);this.hn[0]=0;h=this.huft_build(c,0,a,257,cplens,cplext,h,d,i,this.hn,this.v);if(h!=Z_OK||d[0]==0){if(h==Z_DATA_ERROR)l.msg="oversubscribed literal/length tree";else if(h!=Z_MEM_ERROR){l.msg="incomplete literal/length tree";h=Z_DATA_ERROR}return h}this.initWorkArea(288);h=this.huft_build(c,a,b,0,cpdist,cpdext,j,e,i,this.hn,this.v);if(h!=Z_OK||e[0]==0&&a>257){if(h==Z_DATA_ERROR)l.msg="oversubscribed distance tree";
  else if(h==Z_BUF_ERROR){l.msg="incomplete distance tree";h=Z_DATA_ERROR}else if(h!=Z_MEM_ERROR){l.msg="empty distance tree with lengths";h=Z_DATA_ERROR}return h}return Z_OK};function inflate_trees_fixed(a,b,c,d){a[0]=fixed_bl;b[0]=fixed_bd;c[0]=fixed_tl;d[0]=fixed_td;return Z_OK}
  InfTree.prototype.initWorkArea=function(a){if(this.hn==null){this.hn=new Int32Array(1);this.v=new Int32Array(a);this.c=new Int32Array(BMAX+1);this.r=new Int32Array(3);this.u=new Int32Array(BMAX);this.x=new Int32Array(BMAX+1)}if(this.v.length<a)this.v=new Int32Array(a);for(var b=0;b<a;b++)this.v[b]=0;for(b=0;b<BMAX+1;b++)this.c[b]=0;for(b=0;b<3;b++)this.r[b]=0;arrayCopy(this.c,0,this.u,0,BMAX);arrayCopy(this.c,0,this.x,0,BMAX+1)};
  var testArray=new Uint8Array(1),hasSubarray=typeof testArray.subarray==="function",hasSlice=false;function arrayCopy(a,b,c,d,e){if(e!=0){if(a){if(!c)throw"Undef dest";}else throw"Undef src";if(b==0&&e==a.length)arrayCopy_fast(a,c,d);else if(hasSubarray)arrayCopy_fast(a.subarray(b,b+e),c,d);else a.BYTES_PER_ELEMENT==1&&e>100?arrayCopy_fast(new Uint8Array(a.buffer,a.byteOffset+b,e),c,d):arrayCopy_slow(a,b,c,d,e)}}function arrayCopy_slow(a,b,c,d,e){for(var h=0;h<e;++h)c[d+h]=a[b+h]}
  function arrayCopy_fast(a,b,c){b.set(a,c)}var ADLER_BASE=65521,ADLER_NMAX=5552;
  function adler32(a,b,c,d){if(b==null)return 1;var e=a&65535;a=a>>16&65535;for(var h;d>0;){h=d<ADLER_NMAX?d:ADLER_NMAX;for(d-=h;h>=16;){e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;e+=b[c++]&255;a+=e;h-=16}if(h!=0){do{e+=b[c++]&255;a+=e}while(--h!=0)}e%=ADLER_BASE;
  a%=ADLER_BASE}return a<<16|e}
  function jszlib_inflate_buffer(a,b,c,d){a=b?new Uint8Array(a,b,c):new Uint8Array(a);c=new ZStream;c.inflateInit(DEF_WBITS,true);c.next_in=a;c.next_in_index=0;c.avail_in=a.length;a=[];for(var e=0;;){var h=new Uint8Array(32E3);c.next_out=h;c.next_out_index=0;c.avail_out=h.length;var j=c.inflate(Z_NO_FLUSH);if(j!=Z_OK&&j!=Z_STREAM_END)throw c.msg;if(c.avail_out!=0){var i=new Uint8Array(h.length-c.avail_out);arrayCopy(h,0,i,0,h.length-c.avail_out);h=i}a.push(h);e+=h.length;if(j==Z_STREAM_END)break}if(d)d[0]=
  (b||0)+c.next_in_index;if(a.length==1)return a[0].buffer;else{b=new Uint8Array(e);for(c=d=0;c<a.length;++c){e=a[c];arrayCopy(e,0,b,d,e.length);d+=e.length}return b.buffer}}
  (function(){function a(){p.call(document.querySelectorAll("input[type=range]"),c);(new MutationObserver(function(q){q.forEach(function(s){s.addedNodes&&p.call(s.addedNodes,function(u){b(u);u.childElementCount&&p.call(u.querySelectorAll("input"),b)})})})).observe(document,{childList:true,subtree:true})}function b(q){q.localName=="input"&&q.type!="range"&&q.getAttribute("type")=="range"&&c(q)}function c(q){function s(O){var W=(parseFloat(getComputedStyle(this,0).width)-l.width)/F;if(W){E+=(O.clientX-
  P)/W;P=O.clientX;A=true;this.value=E}}function u(){this.removeEventListener("mousemove",s,true);this.removeEventListener("mouseup",u,true)}function v(){if(!B)this.style.boxShadow=!i?"0 0 0 2px #fb0":"inset 0 0 20px rgba(0,127,255,.1), 0 0 1px rgba(0,127,255,.4)"}function w(O){return!isNaN(O)&&+O==parseFloat(O)}function z(){R=w(q.min)?+q.min:0;J=w(q.max)?+q.max:100;if(J<R)J=R>100?R:100;S=w(q.step)&&q.step>0?+q.step:1;F=J-R;x(true)}function x(O){if(!D&&!C)L=q.getAttribute("value");w(L)||(L=(R+J)/2);
  L=Math.round((L-R)/S)*S+R;if(L<R)L=R;else if(L>J)L=R+~~(F/S)*S;A&&L!=G&&q.dispatchEvent(t);A=false;if(!(!O&&L==G)){G=L;d(q,{background:"-moz-element(#__sliderthumb__) "+(F?(L-R)/F*100:0)+"% no-repeat, "+m})}}var D,C,A,B,G,E,P,R,J,S,F,L=q.value;if(!j){j=document.body.appendChild(document.createElement("hr"));d(j,{"-moz-appearance":i?"scale-horizontal":"scalethumb-horizontal",display:"block",visibility:"visible",opacity:1,position:"fixed",top:"-999999px"});document.mozSetImageElement("__sliderthumb__",
  j)}var fa=function(){return""+L};q.__defineGetter__("value",fa);q.__defineSetter__("value",function O(W){L=""+W;D=true;x();delete q.value;q.value=L;q.__defineGetter__("value",fa);q.__defineSetter__("value",O)});q.__defineGetter__("type",function(){return"range"});["min","max","step"].forEach(function(O){if(q.hasAttribute(O))C=true;q.__defineGetter__(O,function(){return this.hasAttribute(O)?this.getAttribute(O):""});q.__defineSetter__(O,function(W){W===null?this.removeAttribute(O):this.setAttribute(O,
  W)})});q.readOnly=true;d(q,o);z();(new MutationObserver(function(O){O.forEach(function(W){if(W.attributeName!="value"){z();C=true}else if(!D){L=q.getAttribute("value");x()}})})).observe(q,r);q.addEventListener("mousedown",function(O){B=true;setTimeout(function(){B=false},0);if(!(O.button||!F)){var W=(parseFloat(getComputedStyle(this,0).width)-l.width)/F;if(W){var ja=O.clientX-this.getBoundingClientRect().left-l.width/2-(L-R)*W;if(Math.abs(ja)>l.radius){A=true;this.value-=-ja/W}E=L;P=O.clientX;this.addEventListener("mousemove",
  s,true);this.addEventListener("mouseup",u,true)}}},true);q.addEventListener("keydown",function(O){if(O.keyCode>36&&O.keyCode<41){v.call(this);A=true;this.value=L+(O.keyCode==38||O.keyCode==39?S:-S)}},true);q.addEventListener("focus",v,true);q.addEventListener("blur",function(){this.style.boxShadow=""},true)}function d(q,s){for(var u in s)q.style.setProperty(u,s[u],"important")}var e=document.createElement("input");try{e.type="range";if(e.type=="range")return}catch(h){return}e.style.background="linear-gradient(red, red)";
  if(!(!e.style.backgroundImage||!("MozAppearance"in e.style)||!document.mozSetImageElement||!this.MutationObserver)){var j,i=navigator.platform=="MacIntel",l={radius:i?9:6,width:i?22:12,height:i?16:20},m="linear-gradient(transparent "+(i?"6px, #999 6px, #999 7px, #ccc 8px, #bbb 9px, #bbb 10px, transparent 10px":"9px, #999 9px, #bbb 10px, #fff 11px, transparent 11px")+", transparent)",o={"min-width":l.width+"px","min-height":l.height+"px","max-height":l.height+"px",padding:"0 0 "+(i?"2px":"1px"),border:0,
  "border-radius":0,cursor:"default","text-indent":"-999999px"},r={attributes:true,attributeFilter:["min","max","step","value"]},p=Array.prototype.forEach,t=document.createEvent("HTMLEvents");t.initEvent("change",true,false);document.readyState=="loading"?document.addEventListener("DOMContentLoaded",a,true):a()}})();
  