var gmap =
{
  //variables
  mapDOMId : null,
  compatible : false,
  googleMapInstance : null,
  markers : new Array(),
	tooltips: new Array(),
  bounds : null,
  
  /**
   * init function
   */
  init : function(mapDOMId, initLong, initLat, initZoom, showZoom)
  {
    gmap.mapDOMId = mapDOMId;
    showZoom = (showZoom && (showZoom == true || showZoom == false)) ? showZoom : false;
    
    //check browser is compatible
    if (GBrowserIsCompatible())
    {
      //where should the map be placed
      gmap.googleMapInstance = new GMap2(document.getElementById(gmap.mapDOMId));

      /* center op Nederland - inzoomwaarde 15 */
      var center = new GLatLng(initLong, initLat);
      gmap.googleMapInstance.setCenter(center, initZoom);
      
      //show satelite view
      gmap.googleMapInstance.setMapType(G_PHYSICAL_MAP); //G_SATELLITE_MAP
            
      if(showZoom)
        gmap.googleMapInstance.addControl( new google.maps.LargeMapControl3D( ) );
      
      //gmap.googleMapInstance.addControl(new GLargeMapControl());
      //gmap.googleMapInstance.addControl( new google.maps.MenuMapTypeControl( ) );
      
      //object for calculating zooming level
      gmap.bounds = new GLatLngBounds();
    }
    else //if not compatible, hide map
      $('#' . gmap.mapDOMId).hide();
  },
  
  
  
  /**
   * add marker
   */
  addMarker : function(longitude, latitude, popupHTML)
  {
    var point = new GLatLng(longitude, latitude);
    var newMarker = new GMarker
    (
      point,
      { draggable: false }
    );
    
    //add listener to open popup
    GEvent.addListener(newMarker, "click", function() 
		{
      newMarker.openInfoWindowHtml(popupHTML);
		});     	
		
    //add marker as overlay to the map			
		gmap.googleMapInstance.addOverlay(newMarker);
    
    //add items to holders
    gmap.markers.push(newMarker);
		gmap.tooltips.push(popupHTML);
    
    //extend bounds to fit content
    gmap.bounds.extend(point);
  },
	
	
	
	/**
	 * show marker tooltip by index
	 */
	showMarkerTooltip : function(markerIndex)
	{
		if(markerIndex)
			gmap.markers[markerIndex].openInfoWindowHtml(gmap.tooltips[markerIndex]);
	},
  
  
  
  
  /**
   * resize to contents
   */
  resizeToContents : function(maxZoomLevel, extraZoomOut)
  {
		var zoomLevel = gmap.googleMapInstance.getBoundsZoomLevel(gmap.bounds);
		extraZoomOut = (extraZoomOut) ? extraZoomOut : 0;
    
    if(maxZoomLevel && zoomLevel > maxZoomLevel)
      zoomLevel = maxZoomLevel;
      
    gmap.googleMapInstance.setZoom(zoomLevel - extraZoomOut);
    
    gmap.googleMapInstance.setCenter(gmap.bounds.getCenter());    
  }
  
};
