/* ------------------------------------------------------------------------------------------ Google maps */
var geocoder = null;
function map(map_array) {
	
	if (GBrowserIsCompatible()) {
		bereich = '';
		id = '';
		w = '';
		h = '';
		pos_x = 0;
		pos_y = 0;
		zoom = '';
		strasse = '';
		stadt = '';
		land = '';
		icon = '';
		maptype = 'G_NORMAL_MAP';
		controls = '';
		
		for (var eigenschaft in map_array) {
			/* alert (eigenschaft + ": " + map_array[eigenschaft]); */
			window[eigenschaft] = map_array[eigenschaft];
		}
		
		geocoder = new GClientGeocoder();
		
		var address = strasse + ", " + stadt + ", " + land;
		//alert(address);
		
		geocoder.getLatLng(address,
			function(point) {
			
				// alert(point);
				
				if (!point) {
					document.getElementById('id_map' + id).style.display = "none";
					
				} else {
					var x = point.y;
					var y = point.x;
					
					/* alert (point + "\n" + address + "\n" + x + "\n" + y); */
					
					var new_icon = new GIcon();
					/* var path = "_layout/_icons/"; */
					new_icon.image = icon;
					/* icon.shadow = path + "gmaps_" + gender + "_shadow.png"; */
					/* new_icon.iconSize = new GSize(23, 43); */
					/* icon.shadowSize = new GSize(48, 43); */
					new_icon.iconAnchor = new GPoint(pos_x, pos_y);
					/* new_icon.infoWindowAnchor = new GPoint(5, 1); */
					
					var map = new GMap2(document.getElementById('map' + id));
					if (controls == 'large') {
						map.addControl(new GLargeMapControl());
					} else {
						map.addControl(new GSmallMapControl());
					}
					
					
					/* map.addControl(new GMapTypeControl()); */
					map.setCenter(new GLatLng(x, y), zoom);
					var point = new GLatLng(x, y);
					map.addOverlay(new GMarker(point, new_icon));
					map.addMapType(maptype);
					map.setMapType(maptype);
					
					document.getElementById('id_map' + id).style.display = "block";
				}
			}
		)
	}
}

function map_open() {
	var height = document.getElementById('map').style.height;
	
	if (height == "0px") {
		document.getElementById('map').style.height = "340px";
	} else {
		document.getElementById('map').style.height = "0px";
	}
}

function map_close() {
	document.getElementById('map').style.display = "none";
}

function map_show() {
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		map = new GMap2(document.getElementById('map'));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(20.3, 10.7), 1);
	}
}

function addMarker(address, stadt, land) {
	//alert (address);
	geocoder.getLatLng(
	address,
	function(point) {
		if (!point) {
			//alert (address + '\nnix');
			//document.getElementById('id_map').style.display = "none";
		} else {
			//alert(address + "\n" + point);
			var icon = new GIcon();
			icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
			icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
			icon.iconSize = new GSize(12, 20);
			icon.shadowSize = new GSize(22, 20);
			icon.iconAnchor = new GPoint(6, 20);
			icon.infoWindowAnchor = new GPoint(5, 1);
			
			var output = stadt + ", " + land;
			var options = {clickable:true, icon:icon, title:output};
			var marker = new GMarker(point, options);
			
			GEvent.addListener(marker, "click", function() {
				//alert(stadt + "_" + land);
				search('ja', '_includes_ebene_1/inc_1_alumni_suchergebnisse.php', 'map', stadt + '###' + land, '1');
			});
			
			map.addOverlay(marker, options);
		}
	});
}