
function LV_Register(object,domain,pixelx,pixely,offset,radius){var lv=[];object=this.Repair(object);if(!offset)offset=16777216;if(!radius)radius=16777216/Math.PI;lv.TS=(object=="TS")-0;lv.AOL=(object=="AOL")-0;this.object=object.toUpperCase();this.domain=domain.toLowerCase();this.pixelx=pixelx;this.pixely=pixely;this.offset=offset*16;this.radius=radius*16;this.deltax=[+1,+1][lv.TS];this.deltay=[+1,-1][lv.TS];if(lv.TS)this.LLToXY=this.TSLLToXY;if(lv.TS)this.XYToLL=this.TSXYToLL;if(lv.AOL)this.LLToXY=this.AOLLLToXY;if(lv.AOL)this.XYToLL=this.AOLXYToLL;if(lv.AOL)this.fixX=[7,4,1,0,0,0,0,0,0,0,0,0,0,0];if(lv.AOL)this.fixY=[276,244,136,68,34,88,230,46,100,120,6,180,140,130];if(lv.AOL)this.fixZ=[];if(lv.AOL)this.X=977908;if(lv.AOL)this.Y=1232624;if(lv.AOL)this.Z=[2500,4700,9000,18000,36000,74999,154950,324767,701289,1504475,3520471,9779086,29337258,88011773];}
LV_Register.prototype.BuildURL=function(z,w,x,y,X,Y){var lv=[];lv.prefix=(x+y)%4;lv.x=[parseInt((x>>16).toString(2),4),parseInt((x^x>>16<<16).toString(2),4)];lv.y=[parseInt((y>>16).toString(2),4),parseInt((y^y>>16<<16).toString(2),4)];lv.suffix=(("0000000000000000"+(lv.x[0]+lv.y[0]+lv.y[0]).toString(4)).slice(-16)+("0000000000000000"+(lv.x[1]+lv.y[1]+lv.y[1]).toString(4)).slice(-16)).slice(z-21);lv.file=[];if(this.domain)switch(this.object){case "VE":lv.file.shaded="http://tiles."+this.domain+"/tiles/r"+lv.suffix+".png?g=1&shading=hill";lv.file.street="http://tiles."+this.domain+"/tiles/r"+lv.suffix+".png?g=1";lv.file.aerial="http://tiles."+this.domain+"/tiles/a"+lv.suffix+".jpeg?g=1";lv.file.hybrid="http://tiles."+this.domain+"/tiles/h"+lv.suffix+".jpeg?g=1";break;case "MSN":lv.file.shaded="http://tiles."+this.domain+"/tiles/r"+lv.suffix+".png?g=1&shading=hill";lv.file.street="http://tiles."+this.domain+"/tiles/r"+lv.suffix+".png?g=1";lv.file.aerial="http://tiles."+this.domain+"/tiles/a"+lv.suffix+".jpeg?g=1";lv.file.hybrid="http://tiles."+this.domain+"/tiles/h"+lv.suffix+".jpeg?g=1";break;case "GOOGLE":lv.file.shaded="http://mt0."+this.domain+"/vt/lyrs=p@150"+"&x="+x+"&y="+y+"&z="+(21-z+0);lv.file.street="http://mt0."+this.domain+"/vt/lyrs=m@150"+"&x="+x+"&y="+y+"&z="+(21-z+0);lv.file.aerial="http://mt0."+this.domain+"/vt/lyrs=s@150"+"&x="+x+"&y="+y+"&z="+(21-z+0);lv.file.hybrid="http://mt0."+this.domain+"/vt/lyrs=y@150"+"&x="+x+"&y="+y+"&z="+(21-z+0);break;case "YAHOO":lv.file.shaded="http://maps1."+this.domain+"/hx/tl?v=5.0&r=1&t=n"+"&x="+(x)+"&y="+((1<<20>>z)-y-1)+"&z="+(21-z+1);lv.file.street="http://maps1."+this.domain+"/hx/tl?v=5.0&r=1&t=m"+"&x="+(x)+"&y="+((1<<20>>z)-y-1)+"&z="+(21-z+1);lv.file.aerial="http://maps1."+this.domain+"/ae/tl?v=5.0&r=1&t=a"+"&x="+(x)+"&y="+((1<<20>>z)-y-1)+"&z="+(21-z+1);lv.file.hybrid="http://maps1."+this.domain+"/hx/tl?v=5.0&r=1&t=h"+"&x="+(x)+"&y="+((1<<20>>z)-y-1)+"&z="+(21-z+1);break;case "AOL":if(z<4)z=4;if(z>17)z=17;x=~~(0*this.X/this.Z[z-4])+x+0;y=~~(180*this.Y/this.Z[z-4])-y-1;lv.prefix=(x+y)%4+1;lv.file.shaded="http://tile"+lv.prefix+"."+this.domain+"/map/Scale"+this.Z[z-4]+"/"+(~~(y/1000))+"/"+(y%1000)+"/"+(~~(x/1000))+"/"+(x%1000)+".gif?/tiles";lv.file.street="http://tile"+lv.prefix+"."+this.domain+"/map/Scale"+this.Z[z-4]+"/"+(~~(y/1000))+"/"+(y%1000)+"/"+(~~(x/1000))+"/"+(x%1000)+".gif?/tiles";lv.file.aerial="http://tile"+lv.prefix+"."+this.domain+"/sat/Scale"+this.Z[z-4]+"/"+(~~(y/1000))+"/"+(y%1000)+"/"+(~~(x/1000))+"/"+(x%1000)+".jpg?/tiles";lv.file.hybrid="http://tile"+lv.prefix+"."+this.domain+"/hyb/Scale"+this.Z[z-4]+"/"+(~~(y/1000))+"/"+(y%1000)+"/"+(~~(x/1000))+"/"+(x%1000)+".gif?/tiles";break;case "TS":lv.file.detail="http://terraserver."+this.domain+"/tile.ashx?s="+(z+6)+"&x="+x+"&y="+y+"&z="+w+"&t=4";lv.file.topo="http://terraserver."+this.domain+"/tile.ashx?s="+(z+6)+"&x="+x+"&y="+y+"&z="+w+"&t=3";lv.file.topo="http://terraserver."+this.domain+"/tile.ashx?s="+(z+6)+"&x="+x+"&y="+y+"&z="+w+"&t=2";lv.file.aerial="http://terraserver."+this.domain+"/tile.ashx?s="+(z+6)+"&x="+x+"&y="+y+"&z="+w+"&t=1";break;default:break;}return lv.file;}
LV_Register.prototype.LToX=function(z,w,x,y){return(this.offset+this.radius*x*Math.PI/180)>>z;}
LV_Register.prototype.LToY=function(z,w,x,y){return(this.offset-this.radius*Math.log((1+Math.sin(y*Math.PI/180))/(1-Math.sin(y*Math.PI/180)))/2)>>z;}
LV_Register.prototype.XToL=function(z,w,x,y){return(((x<<z)-this.offset)/this.radius)*180/Math.PI;}
LV_Register.prototype.YToL=function(z,w,x,y){return(Math.PI/2-2*Math.atan(Math.exp(((y<<z)-this.offset)/this.radius)))*180/Math.PI;}
LV_Register.prototype.LLToXY=function(z,w,x,y){return[this.LToX(z,w,x,y),this.LToY(z,w,x,y)];}
LV_Register.prototype.XYToLL=function(z,w,x,y){return[this.XToL(z,w,x,y),this.YToL(z,w,x,y)];}
LV_Register.prototype.Repair=function(object){object=object.replace(/Terra\ *Server/gi,"TS");object=object.replace(/Virtual\ *Earth/gi,"VE");return object;}
LV_Register.prototype.ArcLength=function(y){var c,d,e,f,k,l,s,t;var a=6378137.000;var b=6356752.314;e=(a-b)/(a+b);var l0=((a+b)/2)*(1+e*e/4+e*e*e*e/64);var l1=-3*e/2+9*e*e*e/16-3*e*e*e*e*e/32;var l2=15*e*e/16-15*e*e*e*e/32;var l3=-35*e*e*e/48+105*e*e*e*e*e/256;var l4=315*e*e*e*e/512;y=y+l1*Math.sin(2*y)+l2*Math.sin(4*y)+l3*Math.sin(6*y)+l4*Math.sin(8*y);y=y*l0;return y;}
LV_Register.prototype.FootPoint=function(y){var c,d,e,f,k,l,s,t;var a=6378137.000;var b=6356752.314;e=(a-b)/(a+b);var l0=((a+b)/2)*(1+e*e/4+e*e*e*e/64);var l1=3*e/2-27*e*e*e/32+269*e*e*e*e*e/512;var l2=21*e*e/16-55*e*e*e*e/32;var l3=151*e*e*e/96-417*e*e*e*e*e/128;var l4=1097*e*e*e*e/512;y=y/l0;y=y+l1*Math.sin(2*y)+l2*Math.sin(4*y)+l3*Math.sin(6*y)+l4*Math.sin(8*y);return y;}
LV_Register.prototype.KludgeLLToXY=function(z,w,x,y){var c,d,e,f,k,l,s,t;var a=6378137.000;var b=6356752.314;l=(w*6-183)*Math.PI/180;e=(a*a-b*b)/(b*b);c=Math.cos(y);s=Math.sin(y);t=Math.tan(y);y=this.ArcLength(y);f=e*c*c;k=a*a/(b*Math.sqrt(1+f));d=(x-l)*c;x=0;var l0=1;var l1=1*t;var l2=1-t*t+f;var l3=5*t-t*t*t+9*t*f+4*t*f*f;var l4=5-18*t*t+t*t*t*t+14*f-58*t*t*f;var l5=61*t-58*t*t*t+t*t*t*t*t+270*t*f-330*t*t*t*f;var l6=61-479*t*t+179*t*t*t*t-t*t*t*t*t*t;var l7=1385*t-3111*t*t*t+543*t*t*t*t*t-t*t*t*t*t*t*t;x=x+l0*d*k+l2*d*d*d*k/6+l4*d*d*d*d*d*k/120+l6*d*d*d*d*d*d*d*k/5040;y=y+l1*d*d*k/2+l3*d*d*d*d*k/24+l5*d*d*d*d*d*d*k/720+l7*d*d*d*d*d*d*d*d*k/40320;return[x,y];}
LV_Register.prototype.KludgeXYToLL=function(z,w,x,y){var c,d,e,f,k,l,s,t;var a=6378137.000;var b=6356752.314;l=(w*6-183)*Math.PI/180;e=(a*a-b*b)/(b*b);y=this.FootPoint(y);c=Math.cos(y);s=Math.sin(y);t=Math.tan(y);f=e*c*c;k=a*a/(b*Math.sqrt(1+f));d=x/k;x=l;var l0=1;var l1=-1*t-t*f;var l2=-1-2*t*t-f;var l3=5*t+3*t*t*t+6*t*f-6*t*t*t*f-3*t*f*f-9*t*t*t*f*f;var l4=5+28*t*t+24*t*t*t*t+6*f+8*t*t*f;var l5=-61*t-90*t*t*t-45*t*t*t*t*t-107*t*f+162*t*t*t*f;var l6=-61-662*t*t-1320*t*t*t*t-720*t*t*t*t*t*t;var l7=1385*t+3633*t*t*t+4095*t*t*t*t*t+1575*t*t*t*t*t*t*t;x=x+l0*d/c+l2*d*d*d/6/c+l4*d*d*d*d*d/120/c+l6*d*d*d*d*d*d*d/5040/c;y=y+l1*d*d/2+l3*d*d*d*d/24+l5*d*d*d*d*d*d/720+l7*d*d*d*d*d*d*d*d/40320;return[x,y];}
LV_Register.prototype.TSLLToXY=function(z,w,x,y){var sphere=0;var radius=0.9996;w=this.LLToZ(x,y);x=x*Math.PI/180;y=y*Math.PI/180;var xy=this.KludgeLLToXY(z,w,x,y);x=((xy[0]*radius+500000)*16)>>z;y=((xy[1]*radius+sphere)*16)>>z;return[x,y];}
LV_Register.prototype.TSXYToLL=function(z,w,x,y){var sphere=0;var radius=0.9996;x=((x<<z)/16-500000)/radius;y=((y<<z)/16-sphere)/radius;var xy=this.KludgeXYToLL(z,w,x,y);x=xy[0]*180/Math.PI;y=xy[1]*180/Math.PI;w=this.LLToZ(x,y);return[x,y];}
LV_Register.prototype.AOLLLToXY=function(z,w,x,y){if(z<4)z=4;if(z>17)z=17;return[Math.round((180+x)*this.pixelx*this.X/this.Z[z-4]+this.fixX[z-4]),Math.round((90-y)*this.pixely*this.Y/this.Z[z-4]-this.fixY[z-4])];}
LV_Register.prototype.AOLXYToLL=function(z,w,x,y){if(z<4)z=4;if(z>17)z=17;return[(Math.round(x-this.fixX[z-4])*this.Z[z-4]/this.X/this.pixelx)-180,90-(Math.round(y+this.fixY[z-4])*this.Z[z-4]/this.Y/this.pixely)];}
LV_Register.prototype.LLToZ=function(x,y){return(~~((x+180)/6)+1);}
