﻿Type.registerNamespace("TrackMe.Mapping");

TrackMe.Mapping.LMap = function(id, provider, mapType, mapMode, center, zoom, threeDSettings, opts) {
  TrackMe.Mapping.LMap.initializeBase(this, [id, provider, mapType, mapMode, center, zoom]);

  var instance = this;
  //ERO.getInstance().hookEvent('beforehide', a);
  
  // If the browser is Firefox get the version number
  var ffv = 0;
  var ffn = "Firefox/"
  var ffp = navigator.userAgent.indexOf(ffn);
  if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp + ffn.length));
  // If we're using Firefox 1.5 or above override the Virtual Earth drawing functions to use SVG
  if (ffv >= 1.5) {
    Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
  }

  this._map = new VEMap(id);
  this._panelControls = [];
  this.getWrappedMap().sportsDoMap = this;
  var hideDashboard = true;
  if (opts != null && typeof(opts.dashboardSize) !== "undefined") {
    this.setDashboardSize(opts.dashboardSize);
    hideDashboard = false;
  }
  this.getWrappedMap().LoadMap(this.convertLatLngClass(center), zoom, this.convertTypeToStyle(mapType), null, this.convertMode(mapMode));
  
  if (hideDashboard == true) {
    this.hideDashboardPanel();
  }
  
  this._map.AttachEvent("onendpan", function() {
    instance._setBubblePoint(null);
  });
  
  function map_OnChangeView(e) {
    instance.OnChangeView();
  }
  
  this.addShim = function(el) {
    var shim = document.createElement("iframe");
    shim.id = "myShim";
    shim.frameBorder = "0";
    shim.style.position = "absolute";
    shim.style.zIndex = "1";
    shim.style.top  = el.offsetTop;
    shim.style.left = el.offsetLeft;
    shim.width  = el.offsetWidth;
    shim.height = el.offsetHeight;
    el.shimElement = shim;
    el.parentNode.insertBefore(shim, el);
  };
  
  function _MapMouseOver(e) {
    if (e.elementID) {
      var popupShape = instance._map.GetShapeByID(e.elementID)
      if (popupShape && typeof(popupShape.sportsDoPoint) !== "undefined") {
        //popupShape.sportsDoPoint.showBubble();
        return true;
      }
    }
  };
  
  this._justPanned = false;
  
  function _PinClicked(e) {
    if (e.elementID) {
      var shape = instance._map.GetShapeByID(e.elementID)
      
      if (shape) {
        instance._onPointClickDelegate(shape.sportsDoPoint);
        if (typeof(shape.sportsDoPoint) !== "undefined" && shape.sportsDoPoint !== null && typeof(shape.sportsDoPoint.showBubble) !== "undefined") {
          shape.sportsDoPoint.showBubble();
        } else if (shape.Type === "Polyline") {
          var spolyline = shape.sPolyLine;

          onPolyLineClick(this, {"polyline":spolyline, "point": $SLatLng(shape.Latitude, shape.Longitude)});
        }
      }
    } else {
      if (instance._justPanned === false) {
        var args = 
        {
          "point": instance.convertLatLngClass(instance._map.PixelToLatLong(new VEPixel(e.mapX, e.mapY)))
        }
        
        instance._onMapClickDelegate(args);
      }
      this._justPanned = false;
    }
  }
  
  function _MapResize(e) {
    var pnls = instance.getPanelControls();
    var addPnls = [];
    while (pnls.length > 0) {
      var panel = pnls[0];
      instance.removePanelControl(panel.getId());
      Array.add(addPnls, panel);
    }
    for (var i=0; i<addPnls.length; i++) {
      var panel = addPnls[i];
      instance.addPanelControl(panel);
    }
  }
  
  this.isFullyLoaded = false;

  function _MapEndPan(e) {
    instance._justPanned = true;
    
    if (instance.isFullyLoaded === false) {
      instance.isFullyLoaded = true;
      if (typeof(threeDSettings) !== "undefined" && threeDSettings !== null) {
        instance.setAltitude(threeDSettings.altitude);
        instance.setHeading(threeDSettings.heading);
        instance.setPitch(threeDSettings.pitch);
      }
    }
  }
  
  function _MapEndZoom(a) {
    var args = {
      "before": null,
      "now": a.zoomLevel
    }
    instance._onZoomedDelegate(args);
  }
  
  this.MapMouseOverDelegate = Function.createDelegate(this, _MapMouseOver);
  this._map.AttachEvent("onmouseover", this.MapMouseOverDelegate);
  this.PinClickDelegate = Function.createDelegate(this, _PinClicked);
  this._map.AttachEvent("onclick", this.PinClickDelegate);
  this.MapResizeDelegate = Function.createDelegate(this, _MapResize);
  this._map.AttachEvent("onresize", this.MapResizeDelegate);
  this.MapEndPanDelegate = Function.createDelegate(this, _MapEndPan);
  this._map.AttachEvent("onendpan", this.MapEndPanDelegate);
  this.MapEndZoomDelegate = Function.createDelegate(this, _MapEndZoom);
  this._map.AttachEvent("onendzoom", _MapEndZoom);
  
  this._map.AttachEvent("onchangeview", map_OnChangeView);
  
  this.hideDashboardPanel();
  this.setMapType(mapType);
};

TrackMe.Mapping.LMap.prototype = {
  convertIconClass: function(icon) {
    if (icon != null) {
      if (icon.getType && icon.getType() == TrackMe.Mapping.SIcon.getName()) {
        var liveIcon = new VEShape(VEShapeType.Pushpin, new VELatLong(0, 0));
        var iconSpec = new VECustomIconSpecification();
        iconSpec.Image = icon.getImageUrl();
        liveIcon.SetCustomIcon(iconSpec);
        liveIcon.SetTitle("");
        liveIcon.SetDescription("");
        return liveIcon;
      } else {
        var iconSpec = icon.GetCustomIcon();
        var sIcon = new TrackMe.Mapping.SIcon();
        sIcon.setImageUrl(iconSpec.Image);
        return sIcon;
      }
    } else {
      return new VEShape(VEShapeType.Pushpin, new VELatLong(0, 0));
    }
  },

  convertLatLngClass: function(latlng) {
    if (latlng.getType && (latlng.getType() == TrackMe.Mapping.SLatLng.getName() || latlng.getType() == TrackMe.Mapping.SDetailLatLng.getName())) {
      return new VELatLong(latlng.getLatitude(), latlng.getLongitude());
    } else {
      return new TrackMe.Mapping.SLatLng(latlng.Latitude, latlng.Longitude);
    }
  },
  
  convertSizeClass: function(size) {},

  convertPixelClass: function(pixel) {
    if (pixel != null) {
      if (pixel.getType && pixel.getType() == TrackMe.Mapping.SPixel.getName()) {
        return new VEPixel(pixel.getX(), pixel.getY());
      } else {
        return new TrackMe.Mapping.SPixel(pixel.x, pixel.y);
      }
    }
  },
  
  convertMode: function(mode) {
    var lMapMode;
    
    if (mode == '3D') {
      lMapMode = VEMapMode.Mode3D;
    } else {
      lMapMode = VEMapMode.Mode2D;
    }
    
    return lMapMode;
  },

  convertTypeToStyle: function(mapType) {
    var lMapType;
    
    if (mapType == 'Normal') {
      lMapType = VEMapStyle.Road;
    } else if (mapType =='Satellite') {
      lMapType = VEMapStyle.Aerial;
    } else if (mapType == 'Hybrid') {
      lMapType = VEMapStyle.Hybrid;
    } else if (mapType == 'Shaded') {
      lMapType = VEMapStyle.Shaded;
    } else {
      lMapType = VEMapStyle.Road;
    }
    
    return lMapType;
  },
  
  convertStyleToType: function(lMapType) {
    var mapType;
    
    if (lMapType == VEMapStyle.Road) {
      mapType = 'Normal';
    } else if (lMapType == VEMapStyle.Aerial) {
      mapType = 'Satellite';
    } else if (lMapType == VEMapStyle.Hybrid) {
      mapType = 'Hybrid';
    } else if (lMapType == VEMapStyle.Shaded) {
      mapType = 'Shaded';
    } else {
      mapType = 'Normal';
    }
    
    return mapType;
  },
  
  totalDistance: function(latlngs) {
    var prevLatLng = null, totalDistance = 0;

    for (var i=0; i<latlngs.length; i++) {
      var latlng = latlngs[i];
      
      if (prevLatLng != null) {
        totalDistance += latlng.distanceFrom(prevLatLng);
      }
      prevLatLng = latlng;
    }
    
    return totalDistance;
  },
  
  getMapType: function() {
    return this.convertStyleToType(this.getWrappedMap().GetMapStyle());
  },
  setMapType: function(mapType) {
    this.getWrappedMap().SetMapStyle(this.convertTypeToStyle(mapType));
  },
  
  getMapMode: function() {
    if (this.getWrappedMap().GetMapMode() == VEMapMode.Mode3D) {
      return '3D';
    } else {
      return '2D';
    }
  },
  setMapMode: function(mode) {
    if (mode === "3D") {
      this.getWrappedMap().SetMapMode(VEMapMode.Mode3D);
    } else {
      this.getWrappedMap().SetMapMode(VEMapMode.Mode2D);
    }
  },
  
  setZoom: function(zoom) {
    this.getWrappedMap().SetZoomLevel(zoom);
  },
  
  getMapCenter: function() {
    return this.convertLatLngClass(this.getWrappedMap().GetCenter());
  },
  setMapCenter: function(latlng, zoom) {
    if (zoom == null) {
      zoom = this.getWrappedMap().GetZoomLevel();
    }
    this.getWrappedMap().SetCenterAndZoom(this.convertLatLngClass(latlng), zoom);
  },
  
  findAddress: function(address, callback) {
    var instance = this;
    this._map.Find(null, address, null, null, null, null, null, false, false, false,
      function(a, b, c, d, e) {
        var results = [];
        
        if (c != null && c.length > 1) {
          for (x=0; x<c.length; x++) {
            var r = { "name": c[x].Name, "latlng": instance.convertLatLngClass(c[x].LatLong) };
            Array.add(results, r);
          }
        } else if (c != null) {
          var r = {"name": c[0].Name, "latlng": instance.convertLatLngClass(c[0].LatLong) }
          Array.add(results, r);
        }
        
        if (typeof(callback) !== "undefined" && callback !== null) {
          callback.call(instance, results);
        }
      });
  },

  moveToLatLng: function(latlng) {
    this.getWrappedMap().PanToLatLong(this.convertLatLngClass(latlng));
  },

  resizeMap: function(width, height) {
    if (width == null && height == null) {
      this.getWrappedMap().Resize();
    } else {
      this.getWrappedMap().Resize(width, height);
    }
  },
  getMapSize: function() {
    return new TrackMe.Mapping.SSize(this.getWrappedMap().GetWidth(), this.getWrappedMap().GetHeight());
  },
  
  getViewRegion: function() {
    var map = this.getWrappedMap();
    var v;
    if (map.GetMapStyle() === VEMapStyle.Birdseye){
        var be = map.GetBirdseyeScene();
        v = be.GetBoundingRectangle();
    } else {
        v = map.GetMapView();
    }

    var a = 
    {
      topLeft: this.convertLatLngClass(v.TopLeftLatLong),
      bottomRight: this.convertLatLngClass(v.BottomRightLatLong)
    };
    
    return a;
  },
  
  setAltitude: function(altitude) {
    if (typeof(altitude) !== "undefined" && altitude !== null) {
      this.getWrappedMap().SetAltitude(altitude);
    }
  },
  setPitch: function(pitch) {
    if (typeof(pitch) !== "undefined" && pitch !== null) {
      this.getWrappedMap().SetPitch(pitch);
    }
  },
  setHeading: function(heading) {
    if (typeof(heading) !== "undefined" && heading !== null) {
      this.getWrappedMap().SetHeading(heading);
    }
  },
  getAltitude: function() {
    return this.getWrappedMap().GetAltitude();
  },
  getPitch: function() {
    return this.getWrappedMap().GetPitch();
  },
  getHeading: function() {
    return this.getWrappedMap().GetHeading();
  },
  
  setMapView: function(latlng, altitude, pitch, heading) {
    if (this.getMapMode() === '2D') {
        this.setMapCenter(latlng);
    } else {
        var viewspec = new VEMapViewSpecification(this.convertLatLngClass(latlng), null, altitude, pitch, heading);
        this.getWrappedMap().SetMapView(viewspec);
    }
  },
  
  autoZoom: function(topRight, bottomLeft) {
    TrackMe.Mapping.LMap.callBaseMethod(this, 'autoZoom', [topRight, bottomLeft]);

    if (topRight.getLatitude() != null && topRight.getLongitude() != null && bottomLeft.getLatitude() != null && bottomLeft.getLongitude() != null) {
      var a = this.convertLatLngClass(bottomLeft);
      var b = this.convertLatLngClass(topRight);
    
      var locs = [];
      Array.add(locs, a);
      Array.add(locs, b);
    
      this.getWrappedMap().SetMapView(locs);
    }
  },
  
  getCurrentZoom: function() {
    return this.getWrappedMap().GetZoomLevel();
  },
  
  addPolyLine: function(polyline) {
    var allowAdd = TrackMe.Mapping.LMap.callBaseMethod(this, 'addPolyLine', [polyline]);
    if (allowAdd == true) {
      var index = 0;
      var lpoints = [];
      while (index < polyline.getLatLngs().length) {
        var latlng = this.convertLatLngClass(polyline.getLatLngs()[index]);
        Array.add(lpoints, latlng);
        index++;
      };
      
      var rgb = TrackMe.colorHex2Decimal(polyline.getColor());
      var vecolor = new VEColor(rgb[0], rgb[1], rgb[2], 0.8);
      if (lpoints.length == 1) {
        Array.add(lpoints, lpoints[0].Clone());
      }
      var vpolyline = new VEShape(VEShapeType.Polyline, lpoints);
      vpolyline.SetLineWidth(polyline.getWidth());
      vpolyline.SetLineColor(vecolor);
      vpolyline.SetIconVisibility(false);
      polyline.setWrappedPolyLine(vpolyline);
      vpolyline.sPolyLine = polyline;
      this.getWrappedMap().AddShape(vpolyline);
    }
  },
  
  bulkAddShapes: function(shapes) {
    try {
        this.getWrappedMap().AddShape(shapes);
    } catch(e) {
      var map = this.getWrappedMap();
      for (var i=0; i<shapes.length; i++) {
        map.AddShape(shapes[i]);
      }
    }
  },
  removePolyLine: function(polyline) {
    var shape = polyline.getWrappedPolyLine();
    this.getWrappedMap().DeleteShape(shape);
    polyline.setWrappedPolyLine(null);
    TrackMe.Mapping.LMap.callBaseMethod(this, 'removePolyLine', [polyline]);
  },
  
  addPoint: function(point, opts) {
    var allowAdd = TrackMe.Mapping.LMap.callBaseMethod(this, 'addPoint', [point]);
    if (allowAdd == true) {
      var latlng = this.convertLatLngClass(point.getLatLng());
      var pushpin = this.convertIconClass(point.getIcon());
      pushpin.SetPoints(latlng);
    
      if (point.getType() === TrackMe.Mapping.SPoint.getName()) {
        //VEPushpin.ShowDetailOnMouseOver = false;
      } else if (point.getType() === TrackMe.Mapping.SDetailPoint.getName()) {
        pushpin.SetTitle(point.getTitle());
        pushpin.SetDescription(point.getDetails());
      }
    
      pushpin.sportsDoPoint = point;
      point.setWrappedPoint(pushpin);
      if (typeof(opts) === "undefined" || opts.supressAdd === false) {
        this.getWrappedMap().AddShape(pushpin);
      } else if (typeof(opts) !== "undefined") {
        opts.shape = pushpin;
      }
      var args = { "point": point };
      this._onPointAddDelegate(args);
    }
    return allowAdd;
  },
  removePoint: function(point) {
    this.getWrappedMap().DeleteShape(point.getWrappedPoint());
    TrackMe.Mapping.LMap.callBaseMethod(this, 'removePoint', [point]);
  },
  movePoint: function(point) {
    if (point != null) {
      var v = this.getViewRegion();
      if (this.isInRegion(v.topLeft, v.bottomRight, point.getLatLng())) {
        var marker = point.getWrappedPoint();
    
        if (point.isVisible()) {
          if (marker != null) {
            var llatlng = this.convertLatLngClass(point.getLatLng());
            marker.SetPoints(llatlng);
          }
        } else {
          point.show();
        }
      } else {
        point.hide();
      }
    }
    TrackMe.Mapping.LMap.callBaseMethod(this, 'movePoint', [point]);
  },
  hidePoint: function(point) {
    if (point.isVisible() === true) {
      var wpoint = point.getWrappedPoint();
      try {
        //this.getWrappedMap().DeleteShape(wpoint);
        wpoint.Hide();
      } catch(err) {
        debugger;
      }
    }
  },
  showPoint: function(point) {
    var wpoint = point.getWrappedPoint();
    if (wpoint != null) {
      wpoint.Show();
    }
  },
  showBubble: function(point) {
    if (this.isBubbleEnabled() == true && point.getType() === TrackMe.Mapping.SDetailPoint.getName()) {
      var b = this.getBubblePoint();
      if (b != null) {
        b.getWrappedPoint().SetZIndex(10000, null);
      }
      TrackMe.Mapping.LMap.callBaseMethod(this, 'showBubble', [point]);

      var args = {
        "point": point,
        "htmlContent": point.getDetails(),
        "showMapTab": true,
        "showBubble": true
      };
      this._prePointBubbleShowDelegate(args);
      
      if (args.showBubble == true) {
        if (args.htmlContent != null) {
          //if (args.showMapTab === true) {
            // TODO: simulate tab
            //this._showTabbedBubble(point, new GInfoWindowTab(point.getId(), args.htmlContent));
          //} else {
            var marker = point.getWrappedPoint();
            marker.SetZIndex(10001, null);
            marker.SetDescription(args.htmlContent);
            this.getWrappedMap().HideInfoBox();
            this.getWrappedMap().ShowInfoBox(marker);
          //}
        } else {
          //this._showTabbedBubble(point, null, point.getTitle());
        }
      }
    }
  },
  hideBubble: function(point) {
    TrackMe.Mapping.LMap.callBaseMethod(this, 'hideBubble', [point]);
    point.getWrappedPoint().SetZIndex(10000, null);
    this.getWrappedMap().HideInfoBox();
  },
  
  addPhoto: function(photo) {
    var allowAdd = TrackMe.Mapping.LMap.callBaseMethod(this, 'addPhoto', [photo]);
    if (allowAdd == true) {
      var latlng = this.convertLatLngClass(photo.getLatLng());
      var pushpin = this.convertIconClass(photo.getIcon());
      pushpin.SetPoints(latlng);
      pushpin.sportsDoPoint = photo;
      photo.setWrappedPoint(pushpin);
      this.getWrappedMap().AddShape(pushpin);
    }
  },
  removePhoto: function(photo) {
    var wpoint = photo.getWrappedPoint();
    this.getWrappedMap().DeleteShape(wpoint);
    TrackMe.Mapping.LMap.callBaseMethod(this, 'removePhoto', [photo]);
  },
  hidePhoto: function(photo) {
    //TrackMe.Mapping.LMap.callBaseMethod(this, 'hidePhoto', [photo]);
    this.hidePoint(photo);
  },
  showPhoto: function(photo) {
    //TrackMe.Mapping.LMap.callBaseMethod(this, 'showPhoto', [photo]);
    this.showPoint(photo);
  },
  showPhotoBubble: function(photo) {
    if (this.isBubbleEnabled() == true) {
      var b = this.getBubblePoint();
      if (b != null) {
        b.getWrappedPoint().SetZIndex(10000, null);
      }
      TrackMe.Mapping.LMap.callBaseMethod(this, 'showPhotoBubble', [photo]);
      this.generatePhotoBubbleHtml = function(photo) {
        return "<p><b>" + photo.getTitle() + "</b><p><div style='width: 100px; height: 100px'>" + "<a target=\"_blank\" href=\"/photo.ashx?id=" + photo.getId() + "\"><img src=\"/photo.ashx?id=" + photo.getId() + "&thumbnail=true\"></a></div>";
      }

      var html = this.generatePhotoBubbleHtml(photo);
      var marker = point.getWrappedPoint();
      marker.SetZIndex(10001, null);
      marker.SetDescription(html);
      this.getWrappedMap().ShowInfoBox(marker);
      //this._showTabbedBubble(photo, new GInfoWindowTab("Photo", html));
    }
  },
  
  addDoer: function(doer) {
    var allowAdd = TrackMe.Mapping.LMap.callBaseMethod(this, 'addDoer', [doer]);
    if (allowAdd == true) {
      var latlng = this.convertLatLngClass(doer.getLatLng());
      var pushpin = this.convertIconClass(doer.getIcon());
      
      var iconSpec = new VECustomIconSpecification();
      iconSpec.CustomHTML = "<div style='position: absolute; top: -20px;'>" +
               "<div style='color:Black; background-color:#147ad1;'>" +
               "<img style='padding: 1px;' src='api/v1/images/profileImage.ashx?user=" + doer.getId() + "&size=20x20'/></div>" +
               "<div style='width: 22px; text-align: center;'><img src='ui/images/common/down-arrow-small.gif'/></div></div>";
      iconSpec.Image = doer.getIcon().getImageUrl();
      iconSpec.ImageOffset = new VEPixel(0, 0);
      pushpin.SetCustomIcon(iconSpec);
      pushpin.SetPoints(latlng);
      pushpin.sportsDoPoint = doer;
      
      doer.setWrappedPoint(pushpin);
      this.getWrappedMap().AddShape(pushpin);
    }
    return allowAdd;
  },
  removeDoer: function(doer) {
    if (typeof(doer) !== "undefined" && doer !== null) {
      var wpoint = doer.getWrappedPoint();
      this.getWrappedMap().DeleteShape(wpoint);
      TrackMe.Mapping.LMap.callBaseMethod(this, 'removeDoer', [doer]);
    }
  },
  hideDoer: function(doer) {
    //TrackMe.Mapping.LMap.callBaseMethod(this, 'hideDoer', [doer]);
    this.hidePoint(doer);
  },
  showDoer: function(doer) {
    //TrackMe.Mapping.LMap.callBaseMethod(this, 'showDoer', [doer]);
    this.showPoint(doer);
  },
  showDoerBubble: function(doer) {
    if (this.isBubbleEnabled() == true) {
      var b = this.getBubblePoint();
      if (b != null) {
        b.getWrappedPoint().SetZIndex(10000, null);
      }
      
      TrackMe.Mapping.LMap.callBaseMethod(this, 'showDoerBubble', [doer]);
      this.generateDoerBubbleHtml = function(nickname, details) {
      // disgusting hack - jv
        if(nickname.indexOf("___") != -1)
        {
            nickname = nickname.substring(0, nickname.indexOf("___"));
        }

        return "<table><tr><td width='100px'><img src=\"" + TrackMe.URL + "api/v1/images/profileImage.ashx?user=" + nickname + "\"></td>" +
          "<tr><td><a href=\"http://trackme.com/" + nickname + "\" target=\"_blank\">((" + nickname + "))</a></td></tr>" + 
          "<tr><td>" + details + "</td></tr></table>";
      }

      var args = {
        doer: doer,
        htmlContent: this.generateDoerBubbleHtml(doer.getId(), (doer.ext.details ?  doer.ext.details : "")),
        showMapTab: true
      };
      
      this._preDoerBubbleShowDelegate(args);
      
      if (args.htmlContent != null) {
        if (args.showMapTab === true) {
          //this._showTabbedBubble(doer, new GInfoWindowTab("Doer", args.htmlContent));
        } else {
          var marker = doer.getWrappedPoint();
          marker.SetZIndex(10001, null);
          marker.SetDescription(args.htmlContent);
          var map = this.getWrappedMap();
          map.HideInfoBox();
          map.ShowInfoBox(marker);
        }
      }
    }
  },
  
  addPanelControl: function(panel) {
    if (TrackMe.Mapping.LMap.callBaseMethod(this, 'addPanelControl', [panel])) {
      var control = new TrackMe.Mapping.LGenericPanel(this, panel);
      this.getWrappedMap().AddControl(control._el);
      this.addShim(control._el);
    }
  },
  removePanelControl: function(id) {
    var control = document.getElementById("lgenpanel_" + id);
    if (control != null) {
      this.getWrappedMap().DeleteControl(control);
      TrackMe.Mapping.LMap.callBaseMethod(this, 'removePanelControl', [id]);
    }
  },
  
  setDashboardSize: function(size) {
    if (typeof(size) === "undefined" || size === "large") {
      this.getWrappedMap().SetDashboardSize(VEDashboardSize.Normal);
    } else if (size === "small") {
      this.getWrappedMap().SetDashboardSize(VEDashboardSize.Tiny);
    }
  },
  
  showDashboardPanel: function(opts) {
    this.getWrappedMap().ShowDashboard();
  },
  hideDashboardPanel: function() {
    this.getWrappedMap().HideDashboard();
  },
  
  showMapTypePanel: function() {},
  hideMapTypePanel: function() {},
  
  showReplayPanel: function() {},
  hideReplayPanel: function() {},
  
  showOverviewMapPanel: function() {
    this.getWrappedMap().ShowMiniMap();
  },
  hideOverviewMapPanel: function() {
    this.getWrappedMap().HideMiniMap();
  },
  
  showTrackMeLogo: function() {
    var container = document.createElement("div");
    container.style.width = "135px";
    container.style.height = "25px";
    container.style.top = parseInt(this.getMapSize().getHeight()) - 70 + "px";
    container.style.left = "10px";
    container.innerHTML = "<a href=\"http://www.sportsdo.net/\" target=\"_blank\"><img border=\"0\" src='/ui/logos/sportsdo_logo_tiny.gif' /></a>";
    
    var panel = new TrackMe.Mapping.SPanelControl("sportsdologo", container, "BottomRight", new TrackMe.Mapping.SPixel(20, 50));
    this.addPanelControl(panel);
  },
  
  dispose: function() {
    var map = this.getWrappedMap();
    if (map != null) {
      //map.DetachEvent("onmouseover", this.PinHoverDelegate);
      map.Dispose();
    }
    
    this.PinHoverDelegate = null;
    
    TrackMe.Mapping.LMap.callBaseMethod(this, 'dispose');
  },

  getType: function() {
    return TrackMe.Mapping.LMap.getName();
  }
};
TrackMe.Mapping.LMap.inheritsFrom(TrackMe.Mapping.SMap);
TrackMe.Mapping.LMap.registerClass('TrackMe.Mapping.LMap', TrackMe.Mapping.SMap);


TrackMe.Mapping.LGenericPanel = function(map, panel) {
  this._el = document.createElement("div");
  this._el.setAttribute("id", "lgenpanel_" + panel.getId());
  this._el.appendChild(panel.getDivObject());
  this._map = map;
  this._panel = panel;
  //this._panel.LGenericPanel = this;
  
  this.relocate();
};
TrackMe.Mapping.LGenericPanel.prototype = {
  relocate: function() {
    var size = this._map.getMapSize();
    var height = size.getHeight();
    var width = size.getWidth();
    var location = this._panel.getLocation();
    var offset = this._panel.getOffset();
    var div = this._panel.getDivObject();
    
    //this._el.style.offsetWidth = div.style.width;
    //this._el.style.offsetHeight = div.style.height;
    
    switch (location) {
      case "TopRight":
        this._el.style.top = offset.getY() + "px";
        this._el.style.left = parseInt(width) - parseInt(div.style.width) - offset.getX() - 10 + "px";
        break;
      case "TopLeft":
        this._el.style.top = offset.getY() + "px";
        this._el.style.left = offset.getX() + "px";
        break;
      case "BottomRight":
        this._el.style.top = parseInt(height) - parseInt(div.style.height) - offset.getY() + "px";
        this._el.style.left = parseInt(width) - parseInt(div.style.width) - offset.getX() - 10 + "px";
        break;
      case "BottomLeft":
        this._el.style.top = parseInt(height) - parseInt(div.style.height) - offset.getY() + "px";
        this._el.style.left = offset.getX() + "px";
        break;
      default:
        this._el.style.top = offset.getY() + "px";
        this._el.style.left = offset.getX() + "px";
    }
  }
};


// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') {
  Sys.Application.notifyScriptLoaded();
}