// Version 0.2      the .copy() parameters were wrong
// version 1.0      added .show() .hide() .setContents() .setPoint() .setOpacity() .overlap
// version 1.1      Works with GMarkerManager in v2.67, v2.68, v2.69, v2.70 and v2.71
// version 1.2      Works with GMarkerManager in v2.72, v2.73, v2.74 and v2.75
// version 1.3      add .isHidden()
// version 1.4      permit .hide and .show to be used before addOverlay()
// version 1.5      fix positioning bug while label is hidden
// version 1.6      added .supportsHide()
// version 1.7      fix .supportsHide()


      function ELabel(point, html, classname, pixelOffset, percentOpacity, overlap) {
        // Mandatory parameters
        this.point = point;
        this.html = html;
        
        // Optional parameters
        this.classname = classname||"";
        this.pixelOffset = pixelOffset||new GSize(0,0);
        if (percentOpacity) {
          if(percentOpacity<0){percentOpacity=0;}
          if(percentOpacity>100){percentOpacity=100;}
        }        
        this.percentOpacity = percentOpacity;
        this.overlap=overlap||false;
        this.hidden = false;
      } 
      
      ELabel.prototype = new GOverlay();

      ELabel.prototype.initialize = function(map) {
        var div = document.createElement("div");
        div.style.position = "absolute";
        div.innerHTML = '<div class="' + this.classname + '">' + this.html + '</div>' ;
        map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div);
        this.map_ = map;
        this.div_ = div;
        if (this.percentOpacity) {        
          if(typeof(div.style.filter)=='string'){div.style.filter='alpha(opacity:'+this.percentOpacity+')';}
          if(typeof(div.style.KHTMLOpacity)=='string'){div.style.KHTMLOpacity=this.percentOpacity/100;}
          if(typeof(div.style.MozOpacity)=='string'){div.style.MozOpacity=this.percentOpacity/100;}
          if(typeof(div.style.opacity)=='string'){div.style.opacity=this.percentOpacity/100;}
        }
        if (this.overlap) {
          var z = GOverlay.getZIndex(this.point.lat());
          this.div_.style.zIndex = z;
        }
        if (this.hidden) {
          this.hide();
        }
      }

      ELabel.prototype.remove = function() {
        this.div_.parentNode.removeChild(this.div_);
      }

      ELabel.prototype.copy = function() {
        return new ELabel(this.point, this.html, this.classname, this.pixelOffset, this.percentOpacity, this.overlap);
      }

      ELabel.prototype.redraw = function(force) {
        var p = this.map_.fromLatLngToDivPixel(this.point);
        var h = parseInt(this.div_.clientHeight);
        this.div_.style.left = (p.x + this.pixelOffset.width) + "px";
        this.div_.style.top = (p.y +this.pixelOffset.height - h) + "px";
      }

      ELabel.prototype.show = function() {
        if (this.div_) {
          this.div_.style.display="";
          this.redraw();
        }
        this.hidden = false;
      }
      
      ELabel.prototype.hide = function() {
        if (this.div_) {
          this.div_.style.display="none";
        }
        this.hidden = true;
      }
      
      ELabel.prototype.isHidden = function() {
        return this.hidden;
      }
      
      ELabel.prototype.supportsHide = function() {
        return true;
      }

      ELabel.prototype.setContents = function(html) {
        this.html = html;
        this.div_.innerHTML = '<div id="' + this.classname + '">' + this.html + '</div>' ;
        this.redraw(true);
      }
      
      ELabel.prototype.setPoint = function(point) {
        this.point = point;
        if (this.overlap) {
          var z = GOverlay.getZIndex(this.point.lat());
          this.div_.style.zIndex = z;
        }
        this.redraw(true);
      }
      
      ELabel.prototype.setOpacity = function(percentOpacity) {
        if (percentOpacity) {
          if(percentOpacity<0){percentOpacity=0;}
          if(percentOpacity>100){percentOpacity=100;}
        }        
        this.percentOpacity = percentOpacity;
        if (this.percentOpacity) {        
          if(typeof(this.div_.style.filter)=='string'){this.div_.style.filter='alpha(opacity:'+this.percentOpacity+')';}
          if(typeof(this.div_.style.KHTMLOpacity)=='string'){this.div_.style.KHTMLOpacity=this.percentOpacity/100;}
          if(typeof(this.div_.style.MozOpacity)=='string'){this.div_.style.MozOpacity=this.percentOpacity/100;}
          if(typeof(this.div_.style.opacity)=='string'){this.div_.style.opacity=this.percentOpacity/100;}
        }
      }

      ELabel.prototype.getPoint = function() {
        return this.point;
      }
      ELabel.prototype.U = function() {
        return this.point;
      }
      ELabel.prototype.V = function() {
        return this.point;
      }
      ELabel.prototype.W = function() {
        return this.point;
      }
      ELabel.prototype.X = function() {
        return this.point;
      }
      ELabel.prototype.Y = function() {
        return this.point;
      }
      ELabel.prototype.Z = function() {
        return this.point;
      }

function genMap(lat, lon, name) 
{
    if (GBrowserIsCompatible()) 
    {
        var map = new GMap2(document.getElementById('T17Map'));
        var point = new GLatLng(lat,lon);
        var icon = new GIcon();
        
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(point, 13);

        var label = new ELabel(point,"<div id=\"T17MapText\">" + name + "</div>",null,new GSize(-38,-75));
        //BMW Icon
        icon.image = '/revision(a0e09f11-5e2c-4930-9261-7bf25724a3ae).arox';
        icon.iconAnchor = new GPoint(40, 83);
        icon.infoWindowAnchor = new GPoint(5,1);
        icon.iconSize=new GSize(81,55);

        var marker = new GMarker(point,icon);

        //Overlay objects
        map.addOverlay(marker);        
        map.addOverlay(label);
    }
}

function genMap(lat, lon, name, elementName)
{
    if (GBrowserIsCompatible())
    {

        var map = new GMap2(document.getElementById(elementName));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());

        var point = new GLatLng(lat, lon);
        var icon = new GIcon();
        map.setCenter(point, 15);
        var label = new ELabel(point, "<div class=\"maplabel\">" + name + "</div>", null, new GSize(-30, -48));
        //BMW Icon
        icon.image = 'https://cache.bmwusa.com/image_f3712ad7-fddb-48ce-940a-a8a12899ffeb.arox';
        icon.iconAnchor = new GPoint(30, 50);
        icon.iconSize = new GSize(65, 49);

        var marker = new GMarker(point);
        var marker1 = new GMarker(point, icon);
        //Overlay objects
        map.addOverlay(marker1);
        //map.addOverlay(marker);
        map.addOverlay(label);

    }
}

//lat - latitude
//long - longitude
//name = Display name
//elementName - Container to put map into
function GenFlatMap(lat, lon, name, elementName)
{
    if (GBrowserIsCompatible())
    {
        var map = new GMap2(document.getElementById(elementName));
        var point = new GLatLng(lat, lon);
        var icon = new GIcon();

        map.setCenter(point, 15);
        map.disableDragging();

        var label = new ELabel(point, "<div class=\"maplabel\">" + name + "</div>", null, new GSize(-30, -48));

        //BMW Icon
        icon.image = 'https://cache.bmwusa.com/image_f3712ad7-fddb-48ce-940a-a8a12899ffeb.arox';
        icon.iconAnchor = new GPoint(30, 50);
        icon.iconSize = new GSize(65, 49);

        var marker = new GMarker(point);
        var marker1 = new GMarker(point, icon);

        //Overlay objects
        map.addOverlay(marker1);

        //map.addOverlay(marker);
        map.addOverlay(label);
    }
}



//lat - latitude
//long - longitude
//name = Display name
//elementName - Container to put map into
function genStaticMap(lat, lon, name, elementName) 
{
    if (GBrowserIsCompatible()) 
    {
        var map = new GMap2(document.getElementById(elementName));
        var point = new GLatLng(lat+.005,lon);
        var icon = new GIcon();
        
        map.setCenter(point, 13);
        map.disableDragging();

        var label = new ELabel(point,"<div id=\"AccountOverviewMapText\">" + name + "</div>",null,new GSize(-25,-35));
        //BMW Icon
        icon.image = 'https://cache.bmwusa.com/image_c3769ad8-5df3-4096-9cd4-1e5cedaf205b.arox';
        icon.iconAnchor = new GPoint(25, 38);
        icon.infoWindowAnchor = new GPoint(5,1);
        icon.iconSize=new GSize(43,32);

        var marker = new GMarker(point,icon);

        //Overlay objects
        map.addOverlay(marker);        
        map.addOverlay(label);
    }
}
