
var map = null;
var geocoder = null;
var marker = null;

// Adressen
var adresse = new Array();

adresse[0] = new Array();
adresse[0]['adresse'] = 'Stralauer Allee 2, 10245 Berlin, Germany';
adresse[0]['html'] = '<span class="googletext"><b>Heimrich &amp; Hannot GmbH<br>Stralauer Allee 2<br>10245 Berlin</b>';

adresse[1] = new Array();
adresse[1]['adresse'] = 'Bayrische Straße 18, 01069 Dresden, Germany';
adresse[1]['html'] = '<span class="googletext"><b>Heimrich &amp; Hannot GmbH<br>Bayrische Straße 18<br>01069 Dresden</b>';

adresse[2] = new Array();
adresse[2]['adresse'] = 'Im Klapperhof 33, 50670 Köln, Germany';
adresse[2]['html'] = '<span class="googletext"><b>Heimrich &amp; Hannot GmbH<br>Im Klapperhof 33<br>50670 Köln</b>';

adresse[3] = new Array();
adresse[3]['adresse'] = 'Holbeinstraße 29, 04229 Leipzig, Germany';
adresse[3]['html'] = '<span class="googletext"><b>Heimrich &amp; Hannot GmbH<br>Holbeinstraße 29<br>04229 Leipzig</b>';


// functions that open the directions forms
function tohere(x) {
	marker.openInfoWindowHtml(adresse[x]['html']+'<br><br>Routenberechnung: <b>Hierher</b> - <a href="javascript:fromhere(' + x + ')">Von hier</a></span><form style="border-top:1px solid #ccc;width:300px;font-size:1em;padding:.4em 0 1em;margin:.5em 0 0" action="http://maps.google.de/maps" method="get" target="_blank"><input type="hidden" name="daddr" value="' + marker.getPoint().lat() + ',' + marker.getPoint().lng() + '"><span class="googletext">Startadresse (Straße Nr., Ort):</span><br><input type="text" class="googleinput" name="saddr" id="saddr" value=""><br><input value="Routenberechnung" type="submit" class="button" style="margin-top: .3em">');
}
function fromhere(x) {
	marker.openInfoWindowHtml(adresse[x]['html']+'<br><br>Routenberechnung: <a href="javascript:tohere(' + x + ')">Hierher</a> - <b>Von hier</b></span><form style="border-top:1px solid #ccc;width:300px;font-size:1em;padding:.4em 0 1em;margin:.5em 0 0" action="http://maps.google.de/maps" method="get"" target="_blank"><input type="hidden" name="saddr" value="' + marker.getPoint().lat() + ',' + marker.getPoint().lng() + '"><span class="googletext">Zieladresse (Straße Nr., Ort):</span><br><input type="text" class="googleinput" name="daddr" id="daddr" value=""><br><input value="Routenberechnung" type="submit" class="button" style="margin-top: .3em">');
}

// Show Address
function showAddress(address,html,x) {
  geocoder.getLatLng(
	address,
	function(point) {
	  if (!point) {
		alert(address + " not found");
	  } else {
		map.setCenter(point, 13);
		marker = new GMarker(point);
		map.addOverlay(marker);
		marker.openInfoWindowHtml(html+'<br><br>Routenberechnung: <a href="javascript:tohere('+x+')">Hierher</a> - <a href="javascript:fromhere('+x+')" class="googlelink">Von hier</a></span>');
	  }
	}
  );
}		

// Load Map
function load_google_maps(i)
{
	if (GBrowserIsCompatible())
	{
		// Map
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GScaleControl(), 
		new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(90, 10)));
		map.setCenter(new GLatLng(0,0),0);
		geocoder = new GClientGeocoder();	
	}
}

// Load
function stadtplan(x)
{
	if ( document.getElementById('map') ) document.getElementById('heimrich-hannot-de').removeChild(document.getElementById('map'));
	map = document.createElement('div');
	map.id='map';
	document.getElementById('heimrich-hannot-de').insertBefore(map,document.getElementById('standorte').nextSibling);
	window.location.hash='map';
	load_google_maps(x);
	showAddress(adresse[x]['adresse'], adresse[x]['html'],x);
}