/**
 * 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.12
 * For more information, please contact <graham@goat1000.com>
 */
(function(){var O,N,F=Math.abs,q=Math.sin,g=Math.cos,y=Math.max,S=Math.min,A={},B={},C={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,"},d,G,c,h=document,x;for(O=0;O<256;++O){N=O.toString(16);if(O<16){N="0"+N}B[N]=B[N.toUpperCase()]=O.toString()+","}function K(i){return typeof(i)!="undefined"}function m(aa){var j,Z,V,U,Y=[],W=Math.PI*(3-Math.sqrt(5)),X=2/aa;for(j=0;j<aa;++j){Z=j*X-1+(X/2);V=Math.sqrt(1-Z*Z);U=j*W;Y.push([g(U)*V,Z,q(U)*V])}return Y}function R(W,U,ab,aa,Z,Y){var ac,ad=[],X=Math.PI*(3-Math.sqrt(5)),V=2/W;for(ab=0;ab<W;++ab){aa=ab*V-1+(V/2);ac=ab*X;Z=g(ac);Y=q(ac);ad.push(U?[aa,Z,Y]:[Z,aa,Y])}return ad}function v(i){return R(i)}function E(i){return R(i,1)}function o(X,i){var W=X,V,U,j=(i*1).toPrecision(3)+")";if(X[0]==="#"){if(!A[X]){if(X.length===4){A[X]="rgba("+C[X[1]]+C[X[2]]+C[X[3]]}else{A[X]="rgba("+B[X.substr(1,2)]+B[X.substr(3,2)]+B[X.substr(5,2)]}}W=A[X]+j}else{if(X.substr(0,4)==="rgb("||X.substr(0,4)==="hsl("){W=(X.replace("(","a(").replace(")",","+j))}else{if(X.substr(0,5)==="rgba("||X.substr(0,5)==="hsla("){V=X.lastIndexOf(",")+1,U=X.indexOf(")");i*=parseFloat(X.substring(V,U));W=X.substr(0,V)+i.toPrecision(3)+")"}}}return W}function f(i,j){if(window.G_vmlCanvasManager){return null}var U=h.createElement("canvas");U.width=i;U.height=j;return U}function u(){var j=f(3,3),V,U;if(!j){return false}V=j.getContext("2d");V.strokeStyle="#000";V.shadowColor="#fff";V.shadowBlur=3;V.globalAlpha=0;V.strokeRect(2,2,2,2);V.globalAlpha=1;U=V.getImageData(2,2,1,1);j=null;return(U.data[0]>0)}function T(ab,j){var U=1024,X=ab.weightGradient,W,Z,V,aa,Y;if(ab.gCanvas){Z=ab.gCanvas.getContext("2d")}else{ab.gCanvas=W=f(U,1);if(!W){return null}Z=W.getContext("2d");aa=Z.createLinearGradient(0,0,U,0);for(V in X){aa.addColorStop(1-V,X[V])}Z.fillStyle=aa;Z.fillRect(0,0,U,1)}Y=Z.getImageData(~~((U-1)*j),0,1,1).data;return"rgba("+Y[0]+","+Y[1]+","+Y[2]+","+(Y[3]/255)+")"}function t(X,W,U,aa,Y,Z,j){var V=(Z||0)+(j&&j[0]<0?F(j[0]):0),i=(Z||0)+(j&&j[1]<0?F(j[1]):0);X.font=W;X.textBaseline="top";X.fillStyle=U;Y&&(X.shadowColor=Y);Z&&(X.shadowBlur=Z);j&&(X.shadowOffsetX=j[0],X.shadowOffsetY=j[1]);X.fillText(aa,V,i)}function k(ag,Y,ac,ae,X,U,aa,ab,j,af,ad){var V=ae+F(j[0])+ab+ab,i=X+F(j[1])+ab+ab,W,Z;W=f(V+af,i+ad);if(!W){return null}Z=W.getContext("2d");t(Z,Y,U,ag,aa,ab,j);return W}function M(Y,ab,ac,V){var W=Y.width+F(V[0])+ac+ac,j=Y.height+F(V[1])+ac+ac,Z,aa,X=(ac||0)+(V&&V[0]<0?F(V[0]):0),U=(ac||0)+(V&&V[1]<0?F(V[1]):0);Z=f(W,j);if(!Z){return null}aa=Z.getContext("2d");ab&&(aa.shadowColor=ab);ac&&(aa.shadowBlur=ac);V&&(aa.shadowOffsetX=V[0],aa.shadowOffsetY=V[1]);aa.drawImage(Y,X,U);return Z}function H(ag,Y,ae){var af=parseInt(ag.length*ae),X=parseInt(ae*2),V=f(af,X),ab,j,W,aa,ad,ac,U,Z;if(!V){return null}ab=V.getContext("2d");ab.fillStyle="#000";ab.fillRect(0,0,af,X);t(ab,ae+"px "+Y,"#fff",ag);j=ab.getImageData(0,0,af,X);W=j.width;aa=j.height;Z={min:{x:W,y:aa},max:{x:-1,y:-1}};for(ac=0;ac<aa;++ac){for(ad=0;ad<W;++ad){U=(ac*W+ad)*4;if(j.data[U+1]>0){if(ad<Z.min.x){Z.min.x=ad}if(ad>Z.max.x){Z.max.x=ad}if(ac<Z.min.y){Z.min.y=ac}if(ac>Z.max.y){Z.max.y=ac}}}}if(W!=af){Z.min.x*=(af/W);Z.max.x*=(af/W)}if(aa!=X){Z.min.y*=(af/aa);Z.max.y*=(af/aa)}V=null;return Z}function s(i){return"'"+i.replace(/(\'|\")/g,"").replace(/\s*,\s*/g,"', '")+"'"}function z(i,j,U){U=U||h;if(U.addEventListener){U.addEventListener(i,j,false)}else{U.attachEvent("on"+i,j)}}function L(V,U,j){if(V.complete){U.w=V.width;U.h=V.height;j.push(U)}else{z("load",function(){U.w=this.width;U.h=this.height;j.push(U)},V)}}function J(V,U){var j=h.defaultView,i=U.replace(/\-([a-z])/g,function(W){return W[1].toUpperCase()});return(j&&j.getComputedStyle&&j.getComputedStyle(V,null).getPropertyValue(U))||(V.currentStyle&&V.currentStyle[i])}function w(U,j){var i=1,V;if(U.weightFrom){i=1*(j.getAttribute(U.weightFrom)||U.textHeight)}else{if(V=J(j,"font-size")){i=(V.indexOf("px")>-1&&V.replace("px","")*1)||(V.indexOf("pt")>-1&&V.replace("pt","")*1.25)||V*3.3}else{U.weight=false}}return i}function I(X){var V,U,j=h.documentElement,W;for(V in r.tc){U=r.tc[V];W=l(V);if(X.pageX){U.mx=X.pageX-W.x;U.my=X.pageY-W.y}else{U.mx=X.clientX+(j.scrollLeft||h.body.scrollLeft)-W.x;U.my=X.clientY+(j.scrollTop||h.body.scrollTop)-W.y}}}function p(V){var j=r,i=h.addEventListener?0:1,U=V.target&&K(V.target.id)?V.target.id:V.srcElement.parentNode.id;if(U&&V.button==i&&j.tc[U]){I(V);j.tc[U].Clicked(V)}}function Q(U){var i=r,j=U.target&&K(U.target.id)?U.target.id:U.srcElement.parentNode.id;if(j&&i.tc[j]){U.cancelBubble=true;U.returnValue=false;U.preventDefault&&U.preventDefault();i.tc[j].Wheel((U.wheelDelta||U.detail)>0)}}function n(){var U=r.tc,j;for(j in U){U[j].Draw()}}function l(V){var U,j,i;U=h.getElementById(V);j={x:U.offsetLeft,y:U.offsetTop};while(U.offsetParent){i=U.offsetParent;j.x+=i.offsetLeft;j.y+=i.offsetTop;U=i}return j}function b(U,i){var j=q(i),V=g(i);return{x:U.x,y:(U.y*V)+(U.z*j),z:(U.y*-j)+(U.z*V)}}function a(U,i){var j=q(i),V=g(i);return{x:(U.x*V)+(U.z*-j),y:U.y,z:(U.x*j)+(U.z*V)}}function P(V,ab,aa,Y,W,j){var i,X,Z,U=V.z1/(V.z1+V.z2+ab.z);i=ab.y*U;X=ab.x*U;Z=V.z2+ab.z;return{x:X,y:i,z:Z}}function e(i){this.ts=new Date().valueOf();this.tc=i;this.x=this.y=this.w=this.h=this.sc=1;this.z=0;this.SetMethod(i.outlineMethod)}d=e.prototype;d.SetMethod=function(U){var j={block:["PreDraw","DrawBlock"],colour:["PreDraw","DrawColour"],outline:["PostDraw","DrawOutline"],classic:["LastDraw","DrawOutline"]},i=j[U]||j.outline;this[i[0]]=this.Draw;this.drawFunc=this[i[1]]};d.Update=function(aa,Z,ab,X,Y,j,W,i){var U=this.tc.outlineOffset,V=2*U;this.x=Y*aa+W-U;this.y=Y*Z+i-U;this.w=Y*ab+V;this.h=Y*X+V;this.sc=Y;this.z=j.z};d.DrawOutline=function(X,i,W,j,U,V){X.strokeStyle=V;X.strokeRect(i,W,j,U)};d.DrawColour=function(V,Y,W,Z,U,i,aa,j,X){return this[aa.image?"DrawColourImage":"DrawColourText"](V,Y,W,Z,U,i,aa,j,X)};d.DrawColourText=function(W,Z,X,aa,U,i,ab,j,Y){var V=ab.colour;ab.colour=i;ab.Draw(W,j,Y);ab.colour=V;return 1};d.DrawColourImage=function(Z,ac,aa,ad,Y,i,ag,j,ab){var ae=Z.canvas,W=~~y(ac,0),V=~~y(aa,0),X=S(ae.width-W,ad)+0.5|0,af=S(ae.height-V,Y)+0.5|0,U;if(x){x.width=X,x.height=af}else{x=f(X,af)}if(!x){return this.SetMethod("outline")}U=x.getContext("2d");U.drawImage(ae,W,V,X,af,0,0,X,af);Z.clearRect(W,V,X,af);ag.Draw(Z,j,ab);Z.setTransform(1,0,0,1,0,0);Z.save();Z.beginPath();Z.rect(W,V,X,af);Z.clip();Z.globalCompositeOperation="source-in";Z.fillStyle=i;Z.fillRect(W,V,X,af);Z.restore();Z.globalCompositeOperation="destination-over";Z.drawImage(x,0,0,X,af,W,V,X,af);Z.globalCompositeOperation="source-over";return 1};d.DrawBlock=function(X,i,W,j,U,V){X.fillStyle=V;X.fillRect(i,W,j,U)};d.Draw=function(X,i,j,V){var W=new Date().valueOf()-this.ts,U=this.tc;X.setTransform(1,0,0,1,0,0);X.strokeStyle=U.outlineColour;X.lineWidth=U.outlineThickness;X.shadowBlur=X.shadowOffsetX=X.shadowOffsetY=0;if(U.pulsateTo<1){X.globalAlpha=U.pulsateTo+((1-U.pulsateTo)*(0.5+(g(2*Math.PI*W/(1000*U.pulsateTime))/2)))}else{X.globalAlpha=1}return this.drawFunc(X,this.x,this.y,this.w,this.h,U.outlineColour,i,j,V)};d.Active=function(U,i,j){return(i>=this.x&&j>=this.y&&i<=this.x+this.w&&j<=this.y+this.h)};d.PreDraw=d.PostDraw=d.LastDraw=function(){};function D(W,j,aa,ac,ab,Y,U,V){var Z=W.ctxt,X;this.tc=W;this.image=j.src?j:null;this.name=j.src?"":j;this.a=aa;this.p3d={x:ac[0]*W.radius*1.1,y:ac[1]*W.radius*1.1,z:ac[2]*W.radius*1.1};this.x=this.y=0;this.w=ab;this.h=Y;this.colour=U||W.textColour;this.textFont=V||W.textFont;this.weight=this.sc=this.alpha=1;this.weighted=!W.weight;this.outline=new e(W);if(this.image){if(W.txtOpt&&W.shadow){X=M(this.image,W.shadow,W.shadowBlur,W.shadowOffset);if(X){this.image=X;this.w=X.width;this.h=X.height}}}else{this.textHeight=W.textHeight;this.extents=H(this.name,this.textFont,this.textHeight);this.Measure(Z,W)}this.SetShadowColour=W.shadowAlpha?this.SetShadowColourAlpha:this.SetShadowColourFixed;this.SetDraw(W)}G=D.prototype;G.SetDraw=function(i){this.Draw=this.image?(i.ie>7?this.DrawImageIE:this.DrawImage):this.DrawText};G.Measure=function(Y,j){this.h=this.extents?this.extents.max.y+this.extents.min.y:this.textHeight;Y.font=this.font=this.textHeight+"px "+this.textFont;this.w=Y.measureText(this.name).width;if(j.txtOpt){var V=j.txtScale,W=V*this.textHeight,X=W+"px "+this.textFont,U=[V*j.shadowOffset[0],V*j.shadowOffset[1]],i;Y.font=X;i=Y.measureText(this.name).width;this.image=k(this.name,X,W,i,V*this.h,this.colour,j.shadow,V*j.shadowBlur,U,V,V);if(this.image){this.w=this.image.width/V;this.h=this.image.height/V}this.SetDraw(j);j.txtOpt=this.image}};G.SetWeight=function(i){this.weight=i;this.Weight(this.tc.ctxt,this.tc);this.Measure(this.tc.ctxt,this.tc)};G.Weight=function(V,U){var j=this.weight,i=U.weightMode;this.weighted=true;if(i=="colour"||i=="both"){this.colour=T(U,(j-U.min_weight)/(U.max_weight-U.min_weight))}if(i=="size"||i=="both"){this.textHeight=j*U.weightSize}this.extents=H(this.name,this.textFont,this.textHeight)};G.SetShadowColourFixed=function(U,j,i){U.shadowColor=j};G.SetShadowColourAlpha=function(U,j,i){U.shadowColor=o(j,i)};G.DrawText=function(U,Y,j){var Z=this.tc,W=this.x,V=this.y,X,i,aa=this.sc;U.globalAlpha=this.alpha;U.setTransform(aa,0,0,aa,0,0);U.fillStyle=this.colour;Z.shadow&&this.SetShadowColour(U,Z.shadow,this.alpha);U.font=this.font;X=this.w;i=this.h;W+=(Y/aa)-(X/2);V+=(j/aa)-(i/2);U.fillText(this.name,W,V)};G.DrawImage=function(W,aa,V){var ab=this.tc,Y=this.x,X=this.y,ac=this.sc,j=this.image,Z=this.w,U=this.h;W.globalAlpha=this.alpha;W.setTransform(ac,0,0,ac,0,0);W.fillStyle=this.colour;ab.shadow&&this.SetShadowColour(W,ab.shadow,this.alpha);Y+=(aa/ac)-(Z/2);X+=(V/ac)-(U/2);W.drawImage(j,Y,X,Z,U)};G.DrawImageIE=function(W,aa,V){var j=this.image,ab=this.sc,Z=j.width=this.w*ab,U=j.height=this.h*ab,Y=(this.x*ab)+aa-(Z/2),X=(this.y*ab)+V-(U/2);W.globalAlpha=this.alpha;W.drawImage(j,Y,X)};G.Calc=function(W,V){var i=a(this.p3d,W),j=this.tc,X=j.minBrightness,U=j.radius;this.p3d=b(i,V);i=P(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=y(X,S(1,X+1-((i.z-j.z2+U)/(2*U))))};G.CheckActive=function(V,Z,U){var aa=this.tc,ab=this.sc,i=this.outline,Y=this.w,j=this.h,X=this.x-Y/2,W=this.y-j/2;i.Update(X,W,Y,j,ab,this.p3d,Z,U);return i.Active(V,aa.mx,aa.my)?i:null};G.Clicked=function(W){var j=this.a,U=j.target,V=j.href,i;if(U!=""&&U!="_self"){if(self.frames[U]){self.frames[U]=V}else{if(top.frames[U]){top.frames[U]=V}else{window.open(V,U)}}return}if(j.fireEvent){if(!j.fireEvent("onclick")){return}}else{i=h.createEvent("MouseEvents");i.initMouseEvent("click",1,1,window,0,0,0,0,0,0,0,0,0,0,null);if(!j.dispatchEvent(i)){return}}h.location=V};function r(ab,j,V){var Z,W,ai,X,U,ae,ah,aj,ad=h.getElementById(ab),ac=["id","class","innerHTML"],ag,af=[],Y={sphere:m,vcylinder:v,hcylinder:E};if(!ad){throw 0}if(K(window.G_vmlCanvasManager)){ad=window.G_vmlCanvasManager.initElement(ad);this.ie=parseFloat(navigator.appVersion.split("MSIE")[1])}if(ad&&(!ad.getContext||!ad.getContext("2d").fillText)){U=h.createElement("DIV");for(Z=0;Z<ac.length;++Z){U[ac[Z]]=ad[ac[Z]]}ad.parentNode.insertBefore(U,ad);ad.parentNode.removeChild(ad);throw 0}for(Z in r.options){this[Z]=V&&K(V[Z])?V[Z]:(K(r[Z])?r[Z]:r.options[Z])}this.canvas=ad;this.ctxt=ad.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=(ad.height>ad.width?ad.width:ad.height)*0.33*(this.z2+this.z1)/(this.z1);this.max_weight=0;this.min_weight=200;this.textFont=this.textFont&&s(this.textFont);this.pulsateTo*=1;this.textHeight*=1;this.minBrightness*=1;this.ctxt.textBaseline="top";if(this.shadowBlur||this.shadowOffset[0]||this.shadowOffset[1]){this.ctxt.shadowColor=this.shadow;this.shadow=this.ctxt.shadowColor;this.shadowAlpha=u()}else{delete this.shadow}try{W=h.getElementById(j||ab);ai=W.getElementsByTagName("a");this.taglist=[];if(ai.length){this.shape=Y[this.shape]||Y.sphere;X=this.shape(ai.length);for(Z=0;Z<ai.length;++Z){ae=ai[Z].getElementsByTagName("img");if(ae.length){ah=new Image;ah.src=ae[0].src;aj=new D(this,ah,ai[Z],X[Z],1,1);L(ah,aj,this.taglist)}else{this.taglist.push(new D(this,ai[Z].innerText||ai[Z].textContent,ai[Z],X[Z],2,this.textHeight+2,this.textColour||J(ai[Z],"color"),this.textFont||s(J(ai[Z],"font-family"))))}if(this.weight){ag=w(this,ai[Z]);if(ag>this.max_weight){this.max_weight=ag}if(ag<this.min_weight){this.min_weight=ag}af.push(ag)}}if(this.weight=(this.max_weight>this.min_weight)){for(Z=0;Z<this.taglist.length;++Z){this.taglist[Z].SetWeight(af[Z])}}}if(j&&this.hideTags){W.style.display="none"}}catch(aa){aa}this.yaw=this.initial?this.initial[0]*this.maxSpeed:0;this.pitch=this.initial?this.initial[1]*this.maxSpeed:0;z("mousemove",I,ad);z("mouseout",I,ad);z("mouseup",p,ad);if(this.wheelZoom){z("mousewheel",Q,ad);z("DOMMouseScroll",Q,ad)}r.started||(r.started=setInterval(n,this.interval))}c=r.prototype;c.Draw=function(){var ad=this.canvas,ab=ad.width,U=ad.height,j=0,aa=this.yaw,V=this.pitch,W=ab/2,ag=U/2,ae=this.ctxt,Y,af,ac,Z=-1,ah=this.taglist,X=ah.length;if(aa==0&&V==0&&this.drawn){return this.Animate(ab,U)}ae.setTransform(1,0,0,1,0,0);this.active=null;for(ac=0;ac<X;++ac){ah[ac].Calc(aa,V)}ah=ah.sort(function(ai,i){return ai.sc-i.sc});for(ac=0;ac<X;++ac){af=ah[ac].CheckActive(ae,W,ag);if(af&&af.sc>j&&(!this.frontSelect||af.z<=0)){Y=af;Y.index=Z=ac;j=af.sc}}this.active=Y;if(!this.txtOpt&&this.shadow){ae.shadowBlur=this.shadowBlur;ae.shadowOffsetX=this.shadowOffset[0];ae.shadowOffsetY=this.shadowOffset[1]}ae.clearRect(0,0,ab,U);for(ac=0;ac<X;++ac){if(!(Z==ac&&Y.PreDraw(ae,ah[ac],W,ag))){ah[ac].Draw(ae,W,ag)}Z==ac&&Y.PostDraw(ae)}if(this.freezeActive&&Y){this.yaw=this.pitch=this.drawn=0}else{this.Animate(ab,U);this.drawn=1}Y&&Y.LastDraw(ae)};c.Animate=function(Z,W){var U=this,Y=U.mx,X=U.my,j=U.lock,ab,aa,V,i;if(Y>=0&&X>=0&&Y<Z&&X<W){ab=U.maxSpeed,i=U.reverse?-1:1;if(j!="x"){this.yaw=i*((ab*2*Y/Z)-ab)}if(j!="y"){this.pitch=i*-((ab*2*X/W)-ab)}this.initial=null}else{if(!U.initial){ab=U.minSpeed,aa=F(U.yaw),V=F(U.pitch);if(j!="x"&&aa>ab){this.yaw=aa>U.z0?U.yaw*U.decel:0}if(j!="y"&&V>ab){this.pitch=V>U.z0?U.pitch*U.decel:0}}}};c.Zoom=function(i){this.z2=this.z1*(1/i);this.drawn=0};c.Clicked=function(V){var U=this.taglist,i=this.active;try{if(i&&U[i.index]){U[i.index].Clicked(V)}}catch(j){}};c.Wheel=function(j){var U=this.zoom+this.zoomStep*(j?1:-1);this.zoom=S(this.zoomMax,y(this.zoomMin,U));this.Zoom(this.zoom)};r.Start=function(U,i,j){r.tc[U]=new r(U,i,j)};r.tc={};r.options={z1:20000,z2:20000,z0:0.0002,freezeActive:false,pulsateTo:1,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,outlineMethod:"outline",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"},txtOpt:true,txtScale:2,frontSelect:false,wheelZoom:true,zoomMin:0.3,zoomMax:3,zoomStep:0.05,shape:"sphere",lock:null};for(O in r.options){r[O]=r.options[O]}window.TagCanvas=r})();

