/* This notice must be untouched at all times.

wz_jsgraphics.js    v. 2.33
The latest version is available at
http://www.walterzorn.com
or http://www.devira.com
or http://www.walterzorn.de

Copyright (c) 2002-2004 Walter Zorn. All rights reserved.
Created 3. 11. 2002 by Walter Zorn (Web: http://www.walterzorn.com )
Last modified: 24. 10. 2005

Performance optimizations for Internet Explorer
by Thomas Frank and John Holdsworth.
fillPolygon method implemented by Matthieu Haller.

High Performance JavaScript Graphics Library.
Provides methods
- to draw lines, rectangles, ellipses, polygons
	with specifiable line thickness,
- to fill rectangles and ellipses
- to draw text.
NOTE: Operations, functions and branching have rather been optimized
to efficiency and speed than to shortness of source code.

LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
or see http://www.gnu.org/copyleft/lesser.html
http://www.c-point.com/javascript_vector_draw.htm
*/
var jg_ihtm,jg_ie,jg_fast,jg_dom,jg_moz,jg_n4=(document.layers&&typeof document.classes!="undefined");function chkDHTM(A,B){A=document.body||null;jg_ie=A&&typeof A.insertAdjacentHTML!="undefined";jg_dom=(A&&!jg_ie&&typeof A.appendChild!="undefined"&&typeof document.createRange!="undefined"&&typeof (B=document.createRange()).setStartBefore!="undefined"&&typeof B.createContextualFragment!="undefined");jg_ihtm=!jg_ie&&!jg_dom&&A&&typeof A.innerHTML!="undefined";jg_fast=jg_ie&&document.all&&!window.opera;jg_moz=jg_dom&&typeof A.style.MozOpacity!="undefined"}function pntDoc(){this.wnd.document.write(jg_fast?this.htmRpc():this.htm);this.htm=""}function pntCnvDom(){var A=document.createRange();A.setStartBefore(this.cnv);A=A.createContextualFragment(jg_fast?this.htmRpc():this.htm);this.cnv.appendChild(A);this.htm=""}function pntCnvIe(){this.cnv.insertAdjacentHTML("BeforeEnd",jg_fast?this.htmRpc():this.htm);this.htm=""}function pntCnvIhtm(){this.cnv.innerHTML+=this.htm;this.htm=""}function pntCnv(){this.htm=""}function mkDiv(A,D,B,C){this.htm+='<div style="position:absolute;left:'+A+"px;top:"+D+"px;width:"+B+"px;height:"+C+"px;clip:rect(0,"+B+"px,"+C+"px,0);background-color:"+this.color+(!jg_moz?";overflow:hidden":"")+';"></div>'}function mkDivIe(A,D,B,C){this.htm+="%%"+this.color+";"+A+";"+D+";"+B+";"+C+";"}function mkDivPrt(A,D,B,C){this.htm+='<div style="position:absolute;border-left:'+B+"px solid "+this.color+";left:"+A+"px;top:"+D+"px;width:0px;height:"+C+"px;clip:rect(0,"+B+"px,"+C+"px,0);background-color:"+this.color+(!jg_moz?";overflow:hidden":"")+';"></div>'}function mkLyr(A,D,B,C){this.htm+='<layer left="'+A+'" top="'+D+'" width="'+B+'" height="'+C+'" bgcolor="'+this.color+'"></layer>\n'}var regex=/%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g;function htmRpc(){return this.htm.replace(regex,'<div style="overflow:hidden;position:absolute;background-color:$1;left:$2;top:$3;width:$4;height:$5"></div>\n')}function htmPrtRpc(){return this.htm.replace(regex,'<div style="overflow:hidden;position:absolute;background-color:$1;left:$2;top:$3;width:$4;height:$5;border-left:$4px solid $1"></div>\n')}function mkLin(E,M,B,K){if(E>B){var J=B;var G=K;B=E;K=M;E=J;M=G}var P=B-E,O=Math.abs(K-M),L=E,I=M,N=(M>K)?-1:1;if(P>=O){var A=O<<1,H=A-(P<<1),D=A-P,F=L;while((P--)>0){++L;if(D>0){this.mkDiv(F,I,L-F,1);I+=N;D+=H;F=L}else{D+=A}}this.mkDiv(F,I,B-F+1,1)}else{var A=P<<1,H=A-(O<<1),D=A-O,C=I;if(K<=M){while((O--)>0){if(D>0){this.mkDiv(L++,I,1,C-I+1);I+=N;D+=H;C=I}else{I+=N;D+=A}}this.mkDiv(B,K,1,C-K+1)}else{while((O--)>0){I+=N;if(D>0){this.mkDiv(L++,C,1,I-C);D+=H;C=I}else{D+=A}}this.mkDiv(B,C,1,K-C+1)}}}function mkLin2D(Q,B,P,A){if(Q>P){var F=P;var N=A;P=Q;A=B;Q=F;B=N}var J=P-Q,I=Math.abs(A-B),H=Q,G=B,M=(B>A)?-1:1;var K=this.stroke;if(J>=I){if(J>0&&K-3>0){var R=(K*J*Math.sqrt(1+I*I/(J*J))-J-(K>>1)*I)/J;R=(!(K-4)?Math.ceil(R):Math.round(R))+1}else{var R=K}var S=Math.ceil(K/2);var O=I<<1,E=O-(J<<1),L=O-J,D=H;while((J--)>0){++H;if(L>0){this.mkDiv(D,G,H-D+S,R);G+=M;L+=E;D=H}else{L+=O}}this.mkDiv(D,G,P-D+S+1,R)}else{if(K-3>0){var R=(K*I*Math.sqrt(1+J*J/(I*I))-(K>>1)*J-I)/I;R=(!(K-4)?Math.ceil(R):Math.round(R))+1}else{var R=K}var S=Math.round(K/2);var O=J<<1,E=O-(I<<1),L=O-I,C=G;if(A<=B){++S;while((I--)>0){if(L>0){this.mkDiv(H++,G,R,C-G+S);G+=M;L+=E;C=G}else{G+=M;L+=O}}this.mkDiv(P,A,R,C-A+S)}else{while((I--)>0){G+=M;if(L>0){this.mkDiv(H++,C,R,G-C+S);L+=E;C=G}else{L+=O}}this.mkDiv(P,C,R,A-C+S+1)}}}function mkLinDott(D,K,B,I){if(D>B){var H=B;var E=I;B=D;I=K;D=H;K=E}var O=B-D,N=Math.abs(I-K),J=D,G=K,M=(K>I)?-1:1,L=true;if(O>=N){var A=N<<1,F=A-(O<<1),C=A-O;while((O--)>0){if(L){this.mkDiv(J,G,1,1)}L=!L;if(C>0){G+=M;C+=F}else{C+=A}++J}if(L){this.mkDiv(J,G,1,1)}}else{var A=O<<1,F=A-(N<<1),C=A-N;while((N--)>0){if(L){this.mkDiv(J,G,1,1)}L=!L;G+=M;if(C>0){++J;C+=F}else{C+=A}}if(L){this.mkDiv(J,G,1,1)}}}function mkOv(E,M,O,N){var S=O>>1,R=N>>1,L=O&1,D=(N&1)+1,C=E+S,B=M+R,J=0,I=R,G=0,F=R,T=(S*S)<<1,H=(R*R)<<1,P=(T>>1)*(1-(R<<1))+H,A=(H>>1)-T*((R<<1)-1),K,Q;while(I>0){if(P<0){P+=H*((J<<1)+3);A+=(H<<1)*(++J)}else{if(A<0){P+=H*((J<<1)+3)-(T<<1)*(I-1);A+=(H<<1)*(++J)-T*(((I--)<<1)-3);K=J-G;Q=F-I;if(K&2&&Q&2){this.mkOvQds(C,B,-J+2,G+L,-F,F-1+D,1,1);this.mkOvQds(C,B,-J+1,J-1+L,-I-1,I+D,1,1)}else{this.mkOvQds(C,B,-J+1,G+L,-F,F-Q+D,K,Q)}G=J;F=I}else{A-=T*((I<<1)-3);P-=(T<<1)*(--I)}}}this.mkDiv(C-S,B-F,S-G+1,(F<<1)+D);this.mkDiv(C+G+L,B-F,S-G+1,(F<<1)+D)}function mkOv2D(C,D,A,B){var X=this.stroke;A+=X-1;B+=X-1;var n=A>>1,k=B>>1,j=A&1,Q=(B&1)+1,J=C+n,I=D+k,V=0,S=k,G=(n*n)<<1,q=(k*k)<<1,E=(G>>1)*(1-(k<<1))+q,g=(q>>1)-G*((k<<1)-1);if(X-4<0&&(!(X-2)||A-51>0&&B-51>0)){var M=0,L=k,W,e,U,P,O,Z,N;while(S>0){if(E<0){E+=q*((V<<1)+3);g+=(q<<1)*(++V)}else{if(g<0){E+=q*((V<<1)+3)-(G<<1)*(S-1);g+=(q<<1)*(++V)-G*(((S--)<<1)-3);W=V-M;e=L-S;if(W-1){N=W+1+(X&1);e=X}else{if(e-1){N=X;e+=1+(X&1)}else{N=e=X}}this.mkOvQds(J,I,-V+1,M-N+W+j,-L,-e+L+Q,N,e);M=V;L=S}else{g-=G*((S<<1)-3);E-=(G<<1)*(--S)}}}this.mkDiv(J-n,I-L,X,(L<<1)+Q);this.mkDiv(J+n+j-X+1,I-L,X,(L<<1)+Q)}else{var o=(A-((X-1)<<1))>>1,m=(B-((X-1)<<1))>>1,T=0,R=m,H=(o*o)<<1,p=(m*m)<<1,F=(H>>1)*(1-(m<<1))+p,f=(p>>1)-H*((m<<1)-1),U=new Array(),O=new Array(),Y=new Array();U[0]=0;O[0]=k;Y[0]=m-1;while(S>0){if(E<0){E+=q*((V<<1)+3);g+=(q<<1)*(++V);U[U.length]=V;O[O.length]=S}else{if(g<0){E+=q*((V<<1)+3)-(G<<1)*(S-1);g+=(q<<1)*(++V)-G*(((S--)<<1)-3);U[U.length]=V;O[O.length]=S}else{g-=G*((S<<1)-3);E-=(G<<1)*(--S)}}if(R>0){if(F<0){F+=p*((T<<1)+3);f+=(p<<1)*(++T);Y[Y.length]=R-1}else{if(f<0){F+=p*((T<<1)+3)-(H<<1)*(R-1);f+=(p<<1)*(++T)-H*(((R--)<<1)-3);Y[Y.length]=R-1}else{f-=H*((R<<1)-3);F-=(H<<1)*(--R);Y[Y.length-1]--}}}}var M=0,L=k,K=Y[0],c=U.length,W,e;for(var d=0;d<c;d++){if(typeof Y[d]!="undefined"){if(Y[d]<K||O[d]<L){V=U[d];this.mkOvQds(J,I,-V+1,M+j,-L,K+Q,V-M,L-K);M=V;L=O[d];K=Y[d]}}else{V=U[d];this.mkDiv(J-V+1,I-L,1,(L<<1)+Q);this.mkDiv(J+M+j,I-L,1,(L<<1)+Q);M=V;L=O[d]}}this.mkDiv(J-n,I-L,1,(L<<1)+Q);this.mkDiv(J+M+j,I-L,1,(L<<1)+Q)}}function mkOvDott(E,J,O,M){var R=O>>1,Q=M>>1,I=O&1,D=M&1,C=E+R,B=J+Q,H=0,G=Q,N=(R*R)<<1,K=N<<1,F=(Q*Q)<<1,P=(N>>1)*(1-(Q<<1))+F,A=(F>>1)-N*((Q<<1)-1),L=true;while(G>0){if(P<0){P+=F*((H<<1)+3);A+=(F<<1)*(++H)}else{if(A<0){P+=F*((H<<1)+3)-K*(G-1);A+=(F<<1)*(++H)-N*(((G--)<<1)-3)}else{A-=N*((G<<1)-3);P-=K*(--G)}}if(L){this.mkOvQds(C,B,-H,H+I,-G,G+D,1,1)}L=!L}}function mkRect(A,E,B,D){var C=this.stroke;this.mkDiv(A,E,B,C);this.mkDiv(A+B,E,C,D);this.mkDiv(A,E+D,B+C,C);this.mkDiv(A,E+C,C,D-C)}function mkRectDott(A,D,B,C){this.drawLine(A,D,A+B,D);this.drawLine(A+B,D,A+B,D+C);this.drawLine(A,D+C,A+B,D+C);this.drawLine(A,D,A,D+C)}function jsgFont(){this.PLAIN="font-weight:normal;";this.BOLD="font-weight:bold;";this.ITALIC="font-style:italic;";this.ITALIC_BOLD=this.ITALIC+this.BOLD;this.BOLD_ITALIC=this.ITALIC_BOLD}var Font=new jsgFont();function jsgStroke(){this.DOTTED=-1}var Stroke=new jsgStroke();function jsGraphics(B,A){this.setColor=new Function("arg","this.color = arg.toLowerCase();");this.setStroke=function(C){this.stroke=C;if(!(C+1)){this.drawLine=mkLinDott;this.mkOv=mkOvDott;this.drawRect=mkRectDott}else{if(C-1>0){this.drawLine=mkLin2D;this.mkOv=mkOv2D;this.drawRect=mkRect}else{this.drawLine=mkLin;this.mkOv=mkOv;this.drawRect=mkRect}}};this.setPrintable=function(C){this.printable=C;if(jg_fast){this.mkDiv=mkDivIe;this.htmRpc=C?htmPrtRpc:htmRpc}else{this.mkDiv=jg_n4?mkLyr:C?mkDivPrt:mkDiv}};this.setFont=function(D,E,C){this.ftFam=D;this.ftSz=E;this.ftSty=C||Font.PLAIN};this.drawPolyline=this.drawPolyLine=function(C,F,E){for(var D=0;D<C.length-1;D++){this.drawLine(C[D],F[D],C[D+1],F[D+1])}};this.fillRect=function(C,F,D,E){this.mkDiv(C,F,D,E)};this.drawPolygon=function(C,D){this.drawPolyline(C,D);this.drawLine(C[C.length-1],D[C.length-1],C[0],D[0])};this.drawEllipse=this.drawOval=function(C,F,D,E){this.mkOv(C,F,D,E)};this.fillEllipse=this.fillOval=function(G,Q,M,U){var X=(M-=1)>>1,W=(U-=1)>>1,N=(M&1)+1,F=(U&1)+1,E=G+X,D=Q+W,L=0,K=W,I=0,H=W,S=(X*X)<<1,R=S<<1,J=(W*W)<<1,T=(S>>1)*(1-(W<<1))+J,C=(J>>1)-S*((W<<1)-1),P,O,V;if(M+1){while(K>0){if(T<0){T+=J*((L<<1)+3);C+=(J<<1)*(++L)}else{if(C<0){T+=J*((L<<1)+3)-R*(K-1);P=E-L;O=(L<<1)+N;C+=(J<<1)*(++L)-S*(((K--)<<1)-3);V=H-K;this.mkDiv(P,D-H,O,V);this.mkDiv(P,D+K+F,O,V);I=L;H=K}else{C-=S*((K<<1)-3);T-=R*(--K)}}}}this.mkDiv(E-X,D-H,M+1,(H<<1)+F)};this.fillPolygon=function(I,H){var J;var O;var Q,M;var D,P;var C,N;var L,K;var E;var F=I.length;if(!F){return }Q=H[0];M=H[0];for(J=1;J<F;J++){if(H[J]<Q){Q=H[J]}if(H[J]>M){M=H[J]}}for(O=Q;O<=M;O++){var G=new Array();E=0;for(J=0;J<F;J++){if(!J){L=F-1;K=0}else{L=J-1;K=J}P=H[L];N=H[K];if(P<N){D=I[L];C=I[K]}else{if(P>N){N=H[L];P=H[K];C=I[L];D=I[K]}else{continue}}if((O>=P)&&(O<N)){G[E++]=Math.round((O-P)*(C-D)/(N-P)+D)}else{if((O==M)&&(O>P)&&(O<=N)){G[E++]=Math.round((O-P)*(C-D)/(N-P)+D)}}}G.sort(integer_compare);for(J=0;J<E;J+=2){this.mkDiv(G[J],O,G[J+1]-G[J]+1,1)}}};this.drawString=function(D,C,E){this.htm+='<div style="position:absolute;white-space:nowrap;left:'+C+"px;top:"+E+"px;font-family:"+this.ftFam+";font-size:"+this.ftSz+";color:"+this.color+";"+this.ftSty+'">'+D+"</div>"};this.drawStringRect=function(D,C,G,E,F){this.htm+='<div style="position:absolute;overflow:hidden;left:'+C+"px;top:"+G+"px;width:"+E+"px;text-align:"+F+";font-family:"+this.ftFam+";font-size:"+this.ftSz+";color:"+this.color+";"+this.ftSty+'">'+D+"</div>"};this.drawImage=function(G,C,H,E,F,D){this.htm+='<div style="position:absolute;left:'+C+"px;top:"+H+"px;width:"+E+";height:"+F+';"><img src="'+G+'" width="'+E+'" height="'+F+'"'+(D?(" "+D):"")+"></div>"};this.clear=function(){this.htm="";if(this.cnv){this.cnv.innerHTML=this.defhtm}};this.mkOvQds=function(D,J,I,G,F,C,E,H){this.mkDiv(G+D,F+J,E,H);this.mkDiv(G+D,C+J,E,H);this.mkDiv(I+D,C+J,E,H);this.mkDiv(I+D,F+J,E,H)};this.setStroke(1);this.setFont("verdana,geneva,helvetica,sans-serif",String.fromCharCode(49,50,112,120),Font.PLAIN);this.color="#000000";this.htm="";this.wnd=A||window;if(!(jg_ie||jg_dom||jg_ihtm)){chkDHTM()}if(typeof B!="string"||!B){this.paint=pntDoc}else{this.cnv=document.all?(this.wnd.document.all[B]||null):document.getElementById?(this.wnd.document.getElementById(B)||null):null;this.defhtm=(this.cnv&&this.cnv.innerHTML)?this.cnv.innerHTML:"";this.paint=jg_dom?pntCnvDom:jg_ie?pntCnvIe:jg_ihtm?pntCnvIhtm:pntCnv}this.setPrintable(false)}function integer_compare(A,B){return(A<B)?-1:((A>B)*1)};

