// BAVImage() GMaps API extension copyright 2006 Boris Vikhanskiy
// http://gmaps.tommangan.us/tphoto.html
function BAVImage(){}
BAVImage.prototype.initialize=function(a){
 this.parentMap=a;
 var d=this.parentMap.fromLatLngToDivPixel(this.anchorTopLeft);
 var e;
 var myIcon = new GIcon(); //(G_DEFAULT_ICON, this.src); 
 if (this.anchorBottomRight)
 {
    e=this.parentMap.fromLatLngToDivPixel(this.anchorBottomRight);
    this.width=e.x-d.x;
    this.height=e.y-d.y;
 }
 else
 {
    var z=this.parentMap.getZoom();
    var k=1;
    if (z<19)
        k=Math.pow(2,(18-z));
    this.width=this.width/k;
    this.height=this.height/k;
    e = new GPoint(d.x+this.width, d.y+this.height);
    this.anchorBottomRight=this.parentMap.fromDivPixelToLatLng(e);
 }
 myIcon.iconSize = new GSize(this.width, this.height);
 myIcon.iconAnchor = new GPoint(0, 0);
 myIcon.image = this.src;
 myIcon.printImage = this.src;
 myIcon.mozPrintImage = this.src;
 myIcon.shadow='';
 myIcon.printShadow='';
 //myIcon.imageMap=[]; 
 myIcon.maxHeight = 0; 
 var bDraggable = false;
 if (this.draggable)
    bDraggable=true;
// var bClickable = false;
// if (this.clickable)
//    bClickable=true;
 var pt = this.anchorTopLeft;  
 this.marker = new GMarker(pt, {icon: myIcon, draggable: bDraggable, clickable: false});     
 this.parentMap.addOverlay(this.marker);
 this.bDisplayed=true;
 GEvent.bind(a,"zoomend",this,function(){this.setPosition(a)});
// if (bClickable)
//      GEvent.addListener(this.marker, "click", function() {
//        highlightStationMarker(this.marker);
//      });

}

BAVImage.prototype.setPosition=function(a){
 var d=this.parentMap.fromLatLngToDivPixel(this.anchorTopLeft);
 var e=this.parentMap.fromLatLngToDivPixel(this.anchorBottomRight);
 if (this.bDisplayed)
 {
    this.parentMap.removeOverlay(this.marker);
    this.bDisplayed=false;
 }
 var myIcon = this.marker.getIcon();
 myIcon.iconSize = new GSize(e.x-d.x, e.y-d.y);
 this.marker.icon = myIcon;
 if (this.parentMap.getZoom() > 15)
 {
    this.parentMap.addOverlay(this.marker);
    this.bDisplayed=true;    
    this.marker.setPoint(this.anchorTopLeft);
 }
}

BAVImage.prototype.setImage=function(sImagePath){
   this.src = sImagePath;
   if (this.marker)
   {
       var oIcon = this.marker.getIcon(); 
       if (oIcon)
       {
           oIcon.image = this.src;
           oIcon.printImage = this.src;
           oIcon.mozPrintImage = this.src;
       }
//       if (GMarker.prototype.hasOwnProperty("setImage"))
//       {
//          //this code is for version 2.75 and heiger
//           this.marker.setImage(this.src);
//       }
//       else
//       {
         if (this.bDisplayed)
         {
            this.parentMap.removeOverlay(this.marker);
            this.parentMap.addOverlay(this.marker);
         }
//       }
       if (this.bDisplayed)
       {
          this.marker.redraw(true);
       }
   }
}

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

GMap2.prototype.removeBAVImage=function(a){
 if (this.bDisplayed)
 {
    this.parentMap.removeOverlay(this.marker);
    this.bDisplayed=false;
 }
 delete(this.marker);
}

