//================================================================================
// MyMap - LGPL Copyright (c) 2006 Lionel Laské
//
// This file is part of MyMap.
//
// MyMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// MyMap 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with MyMap; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
//================================================================================

var map = null;
var geo = null;

var MYMODE_MAP = G_NORMAL_MAP;
var MYMODE_SATELLITE = G_SATELLITE_MAP;
var MYMODE_MIXTE = G_HYBRID_MAP;

var MYMARKER_TYPE1 = null;
var MYMARKER_TYPE2 = null;

function MyMapInitialize(mapname, lat, lng, zoom, mode) {

  //if (GBrowserIsCompatible()) {
  
    map = new GMap2(document.getElementById(mapname));
    map.setCenter(new GLatLng(lat, lng), zoom, mode);
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());

    geo = new GClientGeocoder();

    var baseIcon = new GIcon();
    baseIcon.shadow = "";
    baseIcon.iconSize = new GSize(8,8);
    baseIcon.iconAnchor = new GPoint(4,4);
    baseIcon.infoWindowAnchor = new GPoint(7,1);
    MYMARKER_TYPE0 = new GIcon(baseIcon);
    MYMARKER_TYPE0.image = "http://www.lsgskychefs.com/fileadmin/templates/lsgskychefs/plugin/aoe_maps/jointventures.gif";
    MYMARKER_TYPE1 = new GIcon(baseIcon);
    MYMARKER_TYPE1.image = "http://www.lsgskychefs.com/fileadmin/templates/lsgskychefs/plugin/aoe_maps/wholly_owned.gif";
    MYMARKER_TYPE2 = new GIcon(baseIcon);
    MYMARKER_TYPE2.image = "http://www.lsgskychefs.com/fileadmin/templates/lsgskychefs/plugin/aoe_maps/strategicpartner.gif";
  //}
}

function MyMapTerminate() {
  GUnload();
}

function MyMapAddMarker(lat, lng, markertype, info)
{  
  var newmarker = new GMarker(new GLatLng(lat, lng), markertype);
  GEvent.addListener(newmarker, "click", function() {
  
    //newmarker.openInfoWindowHtml(info);
    newmarker.openExtInfoWindow(map, "ballon", info, {paddingX:60});
  });
  map.addOverlay(newmarker);
  
  newmarker.openExtInfoWindow(map, "ballon", info, {paddingX:60});
  return newmarker;
  
}

function MyMapRemoveMarker(marker)
{
  map.removeOverlay(marker);
}

function MyMapGoto(lat, lng) {
   map.panTo(new GLatLng(lat, lng));
}

function MyMapSetZoom(zoom) {
   map.setZoom(zoom);
}

function MyMapPoint() {
   this.lat = 0;
   this.lng = 0;
}

function MyMapGeocode(address, callback) {
   geo.getLatLng(address, function(point) {
       if (!point) 
           callback(null);
       else {
           res = new MyMapPoint();
           res.lat = point.lat();
           res.lng = point.lng();
           callback(res);
       }
   });
}
