/**
 * Copyright (C) 2010-2011 Graham Breach
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * TagCanvas 1.7.1
 * For more information, please contact <graham@goat1000.com>
 */
(function(){var y,w,k={},m={},n={"0":"0,","1":"17,","2":"34,","3":"51,","4":"68,","5":"85,","6":"102,","7":"119,","8":"136,","9":"153,",a:"170,",A:"170,",b:"187,",B:"187,",c:"204,",C:"204,",d:"221,",D:"221,",e:"238,",E:"238,",f:"255,",F:"255,"};for(y=0;y<256;++y){w=y.toString(16);if(y<16){w="0"+w}m[w]=m[w.toUpperCase()]=y.toString()+","}function B(J){var j,I,E,D,H=[],F=Math.PI*(3-Math.sqrt(5)),G=2/J;for(j=0;j<J;++j){I=j*G-1+(G/2);E=Math.sqrt(1-I*I);D=j*F;H.push([Math.cos(D)*E,I,Math.sin(D)*E])}return H}function t(G,i){var F=G,E,D,j=new Number(i).toPrecision(3)+")";if(G[0]==="#"){if(!k[G]){if(G.length===4){k[G]="rgba("+n[G[1]]+n[G[2]]+n[G[3]]}else{k[G]="rgba("+m[G.substr(1,2)]+m[G.substr(3,2)]+m[G.substr(5,2)]}}F=k[G]+j}else{if(G.substr(0,4)==="rgb("||G.substr(0,4)==="hsl("){F=(G.replace("(","a(").replace(")",","+j))}else{if(G.substr(0,5)==="rgba("||G.substr(0,5)==="hsla("){E=G.lastIndexOf(",")+1,D=G.indexOf(")");i*=parseFloat(G.substring(E,D));F=G.substr(0,E)+i.toPrecision(3)+")"}else{F=G}}}return F}function l(i,j){if(window.G_vmlCanvasManager){return null}var D=document.createElement("canvas");D.width=i;D.height=j;return D}function g(){var j=l(3,3),E,D;if(!j){return false}E=j.getContext("2d");E.strokeStyle="#000";E.shadowColor="#fff";E.shadowBlur="3";E.globalAlpha=0;E.strokeRect(2,2,2,2);E.globalAlpha=1;D=E.getImageData(2,2,1,1);j=null;return(D.data[0]>0)}function p(K,j){var D=1024,G=K.weightGradient,F,I,E,J,H;if(K.gCanvas){I=K.gCanvas.getContext("2d")}else{K.gCanvas=F=l(D,1);if(!F){return null}I=F.getContext("2d");J=I.createLinearGradient(0,0,D,0);for(E in G){J.addColorStop(1-E,G[E])}I.fillStyle=J;I.fillRect(0,0,D,1)}H=I.getImageData(~~((D-1)*j),0,1,1).data;return"rgba("+H[0]+","+H[1]+","+H[2]+","+(H[3]/255)+")"}function b(P,H,N){var O=parseInt(P.length*N),G=parseInt(N*2),E=l(O,G),K,j,F,J,M,L,D,I;if(!E){return null}K=E.getContext("2d");K.fillStyle="#000";K.fillRect(0,0,O,G);K.font=H;K.textHeight=N;K.textBaseline="top";K.fillStyle="#fff";K.font=N+"px "+H;K.fillText(P,0,0);j=K.getImageData(0,0,O,G);F=j.width;J=j.height;I={min:{x:F,y:J},max:{x:-1,y:-1}};for(L=0;L<J;++L){for(M=0;M<F;++M){D=(L*F+M)*4;if(j.data[D+1]>0){if(M<I.min.x){I.min.x=M}if(M>I.max.x){I.max.x=M}if(L<I.min.y){I.min.y=L}if(L>I.max.y){I.max.y=L}}}}if(F!=O){I.min.x*=(O/F);I.max.x*=(O/F)}if(J!=G){I.min.y*=(O/J);I.max.y*=(O/J)}E=null;return I}function u(i){return"'"+i.replace(/(\'|\")/g,"").replace(/\s*,\s*/g,"', '")+"'"}function x(i,j,D){if(!D){D=document}if(D.addEventListener){D.addEventListener(i,j,false)}else{D.attachEvent("on"+i,j)}}function s(E,D,j){if(E.complete){D.w=E.width;D.h=E.height;j.push(D)}else{x("load",function(){D.w=this.width;D.h=this.height;j.push(D)},E)}}function r(D,j){var i=1,E;if(D.weightFrom){i=1*(j.getAttribute(D.weightFrom)||D.textHeight)}else{if(document.defaultView&&document.defaultView.getComputedStyle){E=document.defaultView.getComputedStyle(j,null).getPropertyValue("font-size");i=E.replace("px","")*1}else{D.weight=false}}return i}function f(F){var E,D,j=document.documentElement;for(E in z.tc){D=z.tc[E];if(F.pageX){D.mx=F.pageX-D.cx;D.my=F.pageY-D.cy}else{D.mx=F.clientX+(j.scrollLeft||document.body.scrollLeft)-D.cx;D.my=F.clientY+(j.scrollTop||document.body.scrollTop)-D.cy}}}function a(E){var j=z,i=document.addEventListener?0:1,D=E.target&&E.target.id!=undefined?E.target.id:E.srcElement.parentNode.id;if(D&&E.button==i&&j.tc[D]){f(E);j.tc[D].Clicked(E)}}function q(){var D=z.tc,j;for(j in D){D[j].Draw()}}function C(i,j){this.x=i;this.y=j}function o(E){var D,j,i;D=document.getElementById(E);j=new C(D.offsetLeft,D.offsetTop);while(D.offsetParent){i=D.offsetParent;j.x+=i.offsetLeft;j.y+=i.offsetTop;D=i}return j}function d(i,D,j){this.x=i;this.y=D;this.z=j}function e(D,i){var j=Math.sin(i),E=Math.cos(i);return new d(D.x,(D.y*E)+(D.z*j),(D.y*-j)+(D.z*E))}function c(D,i){var j=Math.sin(i),E=Math.cos(i);return new d((D.x*E)+(D.z*-j),D.y,(D.x*j)+(D.z*E))}function v(E,K,J,H,F,j){var i,G,I,D=E.z1/(E.z1+E.z2+K.z);i=K.y*D;G=K.x*D;I=E.z2+K.z;return new d(G,i,I)}function A(i){this.ts=new Date().valueOf();this.tc=i;this.x=this.y=this.w=this.h=this.sc=1}A.prototype.Update=function(i,G,j,D,F){var E=this.tc.outlineOffset;this.x=F*(i-E);this.y=F*(G-E);this.w=F*(j+E*2);this.h=F*(D+E*2);this.sc=F};A.prototype.Draw=function(D){var j=new Date().valueOf()-this.ts,i=this.tc;D.setTransform(1,0,0,1,0,0);D.strokeStyle=i.outlineColour;D.lineWidth=i.outlineThickness;D.shadowBlur=D.shadowOffsetX=D.shadowOffsetY=0;if(i.pulsateTo<1){D.globalAlpha=i.pulsateTo+((1-i.pulsateTo)*(0.5+(Math.cos(2*Math.PI*j/(1000*i.pulsateTime))/2)))}else{D.globalAlpha=1}D.strokeRect(this.x,this.y,this.w,this.h)};A.prototype.Active=function(D,i,j){return(i>=this.x&&j>=this.y&&i<=this.x+this.w&&j<=this.y+this.h)};function h(i,F,D,E,j,G){var H=i.ctxt;this.tc=i;this.image=F.src?F:null;this.name=F.src?"":F;this.a=D;this.p3d=new d(0,0,0);this.p3d.x=E[0]*i.radius*1.1;this.p3d.y=E[1]*i.radius*1.1;this.p3d.z=E[2]*i.radius*1.1;this.x=this.y=0;this.w=j;this.h=G;this.colour=i.textColour;this.weight=this.sc=this.alpha=1;this.weighted=!i.weight;this.outline=new A(i);if(!this.image){this.textHeight=i.textHeight;this.extents=b(this.name,i.textFont,this.textHeight);this.Measure(H,i)}this.SetShadowColour=i.shadowAlpha?this.SetShadowColourAlpha:this.SetShadowColourFixed;this.Draw=this.image?this.DrawImage:this.DrawText}h.prototype.Measure=function(j,i){this.h=this.extents?this.extents.max.y+this.extents.min.y:this.textHeight;j.font=this.font=this.textHeight+"px "+i.textFont;this.w1=j.measureText(this.name).width};h.prototype.SetWeight=function(i){this.weight=i;this.Weight(this.tc.ctxt,this.tc);this.Measure(this.tc.ctxt,this.tc)};h.prototype.Weight=function(E,D){var j=this.weight,i=D.weightMode;this.weighted=true;if(i==="colour"||i==="both"){this.colour=p(D,(j-D.min_weight)/(D.max_weight-D.min_weight))}if(i==="size"||i==="both"){this.textHeight=j*D.weightSize}this.extents=b(this.name,D.textFont,this.textHeight)};h.prototype.SetShadowColourFixed=function(D,j,i){D.shadowColor=j};h.prototype.SetShadowColourAlpha=function(D,j,i){D.shadowColor=t(j,i)};h.prototype.DrawText=function(E,I,D){var J=this.tc,G=this.x,F=this.y,H,j,K=this.sc,i=this.outline;E.globalAlpha=this.alpha;E.setTransform(K,0,0,K,0,0);E.fillStyle=this.colour;this.SetShadowColour(E,J.shadow,this.alpha);E.font=this.font;H=this.w1*K;j=this.h*K;G+=1+(I/K)-(H/2);F+=1+(D/K)-(j/2);E.fillText(this.name,G,F);i.Update(G,F,this.w1,this.h,K);return i.Active(E,J.mx,J.my)?i:null};h.prototype.DrawImage=function(E,I,D){var J=this.tc,G=this.x,F=this.y,H,j,K=this.sc,i=this.outline;E.globalAlpha=this.alpha;E.setTransform(K,0,0,K,0,0);E.fillStyle=this.colour;this.SetShadowColour(E,J.shadow,this.alpha);H=this.w*K;j=this.h*K;G+=(I/K)-(H/2);F+=(D/K)-(j/2);E.drawImage(this.image,G,F,H,j);i.Update(G,F,H,j,K);return i.Active(E,J.mx,J.my)?i:null};h.prototype.Calc=function(F,E){var i=c(this.p3d,F),j=this.tc,G=j.minBrightness,D=j.radius;this.p3d=e(i,E);i=v(j,this.p3d,this.w,this.h,Math.PI/4,20);this.x=i.x;this.y=i.y;this.sc=(j.z1+j.z2-i.z)/j.z2;this.alpha=Math.max(G,Math.min(1,G+1-((i.z-j.z2+D)/(2*D))))};h.prototype.Clicked=function(F){var j=this.a,D=j.target,E=j.href,i;if(D!=""&&D!="_self"){if(self.frames[D]){self.frames[D]=E}else{if(top.frames[D]){top.frames[D]=E}else{window.open(E,D)}}return}if(j.fireEvent){if(!j.fireEvent("onclick")){return}}else{i=document.createEvent("MouseEvents");i.initMouseEvent("click",true,true,window,0,0,0,0,0,false,false,false,false,0,null);if(!j.dispatchEvent(i)){return}}document.location=E};function z(J,j,E){var H,F,Q,G,D,M,P,R,L=document.getElementById(J),K=["id","class","innerHTML"],O,N=[];if(!L){throw 0}if(typeof(window.G_vmlCanvasManager)!="undefined"){L=window.G_vmlCanvasManager.initElement(L)}if(L&&(!L.getContext||!L.getContext("2d").fillText)){D=document.createElement("DIV");for(H=0;H<K.length;++H){D[K[H]]=L[K[H]]}L.parentNode.insertBefore(D,L);L.parentNode.removeChild(L);throw 0}for(H in z.options){this[H]=E&&typeof(E[H])!="undefined"?E[H]:(typeof(z[H])!="undefined"?z[H]:z.options[H])}this.canvas=L;this.ctxt=L.getContext("2d");this.z1=(19800/(Math.exp(this.depth)*(1-1/Math.E)))+20000-19800/(1-(1/Math.E));this.z2=this.z1*(1/this.zoom);this.radius=(L.height>L.width?L.width:L.height)*0.33*(this.z2+this.z1)/(this.z1);this.max_weight=0;this.min_weight=200;this.textFont=u(this.textFont);this.ctxt.shadowColor=this.shadow;this.shadow=this.ctxt.shadowColor;this.shadowAlpha=(this.shadowBlur||this.shadowOffset[0]||this.shadowOffset[1])&&g();try{F=document.getElementById(j||J);Q=F.getElementsByTagName("a");this.taglist=[];if(Q.length){G=B(Q.length);for(H=0;H<Q.length;++H){M=Q[H].getElementsByTagName("img");if(M.length){P=new Image;P.src=M[0].src;R=new h(this,P,Q[H],G[H],1,1);s(P,R,this.taglist)}else{this.taglist.push(new h(this,Q[H].innerText||Q[H].textContent,Q[H],G[H],2,this.textHeight+2))}if(this.weight){O=r(this,Q[H]);if(O>this.max_weight){this.max_weight=O}if(O<this.min_weight){this.min_weight=O}N.push(O)}}if(this.weight=(this.max_weight>this.min_weight)){for(H=0;H<this.taglist.length;++H){this.taglist[H].SetWeight(N[H])}}}if(j&&this.hideTags){F.style.display="none"}}catch(I){}this.yaw=this.initial?this.initial[0]*this.maxSpeed:0;this.pitch=this.initial?this.initial[1]*this.maxSpeed:0;D=o(L.id);this.cx=D.x;this.cy=D.y;if(!z.started){x("mousemove",f,null);x("mouseout",f,null);x("mouseup",a,null);z.started=setInterval(q,this.interval)}}z.prototype.Draw=function(){var E=this.canvas,I=0,F,H,J,D,G,j=this.taglist.length;J=this.ctxt;J.setTransform(1,0,0,1,0,0);F=E.width/2;H=E.height/2;this.active=null;for(G=0;G<j;++G){this.taglist[G].Calc(this.yaw,this.pitch)}this.taglist=this.taglist.sort(function(K,i){return K.sc-i.sc});J.textBaseline="top";if(this.shadowBlur||this.shadowOffset[0]||this.shadowOffset[1]){J.shadowBlur=this.shadowBlur;J.shadowOffsetX=this.shadowOffset[0];J.shadowOffsetY=this.shadowOffset[1]}J.clearRect(0,0,E.width,E.height);for(G=0;G<j;++G){D=this.taglist[G].Draw(J,F,H);if(D&&D.sc>I){this.active=D;this.active.index=G;I=D.sc}}if(this.freezeActive&&this.active){this.yaw=this.pitch=0}else{this.Animate(E.width,E.height)}if(this.active){this.active.Draw(J)}};z.prototype.Animate=function(H,E){var j=this,G=j.mx,F=j.my,J,I,D,i;if(G>=0&&F>=0&&G<H&&F<E){J=j.maxSpeed,i=j.reverse?-1:1;this.yaw=i*((J*2*G/H)-J);this.pitch=i*-((J*2*F/E)-J);this.initial=null}else{if(!j.initial){J=j.minSpeed,I=Math.abs(j.yaw),D=Math.abs(j.pitch);if(I>J){this.yaw=I>j.z0?j.yaw*j.decel:0}if(D>J){this.pitch=D>j.z0?j.pitch*j.decel:0}}}};z.prototype.Clicked=function(E){var D=this.taglist,i=this.active;try{if(i&&D[i.index]){D[i.index].Clicked(E)}}catch(j){}};z.Start=function(D,i,j){z.tc[D]=new z(D,i,j)};z.tc={};z.options={z1:20000,z2:20000,z0:0.0002,freezeActive:false,pulsateTo:0.15,pulsateTime:3,reverse:false,depth:0.5,maxSpeed:0.05,minSpeed:0,decel:0.95,interval:20,minBrightness:0.1,outlineColour:"#ffff99",outlineThickness:2,outlineOffset:5,textColour:"#ff99ff",textHeight:15,textFont:"Helvetica, Arial, sans-serif",shadow:"#000",shadowBlur:0,shadowOffset:[0,0],initial:null,hideTags:true,zoom:1,weight:false,weightMode:"size",weightFrom:null,weightSize:1,weightGradient:{0:"#f00",0.33:"#ff0",0.66:"#0f0",1:"#00f"}};for(y in z.options){z[y]=z.options[y]}window.TagCanvas=z})();
