/*
 *  Copyright © 2008 Fair Oaks Labs, Inc.
 *  All rights reserved.
 */
var Struct=new function(){this._DeArray=function(B,C,A){return B.slice(C,C+A)};this._EnArray=function(B,E,A,C){for(var D=0;D<A;D++){B[E+D]=C[D]}};this._DeByte=function(A,B){return A[B]};this._DeByteSigned=function(A,C){var B=A[C];if(B&128){B-=256}return B};this._EnByte=function(A,C,B){A[C]=B&255};this._DeShort=function(A,B){return A[B]+A[B+1]*256};this._DeShortSigned=function(A,C){var B=A[C]+A[C+1]*256;if(B&32768){B-=65536}return B};this._EnShort=function(A,C,B){A[C]=B&255;A[C+1]=(B>>8)&255};this._DeLong=function(A,B){return A[B]+A[B+1]*256+A[B+2]*65536+A[B+3]*16777216};this._DeLongSigned=function(A,C){var B=A[C]+A[C+1]*256+A[C+2]*65536+A[C+3]*16777216;if(B&2147483648){B-=4294967296}return B};this._EnLong=function(A,C,B){A[C]=B&255;A[C+1]=(B>>8)&255;A[C+2]=(B>>16)&255;A[C+3]=(B>>24)&255};this._DeString=function(B,D,A){var E=new Array(A),C;for(C=0;C<A;C++){E[C]=String.fromCharCode(B[D+C])}return E.join("")};this._EnString=function(B,E,A,C){for(var D=0;D<A;D++){B[E+D]=C.charCodeAt(D)}};this._DeFloat=function(B,E){var A,D,C;A=B[E]+B[E+1]*256+(B[E+2]&127)*65536;D=(B[E+2]>>7)+(B[E+3]&127)*2;C=(B[E+3]&128)?-1:1;switch(D){case 0:D=-126;break;case 255:return A?NaN:C*Infinity;default:A=A+(1<<23);D=D-127;break}return C*Math.pow(2,D-23)*A};this._EnFloat=function(B,F,C){var D,E,A;D=C<0?1:0;C=Math.abs(C);if(isNaN(C)||(C==Infinity)){A=isNaN(C)?1:0;E=255}else{E=Math.floor(Math.log(C)/Math.LN2);if(E>=-126){A=C*Math.pow(2,23-E)-(1<<23);E=E+127}else{A=C*Math.pow(2,23+126);E=0}}B[F]=A&255;B[F+1]=(A/256)&255;B[F+2]=(E&1)*128+((A/65536)&127);B[F+3]=(D)*128+((E/2)&127)};this._DeDouble=function(B,F){var C,A,E,D;for(C=0,A=0;C<6;C++){A+=B[F+C]*Math.pow(2,C*8)}A=A+(B[F+6]&15)*Math.pow(2,48);E=(B[F+6]>>4)+(B[F+7]&127)*16;D=(B[F+7]&128)?-1:1;switch(E){case 0:E=-1022;break;case 2047:return A?NaN:D*Infinity;default:A=A+Math.pow(2,52);E=E-1023;break}return D*A*Math.pow(2,-52)*Math.pow(2,E)};this._EnDouble=function(B,G,C){var E,F,A,D;E=C<0?1:0;C=Math.abs(C);if(isNaN(C)||(C==Infinity)){A=isNaN(C)?1:0;F=2047}else{F=Math.floor(Math.log(C)/Math.LN2);if(C*Math.pow(2,-F)<1){F--}if(F>=-1022){A=C*Math.pow(2,-F)*Math.pow(2,52)-Math.pow(2,52);F=F+1023}else{A=C*Math.pow(2,1022)*Math.pow(2,52);F=0}}for(D=0;D<7;D++,A/=256){B[G+D]=A&255}B[G+6]=B[G+6]+(F&15)*16;B[G+7]=(E)*128+((F/16)&127)};this._sPattern="(\\d+)?([AbBhHsfdiIlL])";this._lenLut={A:1,b:1,B:1,h:2,H:2,s:1,f:4,d:8,i:4,I:4,l:4,L:4};this._UnpackSeries=function(D,G,C,A,E){var F=[],B;for(B=0;B<G;B++){F.push(D(A,E+B*C))}return F};this._PackSeries=function(E,H,D,A,F,B,C){for(var G=0;G<H;G++){E(A,F+G*D,B[C+G])}};this.Unpack=function(C,B,F){var E=new RegExp(this._sPattern,"g"),A,H,D,G=[];while(A=E.exec(C)){H=((A[1]==undefined)||(A[1]==""))?1:parseInt(A[1]);D=this._lenLut[A[2]];if((F+H*D)>B.length){return undefined}switch(A[2]){case"A":G.push([this._DeArray(B,F,H)]);break;case"b":G.push(this._UnpackSeries(this._DeByteSigned,H,D,B,F));break;case"B":G.push(this._UnpackSeries(this._DeByte,H,D,B,F));break;case"h":G.push(this._UnpackSeries(this._DeShortSigned,H,D,B,F));break;case"H":G.push(this._UnpackSeries(this._DeShort,H,D,B,F));break;case"i":case"l":G.push(this._UnpackSeries(this._DeLongSigned,H,D,B,F));break;case"I":case"L":G.push(this._UnpackSeries(this._DeLong,H,D,B,F));break;case"s":G.push(this._DeString(B,F,H));break;case"f":G.push(this._UnpackSeries(this._DeFloat,H,D,B,F));break;case"d":G.push(this._UnpackSeries(this._DeDouble,H,D,B,F));break}F+=H*D}return Array.prototype.concat.apply([],G)};this.Pack=function(C,F,A,G){var H=new RegExp(this._sPattern,"g"),D,B,I,E=0;while(D=H.exec(C)){B=((D[1]==undefined)||(D[1]==""))?1:parseInt(D[1]);I=this._lenLut[D[2]];if((A+B*I)>F.length){return false}switch(D[2]){case"A":if((E+1)>G.length){return false}this._EnArray(F,A,B,G[E]);E+=1;break;case"b":case"B":if((E+B)>G.length){return false}this._PackSeries(this._EnByte,B,I,F,A,G,E);E+=B;break;case"h":case"H":if((E+B)>G.length){return false}this._PackSeries(this._EnShort,B,I,F,A,G,E);E+=B;break;case"i":case"I":case"l":case"L":if((E+B)>G.length){return false}this._PackSeries(this._EnLong,B,I,F,A,G,E);E+=B;break;case"s":if((E+1)>G.length){return false}this._EnString(F,A,B,G[E]);E+=1;break;case"f":if((E+B)>G.length){return false}this._PackSeries(this._EnFloat,B,I,F,A,G,E);E+=B;break;case"d":if((E+B)>G.length){return false}this._PackSeries(this._EnDouble,B,I,F,A,G,E);E+=B;break}A+=B*I}return true};this.CalcLength=function(B){var D=new RegExp(this._sPattern,"g"),A,C=0;while(A=D.exec(B)){C+=(((A[1]==undefined)||(A[1]==""))?1:parseInt(A[1]))*this._lenLut[A[2]]}return C}}();