// zeigt die Googlekarte an (klappt sie auf)
// Displays the Google map (it pops up)
function showGMap(){
	if (map == null) {
		loadGMap(0, 0, false);
	}
	map.container.style.display = 'block';
	map.btnHide.style.display = 'inline';
	map.btnShow.style.display = 'none';
}

// versteckt die Googlekarte (klappt sie zu)
// Hides the Google map (it closes)
function hideGMap() {
	map.container.style.display = 'none';
	map.btnShow.style.display = 'inline';
	map.btnHide.style.display = 'none';
}

// zeigt die übergebende Position auf der Googlekarte an
// Displays the transferring position on Google Map
// lat	- Geokoordinate latitude
// lng	- Geokoordinate longitude
// zoom - neues/new Zoomlevel
function showGLatLng(lat, lng, zoom) {
	if (map == null) {
		loadGMap(0, 0, false);
	}
	if (map.container != null) {
		showGMap();
	}
	window.location = '#map';
	map.setCenter(new GLatLng(lat, lng));
	map.setZoom(zoom);
}

// setzt den Zoomlevel und die Position der Karte auf die in map.defaultZoom
// und map.defaultCenter gespeicherten Werte

// Sets the zoom level and position on the map in map.defaultZoom
// and stored values map.defaultCenter
function resetGMap() {
	map.setZoom(map.defaultZoom);
	map.setCenter(map.defaultCenter);
	if (map.container != null) {
		showGMap();
	}
}


// erstellt ein GIcon-Objekt für die GMap und gibt dieses zurück
// iconID  - ID-Nummer, welches das Icon representiert
// nr      - eine zusätzliche Nummer für das Icon (wird nicht immer benötigt)
// Creates an object for the GMap GIcon and returns
// iconID - ID number, which represents the icon
// nr - an additional number for the icon (not always needed)
function createMarkerIcon(iconID, no) {
    var icon = new GIcon();
    switch(iconID) {
    	case 0: // WG - weiteres Angebot im Umkreis
				// WG - further offer within
			icon.image = "img/gmap/wg_off.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
		case 1: // Wohnung - weiteres Angebot im Umkreis
				// Flat - another offer within
			icon.image = "img/gmap/whg_off.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
		case 2: // Haus - weiteres Angebot im Umkreis
				// House - another offer within
			icon.image = "img/gmap/haus_off.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
		case 3: // Nummeriert für die Favorietenliste (max. 99)
				// Number is Favorite List  (max. 99)
			icon.image = "img/gmap/numbered_icons/marker" + no + ".png";
			icon.shadow = "img/gmap/numbered_icons/shadow.png";
			icon.iconSize = new GSize(20, 34);
			icon.shadowSize = new GSize(37, 34);
			icon.iconAnchor = new GPoint(10, 34);
			break;
		case 4: // Umkreissuche Mittelpunkt (Adresse)
				// Radius search center (address)
			icon.image = "img/gmap/umkreis_icons/marker_poi.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(18, 28);
			icon.shadowSize = new GSize(32, 28);
			icon.iconAnchor = new GPoint(10, 28);
			break;
    	case 5: // WG - aktuelle Anzeige
				// WG - current display
			icon.image = "img/gmap/wg_on.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
		case 6: // Wohnung - aktuelle Anzeige
				// Housing - current display
			icon.image = "img/gmap/whg_on.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
		case 7: // Haus - aktuelle Anzeige
				// Home - current display
			icon.image = "img/gmap/haus_on.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
   		case 9: // mehrere Anzeigen auf dem selben Punkt
			    // no enthält die Anzahl der Anzeigen
				// enthält Umkreissuche Mittelpunkt (Adresse)
				// More ads on the same point
				// no shows the number of ads
				// Holds radius search center (address)
			icon.image = "img/gmap/numbered_icons/leer.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(20, 34);
			icon.shadowSize = new GSize(37, 34);
			icon.iconAnchor = new GPoint(10, 34);
			break;
   		case 10: // mehrere Anzeigen auf dem selben Punkt
			     // no enthält die Anzahl der Anzeigen
				 // enthält WG - aktuelle Anzeige
				 // More ads on the same point
				// no shows the number of ads
				// Holds WG - current display
			icon.image = "img/gmap/wg_on_akt.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
   		case 11: // mehrere Anzeigen auf dem selben Punkt
			     // no enthält die Anzahl der Anzeigen
				 // enthält Wohnung - aktuelle Anzeige
				 // More ads on the same point
				// no shows the number of ads
				// contains apartment - current display
			icon.image = "img/gmap/whg_on_akt.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
   		case 12: // mehrere Anzeigen auf dem selben Punkt
			     // no enthält die Anzahl der Anzeigen
				 // enthält Haus - aktuelle Anzeige
				 // More ads on the same point
				// no shows the number of ads
				// containing house - current display
			icon.image = "img/gmap/haus_on_akt.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(24, 38);
			icon.shadowSize = new GSize(36, 38);
			icon.iconAnchor = new GPoint(12, 38);
			break;
		case 13: // nummeriert für die Umkreissuche (max. 20 Ergebnisse)
				 // Numbered for the proximity search (max. 20 results)
			icon.image = "img/gmap/umkreis_icons/marker" + no + ".png";
			icon.shadow = "img/gmap/umkreis_icons/shadow.png";
			icon.iconSize = new GSize(18, 28);
			icon.shadowSize = new GSize(32, 28);
			icon.iconAnchor = new GPoint(10, 28);
			break;
		case 14: // mehrere Anzeigen auf dem selben Punkt - für Detailansicht
			     // no enthält die Anzahl der Anzeigen
				 // More ads on the same point - for details
				 // no shows the number of ads
			icon.image = "img/gmap/umkreis_icons/marker_multiple_ads.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(18, 28);
			icon.shadowSize = new GSize(32, 28);
			icon.iconAnchor = new GPoint(10, 28);
			break;
		case 15: // mehrere Anzeigen auf dem selben Punkt - für Umkreiskarte
			     // no enthält die Anzahl der Anzeigen
				 // More ads on the same point - for perimeter map
				 // no shows the number of ads
			icon.image = "img/gmap/umkreis_icons/marker_multiple_ads.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(18, 28);
			icon.shadowSize = new GSize(32, 28);
			icon.iconAnchor = new GPoint(10, 28);
			break;
		case 16: // mehrere Anzeigen auf dem selben Punkt - für Favoriten
			     // no enthält die Anzahl der Anzeigen
				 // Multiple ads on the same point - to Favorites
				 // no shows the number of ads
			icon.image = "img/gmap/umkreis_icons/marker_multiple_ads.png";
			icon.shadow = "img/gmap/shadow.png";
			icon.iconSize = new GSize(18, 28);
			icon.shadowSize = new GSize(32, 28);
			icon.iconAnchor = new GPoint(10, 28);
			break;
		default:
			return null;
    }
	return icon;
}

// erstellt die tatsächlichen Markierungen in der GMap
// lat       - Geokoordinate Latitude der neuen Markierung
// lng       - Geokoordinate Longitude der neuen Markierung
// infoHTML  - HTML-Text mit Informationen über die Markierung (wird als Tooltip angezeigt)
// link      - Beim klick auf die Markierung wird dieser Link aufgerufen (oder leer lassen)
// options   - siehe Google Maps-API unter GMarkerOptions:
//     http://code.google.com/intl/de/apis/maps/documentation/reference.html#GMarkerOptions

// Create the actual marks on the GMap
// lat - Latitude geo-coordinates of the new marker
// lng - longitude geo-coordinates of the new marker
// info html - HTML text with information about the marker (displayed as a tooltip)
// link - Clicking on the selection of this link is called (or blank)
// options - see Google Maps APIin GMarkerOptions :
// # http://code.google.com/intl/de/apis/maps/documentation/reference.html GMarkerOptions
function createMarker(lat, lng, infoHTML, link, options) {
	var marker = new GMarker(new GLatLng(lat, lng), options);
    marker.link = link;
	marker.infoHTML = infoHTML;
	map.addOverlay(marker);

	if (marker.link || marker.infoHTML) {
		GEvent.addListener(marker, "click", function() {
            if (!marker.link) {
				if (map.infoWin.lastChild != null) {
					if (map.infoWin.open == true && map.infoWin.activeMarker == marker) {
                        map.infoWin.open = false;
						map.infoWin.lastChild.style.display = 'none';
					} else {
						if (map.infoWin.activeMarker != marker) {
							openInfoWin(marker);
						}
						map.infoWin.lastChild.style.display = 'block';
	            		map.infoWin.open = true;
					}
				}
			} else {
				window.open(marker.link, '_blank');;
			}
		});
	}
	if (marker.infoHTML) {
		GEvent.addListener(marker, "mouseover", function() {
			if (map.infoWin.open != true) {
		        openInfoWin(marker);
			}

		});
		GEvent.addListener(marker, "mouseout", function() {
            if (map.infoWin.open != true) {
            	closeInfoWin();
			}
		});
	}
	return marker;
}

// in XML können keine Tags+Anfürungszeichen als Attribute versendet werden
// außerdem gibt es Codierungsfehler bei bestimmten Zeichen wie das €-Zeichen
// diese Funktion wandelt die html-entities in normale Zeichen zurück

// To XML tags, no quotation marks + attributes are  sent as
// Also, there are coding errors with certain characters such as the €-sign
// this function converts the html entities back to normal characters
function html_entity_decode(str) {
	return str.replace(/&amp;/g, "&")
	          .replace(/&lt;/g, "<")
			  .replace(/&gt;/g, ">")
			  .replace(/&apos;/g, "'")
			  .replace(/&quot;/g, '"')
			  .replace(/&euro;/g, "€");
}

// wandet einen XML-Baum (als String) in die entsprechenden Marker zurück
// data    - XML-Baum
// status  - HTTP-Statuscode des Aufrufs

// Wandet an XML tree (as String) in the corresponding markers
// data - XML tree
// status - HTTP status code of the call
var nextDownloadMarker;
function parseXMLToMarker(data, status) {
	//alert(data);
    if (status == 200) {
		var xml = GXml.parse(data);
        var markersXML;
		if (xml != null && xml.documentElement != null) {
			markersXML = xml.documentElement.getElementsByTagName('marker')
        }
		var markers = getMarkers();
		var counter = markers.length;
		for (var i = 0; i < markersXML.length; i++) {
			var duplicate = false;
			for (var ii = 0; ii < counter; ii++) {
            	if (markers[ii].id == markersXML[i].getAttribute('id')) {
            		duplicate = true;
					break;
            	}
			}
			if (!duplicate) {
				var options = {icon: createMarkerIcon(parseInt(markersXML[i].getAttribute('iconID')))};
				markers[markers.length] = {
										   lat: parseFloat(markersXML[i].getAttribute('lat')),
										   lng: parseFloat(markersXML[i].getAttribute('lng')),
										   infoHTML: html_entity_decode(markersXML[i].getAttribute('info')),
					                       link: markersXML[i].getAttribute('link'),
										   options: options,
										   clusterImg: 0
				};
			}
	    }
        markers = clusterMarkers(markers);
        map.clearOverlays();
		for (var i = 0; i < markers.length; i++) {
        	marker = createMarker(markers[i].lat, markers[i].lng, markers[i].infoHTML, markers[i].link, markers[i].options);
		}
		map.infoBar.errorDiv.style.display = 'none';
	    if (xml.documentElement.getAttribute('toMany')==1) {
			// es sind mehr Elemente vorhanden als zurück geliefert werden.
			// There are more items available than are delivered back.
			map.infoBar.countDiv.style.display = 'block';
			map.infoBar.noAdDiv.style.display = 'none';
		} else if (markersXML.length == 0) {
			// es sind keine Anzeigen im bereich vorhanden.
			// There are no ads in the area available.
			map.infoBar.countDiv.style.display = 'none';
			map.infoBar.noAdDiv.style.display = 'block';
		} else {
			map.infoBar.countDiv.style.display = 'none';
			map.infoBar.noAdDiv.style.display = 'none';
	    }
	}

	if (status != 200 || xml == null || xml.documentElement == null || xml.documentElement.nodeName != 'markers'){
    	// fehler beim übertragen.
		// Failed to transfer.
		map.infoBar.errorDiv.style.display = 'block';
		map.infoBar.noAdDiv.style.display = 'none';
		map.infoBar.countDiv.style.display = 'none';
    }

	map.loadIcon.style.visibility = 'hidden';

    if (map.showAds != null && !map.showAds.checked) {
    	resetMarker();
		nextDownloadMarker = null;
    } else {
		// es steht bereits eine neue Anfrage an, diese nun durchführen
		// It is already a new inquiry, it now perform
		if (nextDownloadMarker != null) {
			var lat1 = nextDownloadMarker.lat1;
			var lng1 = nextDownloadMarker.lng1;
			var lat2 = nextDownloadMarker.lat2;
			var lng2 = nextDownloadMarker.lng2;
			nextDownloadMarker = null;
			loadAds(lat1, lng1, lat2, lng2);
		}
	}
}

// neue Anzeigen laden (per Ajax über Google Maps-API)
// New ads download (via Ajax with Google Maps API)
function loadAds(lat1, lng1, lat2, lng2) {
	if (map.loadIcon.style.visibility == 'hidden') {
		map.infoBar.zoomDiv.style.display = 'none';
		map.loadIcon.style.visibility = 'visible';
		GDownloadUrl('gmapxml.php?lat1=' + lat1 + '&lng1=' + lng1 +
		             '&lat2=' + lat2 + '&lng2=' + lng2,
		             parseXMLToMarker);
	} else {
		nextDownloadMarker = {
			lat1: lat1,
			lng1: lng1,
			lat2: lat2,
			lng2: lng2
		};
	}
}


// sucht nach Markierungen, die sehr nahe beeinander liegen
// wenn solche gefunden wurden, werden diese in das Attribut 'cluster'
// verschoben, um dann zusammen gefasst zu werden

// Looks for markers that are very close to each other if any have been found, 
// this 'cluster' in the attribute moved, only to be taken together
function clusterMarkers(tempMarkers) {
    var markers = new Array();
	for (var i = 0; i < tempMarkers.length; i++) {
		duplicate = false;
		for (var ii = 0; ii < markers.length; ii++) {
			if (markers[ii].clusterImg >= 0) {
				if (markers[ii].lat - 0.0001 <= tempMarkers[i].lat && markers[ii].lat + 0.0001 >= tempMarkers[i].lat) {
					if (markers[ii].lng - 0.0001 <= tempMarkers[i].lng && markers[ii].lng + 0.0001 >= tempMarkers[i].lng) {
						if (markers[ii].cluster == null) {
							marker = markers[ii];
							markers[ii].cluster = new Array();
							markers[ii].cluster[0] = marker;
						}
						markers[ii].cluster[markers[ii].cluster.length] = tempMarkers[i];
						duplicate = true;
						break;
					}
				}
			}
		}
		if (!duplicate) {
			markers[ii] = tempMarkers[i];
		}
    }

	for (var i = 0; i < markers.length; i++) {
		var clusterImg = GMAP_DEFAULT_CLUSTER_IMAGE; // default ClusterimageID
		if (markers[i].cluster) {
           	var div = document.createElement('div');
			div.innerHTML = '<div><strong>' + mapText_mehrereAnzeigen + ' (' + markers[i].cluster.length + ')</strong></div>';

			divContent = document.createElement('div');
			divContent.style.display = 'none';
			divContent.style.position = 'relative';
			divContent.innerHTML = '<div style="position: absolute; right: 0; top:-13px;" onclick="javascript:map.infoWin.style.visibility = \'hidden\';map.infoWin.open=false;"><a href="javascript:void(0)" class="map_btnClose">&nbsp;</a></div>';
            div.appendChild(divContent);

			var divFlow = document.createElement('div');
			divFlow.className = 'infoWin_Flow';
			for (var ii = 0; ii < markers[i].cluster.length; ii++) {
				divLine = document.createElement('div');
				divLine.className = 'divide';
				divLine.innerHTML = '&nbsp;';
				divLine.style.width = '98%';
				divLine.style.minWidth = '100px';
                   if (ii == 0) {
					divContent.appendChild(divLine);
					divContent.appendChild(divFlow);
                   } else {
					divFlow.appendChild(divLine);
                   }

				var divChild = document.createElement('div');
                   divChild.innerHTML = markers[i].cluster[ii].infoHTML;
				divChild.style.position = 'relative';
				divFlow.appendChild(divChild);

				var divImage = document.createElement('div');
				divImage.style.position = 'absolute';
				divImage.style.right = '2px';
				divImage.style.top = '0px';
				divImage.style.height = '1px';
				divImage.style.overflow = 'visible';
				divImage.title = mapText_zurAnzeige;
				var divMarkerImg = document.createElement('img');
				divMarkerImg.src = markers[i].cluster[ii].options.icon.image;
				divMarkerImg.width = markers[i].cluster[ii].options.icon.iconSize.width;
				divMarkerImg.height = markers[i].cluster[ii].options.icon.iconSize.height;
				if (markers[i].cluster[ii].link) {
					var divMarkerLink = document.createElement('a');
					divMarkerLink.target = '_blank';
					divMarkerLink.href = markers[i].cluster[ii].link;
					divMarkerLink.appendChild(divMarkerImg);
					divImage.appendChild(divMarkerLink);
				} else {
					divImage.appendChild(divMarkerImg);
				}
				divChild.appendChild(divImage);

                if (markers[i].clusterImg > 0) {
                	clusterImg = markers[i].clusterImg;
                }

               }
			markers[i].infoHTML = div.innerHTML;
			markers[i].link = '';
			markers[i].options.icon = createMarkerIcon(clusterImg, markers[i].cluster.length);
		}
	}
	return markers;
}

function resetMarkers() {
	var markers = getMarkers();
	markers = clusterMarkers(markers);
	map.clearOverlays();
	for (var i = 0; i < markers.length; i++) {
		createMarker(markers[i].lat, markers[i].lng, markers[i].infoHTML, markers[i].link, markers[i].options);
	}
	map.infoBar.zoomDiv.style.display = 'block';
	map.infoBar.countDiv.style.display = 'none';
	map.infoBar.errorDiv.style.display = 'none';
	map.infoBar.noAdDiv.style.display = 'none';
}


// Einstiegspunkt für die GMap, erstellt und lädt die GMap V2 (deprecated)
/*
function loadGMap(lat, lng, nachladenAnzeigen) {
	if (GBrowserIsCompatible()) {
        // erstellt das tatsächliche GMap-Element
		var div = document.getElementById('map');
		var width = parseInt(div.style.width);
		var height = parseInt(div.style.height);
		map = new GMap2(div, {size: new GSize(width, height)});
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(lat, lng), 13);

        map.container = document.getElementById('map_container');
		map.btnHide = document.getElementById('map_ausblenden');
		map.btnShow = document.getElementById('map_anzeigen');
		map.btnReset = document.getElementById('map_resetten');


		map.infoBar = document.getElementById('map_infoBar');
		if (nachladenAnzeigen) {
	        // erstellt das Ladenicon
			map.loadIcon = document.createElement('div');
			map.loadIcon.id = 'mapIsLoading';
			map.loadIcon.innerHTML = '<img src="img/gmap/loading.gif" style="position: relative; top: 4px; left: 50px;" WIDTH="16px" HEIGHT="16px"> <span style="color: #CE6300; position: relative; left: 50px;">loading...</span>';
			map.getContainer().appendChild(map.loadIcon);
	    	map.loadIcon.style.visibility = 'hidden';
			map.loadIcon.style.top = (width/2-63) + 'px';
			map.loadIcon.style.left = (height/2-63) + 'px';

			// erstelle Infotext für weit ausstehende Zoomlevel
			map.infoBar.zoomDiv = document.getElementById('map_infoZoom');
			if (map.infoBar.zoomDiv == null) {
               map.infoBar.zoomDiv = document.createElement('div');
			}
			map.infoBar.countDiv = document.getElementById('map_infoAnzahl');
			if (map.infoBar.countDiv == null) {
               map.infoBar.countDiv = document.createElement('div');
			}
			map.infoBar.noAdDiv = document.getElementById('map_infoEmpty');
			if (map.infoBar.noAdDiv == null) {
				map.infoBar.noAdDiv = document.createElement('div');
			}
			map.infoBar.errorDiv = document.getElementById('map_infoError');
			if (map.infoBar.errorDiv == null) {
				map.infoBar.errorDiv = document.createElement('div');
			}
			map.getContainer().appendChild(map.infoBar);

			map.infoBar.style.display = 'block';

			map.showAds = document.getElementById('map_anzeigenEinblenden');
			map.hideAds = document.getElementById('map_anzeigenAusblenden');
			
			if (map.showAds != null || map.hideAds != null) {
				map.showAds.onclick = function () {
					map.showAds.style.display = 'none';
					map.hideAds.style.display = 'inline';
					map.setZoom(16);
					var bounds = map.getBounds();
					var southwest = bounds.getSouthWest();
					var northeast = bounds.getNorthEast();
					loadAds(southwest.lat(), southwest.lng(), northeast.lat(), northeast.lng());
				}
				map.hideAds.onclick = function () {
					map.showAds.style.display = 'inline';
					map.hideAds.style.display = 'none';
					resetMarkers();
				}
			}
		} else {
			if (map.infoBar != null) {
	        	map.infoBar.style.display = 'none';
			}
			var showAds = document.getElementById('map_showAds');
			if (showAds != null) {
				showAds.style.display = 'none';
			}
		}

		// erstellt das kleine Infofenster für die Anzeigen
		map.infoWin = document.createElement('div');
		map.infoWin.id = 'map_infoWin';
		map.infoWin.style.visibility = 'hidden';
		map.infoWin.style.position = 'absolute';
		map.getContainer().appendChild(map.infoWin);

		// erstellt alle bereits zu beginn bekannten Marker für die Anzeigen
		var markers = clusterMarkers(getMarkers());

        var bounds = new GLatLngBounds();
		for (var i = 0; i < markers.length; i++) {
        	marker = createMarker(markers[i].lat, markers[i].lng, markers[i].infoHTML, markers[i].link, markers[i].options);
			bounds.extend(marker.getLatLng());
		}
        if (markers) {
        	if (markers.length == 1) {
        		map.defaultZoom = 14;
        	} else {
				map.defaultZoom = map.getBoundsZoomLevel(bounds);
            }
			map.defaultCenter = bounds.getCenter()
			resetGMap();
			var point = map.fromLatLngToContainerPixel(bounds.getNorthEast());
			if (point.y < 32) {
				map.defaultZoom -= 1;
				resetGMap();
			}
        }

        // Resettbutton anzeigen, sobald GMap geladen wurde
		if (map.btnReset != null) {
			map.btnReset.style.display = 'inline';
		}


        // wenn alle Anzeigen auch dargestellt werden sollen, die im
		// sichtbaren bereich sind, sind die zusätzlichen Events zu behandeln
		if (nachladenAnzeigen) {
			GEvent.addListener(map, "dragend", function() {
				if (map.getZoom() >= GMAP_MIN_ZOOM && (map.showAds == null || map.showAds.checked)) {
					var bounds = map.getBounds();
					var southwest = bounds.getSouthWest();
					var northeast = bounds.getNorthEast();
					loadAds(southwest.lat(), southwest.lng(), northeast.lat(), northeast.lng());
				}
			});
			GEvent.addListener(map, "zoomend", function(oldLevel, newLevel) {
				if (newLevel >= GMAP_MIN_ZOOM && (map.showAds == null || map.showAds.checked)) {
					var bounds = map.getBounds();
					var southwest = bounds.getSouthWest();
					var northeast = bounds.getNorthEast();
					loadAds(southwest.lat(), southwest.lng(), northeast.lat(), northeast.lng());
				} else if (oldLevel > newLevel && oldLevel == GMAP_MIN_ZOOM) {
					resetMarkers();
				}
			});
	    }

	    // Map Ads Unit
		var publisherID = 'pub-7157467210962335';
		var adsManagerOptions = {
			maxAdsOnMap : 1,
			style: 'adunit',
			channel: '2067313022'
		};
		adsManager = new GAdsManager(map, publisherID, adsManagerOptions);
		//adsManager.enable();
	}
}
*/

//////////////////////////////////////////// MAP V3 /////////////////////////////////////
// Einstiegspunkt für die GMap, erstellt und lädt die GMap V3
function loadGMap(lat, lng, nachladenAnzeigen) {
	// erstellt das tatsächliche GMap-Element
	var div = document.getElementById('map');
	if (!div) { return; }
	var width = parseInt(div.style.width);
	var height = parseInt(div.style.height);
	var latlng = new google.maps.LatLng(lat, lng);
	
	var mapOptions = {
	  zoom: 15,
	  center: latlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	// generate map
	var map = new google.maps.Map(div, mapOptions);
	
	// overlay markers
	var ads = [
	  ['Aktuell Anzeige', lat, lng, 4]
	];
	setMarkers(map, ads);
}
// marker v3
function setMarkers(map, locations) {
  // Add markers to the map

  // Marker sizes are expressed as a Size of X,Y
  // where the origin of the image (0,0) is located
  // in the top left of the image.

  // Origins, anchor positions and coordinates of the marker
  // increase in the X direction to the right and in
  // the Y direction down.
  var image = new google.maps.MarkerImage('img/gmap/wg_on.png',
      // This marker is 18 pixels wide by 28 pixels tall.
      new google.maps.Size(20, 32),
      // 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(14, 32));
  var shadow = new google.maps.MarkerImage('img/gmap/shadow.png',
      // The shadow image is larger in the horizontal dimension
      // while the position and offset are the same as for the main image.
      new google.maps.Size(37, 32),
      new google.maps.Point(0,0),
      new google.maps.Point(10, 28));
      // Shapes define the clickable region of the icon.
      // The type defines an HTML <area> element 'poly' which
      // traces out a polygon as a series of X,Y points. The final
      // coordinate closes the poly by connecting to the first
      // coordinate.
  var shape = {
      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
      type: 'poly'
  };
  for (var i = 0; i < locations.length; i++) {
    var ads = locations[i];
    var myLatLng = new google.maps.LatLng(ads[1], ads[2]);
	var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        shadow: shadow,
        icon: image,
        shape: shape,
        title: ads[0],
        zIndex: ads[3],
    });
	
	var markerCounter = 0;
	markerCounter++;
	var contentString = 'this is the infor test text for:<br/> marker '+markerCounter;
	// var contentString = displayInfoWindow();
	
	//Open the info window
	var infowindow = new google.maps.InfoWindow({
		content: contentString
	});
  }
	
	// Show and hide info window
	google.maps.event.addListener(marker, 'mouseover', function() {
		infowindow.open(map,marker);
	});
	google.maps.event.addListener(marker, 'mouseout', function() {
		infowindow.close(map,marker);
	});
}








