// TPhoto() GMaps API extension copyright 2005 Tom Mangan (tmangan@gmail.com)
// http://gmaps.tommangan.us/tphoto.html
// free for non-commercial use
// the 'Made with TPhoto' bug must remain in place for free use
function normSin(a){
 if(a>0.9999){a=0.9999;}
 if(a<-0.9999){a=-0.9999;}
 return a;
}
function TPhoto(){}
TPhoto.prototype.initialize=function(a){
 if (a.TBugged<1||typeof(a.TBugged=='undefined')){this.addTBug(a);}
 var b=document.createElement('img');
 b.style.display='none';
 b.setAttribute('id',this.id);
 b.setAttribute('src',this.src);
 b.style.position='absolute';
 b.style.zIndex=1;
 this.mapTray=document.getElementById(a.getContainer().id).firstChild;
 this.mapTray.appendChild(b);
 this.setPosition(a);
 b.style.display='block';
 if(this.percentOpacity){this.setOpacity(this.percentOpacity);}
// GEvent.bind(a,"zoomend",this,function(){this.setPosition(a)});
// GEvent.bind(a,"zoomend",this,function(){this.setPosition(a)});
}
TPhoto.prototype.setPosition=function(a){
 var b=this.anchorTopLeft;
 var c=this.anchorBottomRight;
 var d=this.getXY(a,b);
 var e=this.getXY(a,c);
 var x=document.getElementById(this.id);
//alert(x);

 x.style.top=d.y+'px';
 x.style.left=d.x+'px';
 x.style.width=e.x-d.x+'px';
 x.style.height=e.y-d.y+'px';
}
TPhoto.prototype.getXY=function(a,b){
 var c=a.getZoom();
 var d=a.getSize();
 var e=a.getCenter();
 with(Math){
  var pxLng=128*pow(2,c)/180;
  var pxLat=128*pow(2,c)/PI;
  var xDif=-(e.x-b.x)*pxLng;
  var g=normSin(sin(b.y*PI/180));
  var h=normSin(sin(e.y*PI/180));
  var yDif=(0.5*log((1+h)/(1-h))-0.5*log((1+g)/(1-g)))*pxLat;
  var x=round((d.width/2)+xDif)-parseInt(this.mapTray.style.left);
  var y=round((d.height/2)+yDif)-parseInt(this.mapTray.style.top);
 }
 return(new GPoint(x,y));
}
TPhoto.prototype.setOpacity=function(b){
 if(b<0){b=0;}  if(b>=100){b=100;}
 var c=b/100;
 var d=document.getElementById(this.id);
 if(typeof(d.style.filter)=='string'){d.style.filter='alpha(opacity:'+b+')';}
 if(typeof(d.style.KHTMLOpacity)=='string'){d.style.KHTMLOpacity=c;}
 if(typeof(d.style.MozOpacity)=='string'){d.style.MozOpacity=c;}
 if(typeof(d.style.opacity)=='string'){d.style.opacity=c;}
}
TPhoto.prototype.addTBug=function(a){
 if(typeof(a.TBugged)=='undefined'){
  var b=document.createElement('div');
  b.id='TPhotoBug';
  b.style.position='absolute';
  b.style.right='0px';
  b.style.bottom='20px';
  b.style.backgroundColor='#f2efe9';
  b.style.zIndex=25500;
  b.innerHTML='<a href="http://gmaps.tommangan.us/tphoto.html" style="font: 10px verdana; text-decoration: none; padding: 2px; color: #000;">Made with TPhoto</a>';
  document.getElementById(a.getContainer().id).appendChild(b);
  var c=0.7;
  var d=document.getElementById(b.id);
  if(typeof(d.style.filter)=='string'){d.style.filter='alpha(opacity:'+c*100+')';}
  if(typeof(d.style.KHTMLOpacity)=='string'){d.style.KHTMLOpacity=c;}
  if(typeof(d.style.MozOpacity)=='string'){d.style.MozOpacity=c;}
  if(typeof(d.style.opacity)=='string'){d.style.opacity=c;}
  a.TBugged=1;
 }
}
GMap.prototype.addTPhoto=function(a){
 a.initialize(this);
}
GMap.prototype.removeTPhoto=function(a){
 var b=document.getElementById(a.id);
 document.getElementById(this.getContainer().id).firstChild.removeChild(b);
 delete(b);
}
GMap2.prototype.addTPhoto=function(a){
 a.initialize(this);
}
GMap2.prototype.removeTPhoto=function(a){
 var b=document.getElementById(a.id);
 document.getElementById(this.getContainer().id).firstChild.removeChild(b);
 delete(b);
}

