// TPhoto() GMaps API extension copyright 2005-2006 Tom Mangan
// http://gmaps.tommangan.us/tphoto.html
// free for non-commercial use

function TPhoto(){}

function zoom_to()
{
	this.setPosition(map);
}

function move_end()
{
	this.setPosition(map);
}

TPhoto.prototype.initialize=function(map){
	this.parentMap = map;
	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 = map.getPane(G_MAP_MAP_PANE);
	this.mapTray.appendChild(b);
	this.setPosition(map);
	b.style.display = 'block';
	if (this.percentOpacity) {
		this.setOpacity(this.percentOpacity);
	}
	GEvent.bind(map, "zoomend", this, zoom_to);
	GEvent.bind(map, "moveend", this, move_end);
}

TPhoto.prototype.setPosition=function(a)
{
	var d=this.parentMap.fromLatLngToDivPixel(this.anchorTopLeft);
	var e=this.parentMap.fromLatLngToDivPixel(this.anchorBottomRight);
	var x = document.getElementById(this.id);
	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.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;
	}
}

GMap2.prototype.addTPhoto=function(a){
	a.initialize(this);
}

GMap2.prototype.removeTPhoto=function(a){
	var b = document.getElementById(a.id);
	// this.getPane(G_MAP_MAP_PANE).removeChild(b);
	var garbageBin = document.getElementById('IELeakGarbageBin');
    	if (!garbageBin) {
        	garbageBin = document.createElement('DIV');
        	garbageBin.id = 'IELeakGarbageBin';
        	garbageBin.style.display = 'none';
        	document.body.appendChild(garbageBin);
    	}

    	// move the element to the garbage bin
    	garbageBin.appendChild(b);
    	garbageBin.innerHTML = '';
	GEvent.clearNode(this);
	delete(b);
}


