var Base=function(){if(arguments.length){if(this==window){Base.prototype.extend.call(arguments[0],arguments.callee.prototype)}else{this.extend(arguments[0])}}};Base.version="1.0.2";Base.prototype={extend:function(B,H){var G=Base.prototype.extend;if(arguments.length==2){var F=this[B];if((F instanceof Function)&&(H instanceof Function)&&F.valueOf()!=H.valueOf()&&/\bbase\b/.test(H)){var A=H;H=function(){var K=this.base;this.base=F;var J=A.apply(this,arguments);this.base=K;return J};H.valueOf=function(){return A};H.toString=function(){return String(A)}}return this[B]=H}else{if(B){var I={toSource:null};var D=["toString","valueOf"];if(Base._prototyping){D[2]="constructor"}for(var E=0;(C=D[E]);E++){if(B[C]!=I[C]){G.call(this,C,B[C])}}for(var C in B){if(!I[C]){G.call(this,C,B[C])}}}}return this},base:function(){}};Base.extend=function(B,F){var G=Base.prototype.extend;if(!B){B={}}Base._prototyping=true;var E=new this;G.call(E,B);var D=E.constructor;E.constructor=this;delete Base._prototyping;var A=function(){if(!Base._prototyping){D.apply(this,arguments)}this.constructor=A};A.prototype=E;A.extend=this.extend;A.implement=this.implement;A.toString=function(){return String(D)};G.call(A,F);var C=D?A:E;if(C.init instanceof Function){C.init()}return C};Base.implement=function(A){if(A instanceof Function){A=A.prototype}this.prototype.extend(A)};var aColor=Base.extend({constructor:function(){this.warn()},toHex:function(){this.warn()},toRGB:function(){this.warn()},toXYZ:function(){this.warn()},toCIELab:function(){this.warn()},toCIELCh:function(){this.warn()},toCMY:function(){this.warn()},toCMYK:function(){this.warn()},toHSV:function(){this.warn()},distance:function(B){var C=this.toCIELab();var A=B.toCIELab();return Math.sqrt(Math.pow((C.l-A.l),2)+Math.pow((C.a-A.a),2)+Math.pow((C.b-A.b),2))},websafe:function(){var B=new Array("00","CC","33","66","99","FF");var A=[];for(i=0;i<6;i++){for(j=0;j<6;j++){for(k=0;k<6;k++){A.push(new Hex(B[i]+B[j]+B[k]))}}}return this.match(A)},match:function(A){var E=null;var C=null;for(var B=0;B<A.length;B++){var D=this.distance(A[B]);if(E==null||D<E){E=D;C=A[B]}}return C[this.toSelf]()},equal:function(E,A){if(A==null){A=false}if(E<2){E=2}var D=this.toCIELCh();var F=360/E;var B=[];if(A){B.push(this)}for(var C=1;C<E;C++){B.push(new CIELCh(D.l,D.c,D.h+(F*C))[this.toSelf]())}return B},split:function(A){if(A==null){A=false}var C=this.toCIELCh();var D=150;var B=[new CIELCh(C.l,C.c,C.h+D)[this.toSelf](),new CIELCh(C.l,C.c,C.h-D)[this.toSelf]()];if(A){B.unshift(this)}return B},analogous:function(A){if(A==null){A=false}var C=this.toCIELCh();var D=30;var B=[new CIELCh(C.l,C.c,C.h+D)[this.toSelf](),new CIELCh(C.l,C.c,C.h-D)[this.toSelf]()];if(A){B.unshift(this)}return B},rectangle:function(B,A){if(A==null){A=false}var E=B;var C=(360-(B*2))/2;var F=this.toCIELCh();var D=[new CIELCh(F.l,F.c,F.h+E)[this.toSelf](),new CIELCh(F.l,F.c,F.h+E+C)[this.toSelf](),new CIELCh(F.l,F.c,F.h+E+C+E)[this.toSelf]()];if(A){D.unshift(this)}return D},range:function(E,F,B){if(B==null){B=false}var I=this.toRGB();var G=E.toRGB();var A=[];F--;for(n=1;n<F;n++){var H=Math.floor(I.r+(n*(G.r-I.r)/F));var C=Math.floor(I.g+(n*(G.g-I.g)/F));var D=Math.floor(I.b+(n*(G.b-I.b)/F));A.push(new RGB(H,C,D)[this.toSelf]())}if(B){A.unshift(this);A.push(E[this.toSelf]())}return A},greyscale:function(){var A=this.toRGB();var B=(Math.max(A.r,A.g,A.b)+Math.min(A.r,A.g,A.b))/2;return new RGB(B,B,B)[this.toSelf]()},hue:function(B){var A=this.toCIELCh();A.h+=B;return A[this.toSelf]()},saturation:function(A){var B=this.toHSV();B.s+=(A/100);B.s=Math.min(1,Math.max(0,B.s));return B[this.toSelf]()},brightness:function(B){var A=this.toHSV();A.v+=(B/100);A.v=Math.min(1,Math.max(0,A.v));return A[this.toSelf]()},warn:function(){alert("aColor should not be created directly. Treat this as an abstract class.")}});var Hex=aColor.extend({constructor:function(A){this.hex=A;if(this.hex.substring(0,1)=="#"){this.hex=this.hex.substring(1,7)}},toHex:function(){return this},toRGB:function(){var C=parseInt(this.hex.substring(0,2),16);var B=parseInt(this.hex.substring(2,4),16);var A=parseInt(this.hex.substring(4,6),16);return new RGB(C,B,A)},toXYZ:function(){return this.toRGB().toXYZ()},toCIELab:function(){return this.toXYZ().toCIELab()},toHSV:function(){return this.toRGB().toHSV()},toCMY:function(){return this.toRGB().toCMY()},toCMYK:function(){return this.toCMY().toCMYK()},toString:function(){return this.hex.toUpperCase()},toCIELCh:function(){return this.toCIELab().toCIELCh()},toSelf:"toHex"});var RGB=aColor.extend({constructor:function(C,B,A){this.r=Math.min(255,Math.max(C,0));this.g=Math.min(255,Math.max(B,0));this.b=Math.min(255,Math.max(A,0))},toHex:function(){var B=[this.r,this.g,this.b];var C="";for(i=0;i<B.length;i++){var A="0123456789ABCDEF";C+=A.charAt(Math.floor(B[i]/16))+A.charAt(B[i]-(Math.floor(B[i]/16)*16))}return new Hex(C)},toRGB:function(){return this},toXYZ:function(){var D=this.r/255;var C=this.g/255;var B=this.b/255;if(D>0.04045){D=Math.pow(((D+0.055)/1.055),2.4)}else{D=D/12.92}if(C>0.04045){C=Math.pow(((C+0.055)/1.055),2.4)}else{C=C/12.92}if(B>0.04045){B=Math.pow(((B+0.055)/1.055),2.4)}else{B=B/12.92}D=D*100;C=C*100;B=B*100;var A=D*0.4124+C*0.3576+B*0.1805;var F=D*0.2126+C*0.7152+B*0.0722;var E=D*0.0193+C*0.1192+B*0.9505;return new XYZ(A,F,E)},toCIELab:function(){return this.toXYZ().toCIELab()},toHSV:function(){var G=(this.r/255);var A=(this.g/255);var D=(this.b/255);var I=Math.min(G,A,D);var M=Math.max(G,A,D);var J=M-I;var B=M;if(J==0){var L=0;var E=0}else{var E=J/M;var K=(((M-G)/6)+(J/2))/J;var C=(((M-A)/6)+(J/2))/J;var F=(((M-D)/6)+(J/2))/J;if(G==M){L=F-C}else{if(A==M){L=(1/3)+K-F}else{if(D==M){L=(2/3)+C-K}}}if(L<0){L+=1}if(L>1){L-=1}}return new HSV(L,E,B)},toCMY:function(){var B=1-(this.r/255);var D=1-(this.g/255);var A=1-(this.b/255);return new CMY(B,D,A)},toCMYK:function(){return this.toCMY().toCMYK()},toString:function(){return this.r+","+this.g+","+this.b},toCIELCh:function(){return this.toCIELab().toCIELCh()},toSelf:"toRGB"});var XYZ=aColor.extend({constructor:function(A,C,B){this.x=A;this.y=C;this.z=B},toHex:function(){return this.toRGB().toHex()},toRGB:function(){var F=this.x/100;var E=this.y/100;var C=this.z/100;var H=F*3.2406+E*-1.5372+C*-0.4986;var B=F*-0.9689+E*1.8758+C*0.0415;var D=F*0.0557+E*-0.204+C*1.057;if(H>0.0031308){H=1.055*Math.pow(H,(1/2.4))-0.055}else{H=12.92*H}if(B>0.0031308){B=1.055*Math.pow(B,(1/2.4))-0.055}else{B=12.92*B}if(D>0.0031308){D=1.055*Math.pow(D,(1/2.4))-0.055}else{D=12.92*D}var A=Math.round(H*255);var G=Math.round(B*255);var I=Math.round(D*255);return new RGB(A,G,I)},toXYZ:function(){return this},toCIELab:function(){var C=95.047;var A=100;var I=108.883;var H=this.x/C;var F=this.y/A;var D=this.z/I;if(H>0.008856){H=Math.pow(H,1/3)}else{H=(7.787*H)+(16/116)}if(F>0.008856){F=Math.pow(F,1/3)}else{F=(7.787*F)+(16/116)}if(D>0.008856){D=Math.pow(D,1/3)}else{D=(7.787*D)+(16/116)}if(F>0.008856){var B=(116*F)-16}else{var B=903.3*F}var G=500*(H-F);var E=200*(F-D);return new CIELab(B,G,E)},toHSV:function(){return this.toRGB().toHSV()},toCMY:function(){return this.toRGB().toCMY()},toCMYK:function(){return this.toCMY().toCMYK()},toCIELCh:function(){return this.toCIELab().toCIELCh()},toString:function(){return this.x+","+this.y+","+this.z},toSelf:"toXYZ"});var CIELab=aColor.extend({constructor:function(C,B,A){this.l=C;this.a=B;this.b=A},toHex:function(){return this.toRGB().toHex()},toRGB:function(){return this.toXYZ().toRGB()},toXYZ:function(){var F=95.047;var E=100;var C=108.883;var B=(this.l+16)/116;var D=this.a/500+B;var A=B-this.b/200;if(Math.pow(B,3)>0.008856){B=Math.pow(B,3)}else{B=(B-16/116)/7.787}if(Math.pow(D,3)>0.008856){D=Math.pow(D,3)}else{D=(D-16/116)/7.787}if(Math.pow(A,3)>0.008856){A=Math.pow(A,3)}else{A=(A-16/116)/7.787}x=F*D;y=E*B;z=C*A;return new XYZ(x,y,z)},toCIELab:function(){return this},toHSV:function(){return this.toRGB().toHSV()},toCMY:function(){return this.toRGB().toCMY()},toCMYK:function(){return this.toCMY().toCMYK()},toCIELCh:function(){var B=Math.atan2(this.b,this.a);if(B>0){B=(B/Math.PI)*180}else{B=360-(Math.abs(B)/Math.PI)*180}var A=this.l;var D=Math.sqrt(Math.pow(this.a,2)+Math.pow(this.b,2));var C=B;return new CIELCh(A,D,C)},toString:function(){return this.l+","+this.a+","+this.b},toSelf:"toCIELab"});var HSV=aColor.extend({constructor:function(C,B,A){this.h=C;this.s=B;this.v=A},toHex:function(){return this.toRGB().toHex()},toRGB:function(){if(this.s==0){var C=this.v*255;var A=this.v*255;var D=this.v*255}else{var_h=this.h*6;if(var_h==6){var_h=0}var_i=Math.floor(var_h);var_1=this.v*(1-this.s);var_2=this.v*(1-this.s*(var_h-var_i));var_3=this.v*(1-this.s*(1-(var_h-var_i)));if(var_i==0){var_r=this.v;var_g=var_3;var_b=var_1}else{if(var_i==1){var_r=var_2;var_g=this.v;var_b=var_1}else{if(var_i==2){var_r=var_1;var_g=this.v;var_b=var_3}else{if(var_i==3){var_r=var_1;var_g=var_2;var_b=this.v}else{if(var_i==4){var_r=var_3;var_g=var_1;var_b=this.v}else{var_r=this.v;var_g=var_1;var_b=var_2}}}}}var C=var_r*255;var A=var_g*255;var D=var_b*255}return new RGB(C,A,D)},toXYZ:function(){return this.toRGB().toXYZ()},toCIELab:function(){return this.toRGB().toCIELab()},toHSV:function(){return this},toCMY:function(){return this.toRGB().toCMY()},toCMYK:function(){return this.toCMY().toCMYK()},toCIELCh:function(){return this.toCIELab().toCIELCh()},toString:function(){return this.h+","+this.s+","+this.v},toSelf:"toHSV"});var CMY=aColor.extend({constructor:function(C,A,B){this.c=C;this.m=A;this.y=B},toHex:function(){return this.toRGB().toHex()},toRGB:function(){var C=(1-this.c)*255;var A=(1-this.m)*255;var D=(1-this.y)*255;return new RGB(C,A,D)},toXYZ:function(){return this.toRGB().toXYZ()},toCIELab:function(){return this.toRGB().toCIELab()},toCMY:function(){return this},toCMYK:function(){var E=1;if(this.c<E){E=this.c}if(this.m<E){E=this.m}if(this.y<E){E=this.y}if(E==1){var D=0;var F=0;var B=0}else{var D=(this.c-E)/(1-E);var F=(this.m-E)/(1-E);var B=(this.y-E)/(1-E)}var A=E;return new CMYK(D,F,B,A)},toCIELCh:function(){return this.toCIELab().toCIELCh()},toString:function(){return this.c+","+this.m+","+this.y},toSelf:"toCMY"});var CMYK=aColor.extend({constructor:function(D,A,C,B){this.c=D;this.m=A;this.y=C;this.k=B},toHex:function(){return this.toRGB().toHex()},toRGB:function(){return this.toCMY().toRGB()},toXYZ:function(){return this.toRGB().toXYZ()},toCIELab:function(){return this.toRGB().toCIELab()},toCMY:function(){var B=(this.c*(1-this.k)+this.k);var D=(this.m*(1-this.k)+this.k);var A=(this.y*(1-this.k)+this.k);return new CMY(B,D,A)},toCMYK:function(){return this},toCIELCh:function(){return this.toCIELab().toCIELCh()},toString:function(){return this.c+","+this.m+","+this.y+","+this.k},toSelf:"toCMYK"});var CIELCh=aColor.extend({constructor:function(A,C,B){this.l=A;this.c=C;this.h=B<360?B:(B-360)},toHex:function(){return this.toCIELab().toHex()},toRGB:function(){return this.toCIELab().toRGB()},toXYZ:function(){return this.toCIELab().toXYZ()},toCIELab:function(){var C=this.l;var D=this.h*(Math.PI/180);var B=Math.cos(D)*this.c;var A=Math.sin(D)*this.c;return new CIELab(C,B,A)},toHSV:function(){return this.toCIELab().toHSV()},toCMY:function(){return this.toCIELab().toCMY()},toCMYK:function(){return this.toCIELab().toCMYK()},toString:function(){return this.l+","+this.c+","+this.h},toCIELCh:function(){return this},toSelf:"toHex"});
