var map = null;
var geocoder = null;

function iniMap (div,center,oOptions) {

	var oOptions = augment ({
		mapControl: true,
		typeControl: true,
		zoom:5,
		mapMode:G_HYBRID_MAP
	}, oOptions );
	if (GBrowserIsCompatible()) {
//		map = new GMap2(div);
		map = new GMap2(document.getElementById("airportmap"));
	//	var bounds = new GLatLngBounds(); // Fitting Data into Zoom
	
		if (oOptions.mapControl ) map.addControl(new GSmallMapControl());
		if (oOptions.typeControl) map.addControl(new GMapTypeControl());
		map.setCenter(center,oOptions.zoom,oOptions.mapMode);
	}
	return map;
}


function createMarker(map,latlng, bounds, html, iconType) {
  var gicons=[];
  var marker;
 
  var epafMarker = new GIcon();
  epafMarker.iconSize = new GSize(20, 30);
  epafMarker.shadowSize = new GSize(26, 39);
  epafMarker.iconAnchor = new GPoint(10, 30);
  epafMarker.infoWindowAnchor = new GPoint(5, 1);

  gicons["airport"] = new GIcon( epafMarker, "http://www.einfach-parken-am-flughafen.de/images/buttons/marker/airport.png");
  
  gicons["parkingsite"] = new GIcon( epafMarker, "http://www.einfach-parken-am-flughafen.de/images/buttons/marker/parkingsite.gif");
  epafMarker = new GIcon();
  epafMarker.iconSize = new GSize(18, 17);
//  epafMarker.shadowSize = new GSize(26, 39);
  epafMarker.iconAnchor = new GPoint(9, 8);
  epafMarker.infoWindowAnchor = new GPoint(5, 1);
  gicons["airportsml"] = new GIcon( epafMarker, "http://www.einfach-parken-am-flughafen.de/images/buttons/marker/airport_sml.png");

  if (bounds != null) bounds.extend(latlng);

  if (iconType == "airport") marker = new GMarker(latlng,gicons["airport"]);
  else if (iconType == "airportsml") marker = new GMarker(latlng,gicons["airportsml"]);
  else if (iconType == "parkingsite") marker = new GMarker(latlng,gicons["parkingsite"]);
  else marker = new GMarker(latlng);
  
  if (html != null) {
	  marker.value = html;
	  GEvent.addListener(marker,"click", function() {
		var myHtml = html;
		map.openInfoWindowHtml(latlng, myHtml);
	  });
  }
  return marker;
}

function createMarkerSidebar(map,latlng, bounds, html,name) {
	var marker = createMarker(map,latlng, bounds, html);
	GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });

	side_bar_html += '<a href="javascript:myclick(markers' + (gmarkers.length-1) + ')">' + name + '</a><br>';
	return marker
}


function myclick(gmarkers,i) {
	GEvent.trigger(gmarkers[i], "click");
}

/*
  Augment an object by replacing its key:value pairs with those
  from other object(s), and adding pairs from other object(s) that don't
  exist in you.  Key:value pairs from later objects will
  overwrite those from earlier objects.
  
  If null is given as the initial object, a new one will be created.
  
  This mutates and returns the object passed as oSelf. The other objects are not changed.
*/
function augment (oSelf, oOther) {
    if (oSelf == null) {
        oSelf = {};
    }
    for (var i = 1; i < arguments.length; i++) {
        var o = arguments[i];
        if (typeof(o) != 'undefined' && o != null) {
            for (var j in o) {
                oSelf[j] = o[j];
            }
        }
    }
    return oSelf;
}
