/**
 * Prüft auf kompatiblen Browser und vorhandene Variablen und ruft die
 * Funktion auf, die die GoogleMap erstellt.
 */
function twGmapLoad() {
	if (GBrowserIsCompatible()) {
		var elementId 			= "gmap";  // ID des DIV-Containers
		var lat       			= "50.6826";  // Breitengrad (Latitude)
		var lon       			= "6.9751";  // Längengrad (Longitude)
		var zoom      			= 10;        // einen Wert von 1 bis ca 17

		var point_rheinbach  	= new GPoint(6.9518, 50.6258); // Longitude, Latitude von der Filiale in Rheinbach
		var point_meckenheim  	= new GPoint(6.9911, 50.7623); // Longitude, Latitude von der Filiale in Meckenheim
		var point_bornheim  	= new GPoint(7.021301686763763, 50.62148028219454); // Longitude, Latitude von der Filiale in Meckenheim

		// Rotec Marker
		var width = 25; // Breite der Grafik
		var height = 29; // Höhe der Grafik
		var hermeler = new GIcon(G_DEFAULT_ICON);
		hermeler.image = "templates/default/img/g-map-pin.gif";
		hermeler.iconSize = new GSize(width, height);
		hermeler.mozPrintImage = "";
		hermeler.shadow = "";
		hermeler.transparent = "";
		hermeler.printImage = "";
		hermeler.printShadow = "";
		hermeler.iconAnchor = new GPoint(12.5, 29);
		hermeler.infoWindowAnchor = new GPoint(12.5, 29);
		hermeler.shadowSize = new GSize(0, 0);
		var markerOptions = { icon:hermeler };

		machTwGmap(elementId, lat, lon, zoom, point_rheinbach, point_bornheim, point_meckenheim, markerOptions);
	}
}

function machTwGmap(id, lat, lon, zoom, point_rheinbach, point_meckenheim, point_bornheim, markerOptions) {
	var map = new GMap2(document.getElementById(id));
	map.addControl(new GSmallZoomControl());
	map.setCenter(new GLatLng(lat, lon), zoom, G_HYBRID_MAP);
	map.enableScrollWheelZoom();
	map.enableContinuousZoom();
	map = rheinbach(map, point_rheinbach, markerOptions);
	map = meckenheim(map, point_meckenheim, markerOptions);
	map = bornheim(map, point_bornheim, markerOptions);
}

function rheinbach(map, point_rheinbach, markerOptions) {
	var marker = new GMarker(point_rheinbach);
	var html   = "";

	html += "<div class='twGmapInfo'>";
	html += "	<div class='twGmapContent'>";
	html += "		<h3>Hörgeräte Hermeler in Rheinbach</h3>";
	html += "		<p>Vor dem Voigtstor 1 <br />53359 Rheinbach</p><p>Tel.: (02226) 178 55<br />Fax.: (02226) 178 95</p>";
	html += "		<form name='search_route' method='get' action='http://maps.google.de/' target='_blank'>";
	html += "			<p>";
	html += "				<label style='display: block; width: auto; float: none;' for='saddr'><strong>Route berechnen:</strong> geben Sie hier Ihre Adresse ein.</label>";
	html += "				<input name='saddr' style='clear: both;' type='text' id='saddr' value=''>";
	html += "				<input name='daddr' type='hidden' id='daddr' value='Vor dem Voigtstor 1, 53359 Rheinbach, Deutschland'>";
	html += "				<input type='submit' name='Submit' class='submit' value='Anfahrt berechnen'>";
	html += "			</p>";
	html += "		</form>";
	html += "	</div>";
	html += "</div>";

    var marker = new GMarker(point_rheinbach, markerOptions);

	GEvent.addListener(marker, 'click', function() {
  		marker.openInfoWindowHtml(html);
	});

	map.addOverlay(marker);

	return map;
}

function meckenheim(map, point_meckenheim, markerOptions) {
	var marker = new GMarker(point_meckenheim);
	var html   = "";

	html += "<div class='twGmapInfo'>";
	html += "	<div class='twGmapContent'>";
	html += "		<h3>Hörgeräte Hermeler in Meckenheim</h3>";
	html += "		<p>Glockengasse 1<br />53340 Meckenheim</p><p>Tel.: (02225) 70 30 30<br />Fax.: (02225) 70 30 31 </p>";
	html += "		<form name='search_route' method='get' action='http://maps.google.de/' target='_blank'>";
	html += "			<p>";
	html += "				<label style='display: block; width: auto; float: none;' for='saddr'><strong>Route berechnen:</strong> geben Sie hier Ihre Adresse ein.</label>";
	html += "				<input name='saddr' style='clear: both;' type='text' id='saddr' value=''>";
	html += "				<input name='daddr' type='hidden' id='daddr' value='Glockengasse 1, 53340 Meckenheim, Deutschland'>";
	html += "				<input type='submit' name='Submit' class='submit' value='Anfahrt berechnen'>";
	html += "			</p>";
	html += "		</form>";
	html += "	</div>";
	html += "</div>";

	var marker = new GMarker(point_meckenheim, markerOptions);

	GEvent.addListener(marker, 'click', function() {
  		marker.openInfoWindowHtml(html);
	});

	map.addOverlay(marker);

	return map;
}



function bornheim(map, point_bornheim, markerOptions) {
	var marker = new GMarker(point_bornheim);
	var html   = "";

	html += "<div class='twGmapInfo'>";
	html += "	<div class='twGmapContent'>";
	html += "		<h3>Hörgeräte Hermeler in Bornheim</h3>";
	html += "		<p>Königstraße 59<br />53332 Bornheim</p><p>Tel.: (02222) 92 99 99 3<br />Fax.: (02222) 92 99 99 4</p>";
	html += "		<form name='search_route' method='get' action='http://maps.google.de/' target='_blank'>";
	html += "			<p>";
	html += "				<label style='display: block; width: auto; float: none;' for='saddr'><strong>Route berechnen:</strong> geben Sie hier Ihre Adresse ein.</label>";
	html += "				<input name='saddr' style='clear: both;' type='text' id='saddr' value=''>";
	html += "				<input name='daddr' type='hidden' id='daddr' value='Königstraße 59, 53332 Bornheim, Deutschland'>";
	html += "				<input type='submit' name='Submit' class='submit' value='Anfahrt berechnen'>";
	html += "			</p>";
	html += "		</form>";
	html += "	</div>";
	html += "</div>";

	var marker = new GMarker(point_bornheim, markerOptions);

	GEvent.addListener(marker, 'click', function() {
  		marker.openInfoWindowHtml(html);
	});

	map.addOverlay(marker);

	return map;
}
