function map_initialize(page) {
	var latlng = new google.maps.LatLng(52.3748, 9.74319);
	var zoom = 8;
	if (page == "detail") {
		/* auf Detailseite wird der Geocode mitgegeben */
		latlng = new google.maps.LatLng(myLocLat, myLocLong);
		zoom = 16;
	}
	var myOptions = {
		zoom: zoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map_canvas = "map_" + page;
	var map = new google.maps.Map(document.getElementById(map_canvas), myOptions);
	var markerimage = map_markerimage();
	
	if (page == "detail") {
		var marker = new google.maps.Marker({
			position: latlng, 
			map: map, 
			title: document.title,
			icon: markerimage,
		});  	
	} else if(page == "list") {
		/* Markieren der POIs auf der Karte */
		map_setlocations(map); 
	}
}

function map_setlocations(map) {
	var locations = adrlocations; /* wurden im Dokument festgelegt */
      var latlngbounds = new google.maps.LatLngBounds( );
	var markerimage = map_markerimage();
      for (var i = 0; i < locations.length; i++) {
		var loc = locations[i];
		var myLatLng = new google.maps.LatLng(loc[1], loc[2]);
		var marker = new google.maps.Marker({
			position: myLatLng,
			map: map,
			title: loc[0],
			icon: markerimage,
		});
		latlngbounds.extend( myLatLng );
	}
/*	map.setCenter( latlngbounds.getCenter( )); */
	map.fitBounds( latlngbounds);
}

function map_markerimage() {
	var image = new google.maps.MarkerImage('/i/marker.gif',
      // This marker is 25 pixels wide by 42 pixels tall.
      new google.maps.Size(30, 42),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(15, 38));
      return image;
}

function initSearch(field) {
	var acfield = "ac_" + field;
	var acchoices = "ac_" + field + "_choices";
	var currentval = $(acfield).value;
	if (currentval == 'Branche' || currentval == 'Stadt') {
		$(acfield).value="";
	}
	new Ajax.Autocompleter(acfield, acchoices, "/ajax.php", {});	
}

function MyOnOff(id) {
	ref = document.getElementById(id);
	var hidden = true;
	if (ref.style.display != 'none') {
		ref.style.display='none';
		hidden = true;
	} else {
		ref.style.display='block';
		hidden = false;
	}
	/* Text setzen */
	if (id == "map_detail") {
		ref = document.getElementById('toggle_map_detail');
		if (hidden) {
			ref.innerHTML = '> einblenden';
		} else {
			ref.innerHTML = '> ausblenden';
		}
	}
	if (id == "credit_more") {
		ref = document.getElementById('toggle_credit_more');
		if (!hidden) {
			ref.innerHTML = '';
		}
	}
}
