//================================================================================
// 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 overlayControl = 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;

var letter = null;

var LetterMarkers = new Array();


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());

    // add thumbnail for the map
    overlayControl = new GOverviewMapControl();
    map.addControl(overlayControl);

    geo = new GClientGeocoder();

    var baseIcon = new GIcon();
    baseIcon.shadow = "http://www.google.com/intl/en_us/mapfiles/arrowshadow.png";
    baseIcon.iconSize = new GSize(26, 26);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);
    baseIcon.infoShadowAnchor = new GPoint(18, 25);
    MYMARKER_TYPE1 = new GIcon(baseIcon);
    MYMARKER_TYPE1.image = "http://maps.google.com/mapfiles/marker.png"
    MYMARKER_TYPE2 = new GIcon(baseIcon);
    MYMARKER_TYPE2.image = "http://maps.google.com/mapfiles/arrow.png"
  
	for (i=0; i<26; i++){
		var myIcon = new GIcon(baseIcon);
	  	letter = String.fromCharCode("A".charCodeAt(0) + i);
		var imgSrc = "/assets/images/ima/cus/"+letter+"_ResultTabs.png";
		myIcon.image = imgSrc;
		LetterMarkers[i] = myIcon;
	}
	
 }
}

function MyMapTerminate() {
  GUnload();
}

function MyMapAddMarker(lat, lng, markertype, info)
{
  
  var newmarker = new GMarker(new GLatLng(lat, lng), markertype);
  if (info != null) {
     GEvent.addListener(newmarker, "click", function() {
      MyMapOpenWindow(newmarker,info);
     });
  }
  map.addOverlay(newmarker);
  return newmarker;
}

function MyMapOpenWindow(marker, info)
{
   marker.openInfoWindowHtml(info);
}

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);
       }
   });
}

