// Create an overlay on the map from a projected image...
// Author. John D. Coryat 01/2008
// USNaviguide LLC - http://www.usnaviguide.com
// Thanks go to Mile Williams EInsert: http://econym.googlepages.com/einsert.js, Google's GOverlay Example and Bratliff's suggestion...
// Opacity code from TPhoto: http://gmaps.tommangan.us/addtphoto.html
// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// Parameters: 
//    imageUrl: URL of the image
//    bounds: Bounds object of image destination
//    addZoom: Added Zoom factor as a parameter to the imageUrl (include complete parameter, including separater like '?zoom='
//
	
function ProjectedOverlay(imageUrl, bounds, opacity)
{
 this.url_ = imageUrl ;
 this.bounds_ = bounds ;
 this.opacity_ = opacity;
 this.id = imageUrl ;				// Added to allow for multiple images
}
ProjectedOverlay.prototype = new GOverlay();

ProjectedOverlay.prototype.initialize = function(map)
{
 var div = document.createElement("div") ;
 div.style.position = "absolute" ;
 div.setAttribute('id',this.id) ;
 map.getPane(G_MAP_MAP_PANE).appendChild(div) ;
 this.map_ = map ;
 this.div_ = div ;
}

// Remove the main DIV from the map pane

ProjectedOverlay.prototype.remove = function()
{
 this.div_.parentNode.removeChild(this.div_);
 delete(this.map) ;
 delete(this.div) ;
}

// Copy our data to a new ProjectedOverlay...

ProjectedOverlay.prototype.copy = function()
{
 return new ProjectedOverlay(this.url_, this.bounds_, this.Opacity_);
}

// Redraw based on the current projection and zoom level...

ProjectedOverlay.prototype.redraw = function(force)
{
     // We only need to redraw if the coordinate system has changed
     if (!force)
     {
      return ;
     }

     var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
     var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());

     // Now position our DIV based on the DIV coordinates of our bounds

     this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
     this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
     this.div_.style.left = Math.min(c2.x, c1.x) + "px";
     this.div_.style.top = Math.min(c2.y, c1.y) + "px";
     
     this.div_.innerHTML = '<div style=" filter:alpha(opacity:60); MozOpacity: 0.6; opacity:0.6"><img src="' + this.url_ + '"  width=' + this.div_.style.width + ' height=' + this.div_.style.height + ' ></div>' ;
}

ProjectedOverlay.prototype.show=function()
{
 var d = document.getElementById( this.id ) ;
 d.style.display = 'block';
}

ProjectedOverlay.prototype.hide=function()
{
 var d = document.getElementById( this.id ) ;
 d.style.display = 'none';
}


