/**
 * Zeigt eine einfache Karte mit einer Markierung.
 * Beispiel:
 * mapShow.init(
 *   { divMap: document.getElementById("google_map") },
 *   {
 *     title: "Title der Markierung",
 *     text: "Text im Infofenster der Markierung",
 *     lat: 47.679,
 *     lng: 9.358
 *   }
 * );
 * window.onload = mapShow.start;
 */
var mapShow = {

  // HTML-Elemente
  html: { divMap: null },

  // Position fuer die Markierung
  pos: { title: null, text: null, lat: null, lng: null },

  // Google-Map-Objekte
  map: null,
  marker: null,
  info: null,

  /**
   * Initialisiert die notwendigen Variablen.
   *
   * @param {object} HTML-Elemente
   * @param {object} Position
   */
  init: function(html, pos)
  {
    if(html) mapShow.html = html;
    if(pos) mapShow.pos = pos;
  },

  /**
   * Lädt die Karte mit allen Bedienelementen und
   * registriert die Events.
   */
  start: function()
  {
    var latLng = new google.maps.LatLng(mapShow.pos.lat, mapShow.pos.lng);
    var mapOptions = {
      zoom: 13,
      center: latLng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      disableDefaultUI: true,
      mapTypeControl: true,
      mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
        mapTypeIds: [
          google.maps.MapTypeId.ROADMAP,
          google.maps.MapTypeId.SATELLITE,
          google.maps.MapTypeId.HYBRID
        ]
      },
      scaleControl: true
    }

    mapShow.map = new google.maps.Map(mapShow.html.divMap, mapOptions);
    mapShow.map.controls[google.maps.ControlPosition.TOP_LEFT].push(new mapUtils.navControl(mapShow.map));
    mapShow.marker = new google.maps.Marker();
    mapShow.marker.setPosition(latLng);
    mapShow.marker.setMap(mapShow.map);
    mapShow.marker.setTitle(mapShow.pos.title);
    mapShow.info = new google.maps.InfoWindow();
    mapShow.info.setContent(mapShow.pos.text);
    mapShow.info.open(mapShow.map, mapShow.marker);

    google.maps.event.addListener(mapShow.marker, 'click', mapShow.showHideInfo);
  },

  /**
   * Zeigt und versteckt das Infofenster der Markierung.
   */
  showHideInfo: function()
  {
    if(mapShow.info.view) mapShow.info.close();
    else mapShow.info.open(mapShow.map, mapShow.marker);
  }

}

