var map 		= null;
var gDir 		= null;
var pathPanel 	= null;
var streetView 	= null;			
var geocoder 	= null;

//hashTable
var nameHash = new Array();
var imageHash = new Array();

nameHash["Augsburg, Ludwigstr.2"] = "Hotel Augusta<br>Entry Kesselmarkt<br><br>86152 Augsburg<br>Ludwigstr. 2"
nameHash["Frankfurt Flughafen"] = "Frankfurt Airport";
nameHash["Stuttgart Flughafen"] = "Stuttgart Airport";
nameHash["Munich Flughafen"] = "Munich Airport<p>From Munich Airport, you have to use the<br>tram or bus to Munich central station. There's no direct connection to Augsburg<p> (About 40 min, total time: about 1h 30min)";
nameHash["Paris Airport"] = "Paris Airport";
nameHash["Paris Center"] = "Paris Center";
nameHash["Salzburg Airport"] = "Salzburg Airport";
nameHash["Nuernberg Flughaben"] = "Nuernberg Airport";

imageHash["Augsburg, Ludwigstr.2"] = "files/h_augusta.jpg";
imageHash["Frankfurt Flughafen"] = "files/h_frankfurt.jpg";
imageHash["Stuttgart Flughafen"] = "files/h_stuttgart.jpg";
imageHash["Munich Flughafen"] = "files/h_munich.jpg";
imageHash["Paris Airport"] = "files/h_Paris.jpg";
imageHash["Paris Center"] = "files/h_ParisCenter.jpg";
imageHash["Salzburg Airport"] = "files/h_salzburg.jpg";
imageHash["Nuernberg Flughafen"] = "files/h_Nuernberg.jpg";

//var encPoints = "ilefHubmaAaBkHrCiCfBkb@m@yGyVbJeAcHqCXyBdE";
//var encLevel = "BBBBBBBBB"
				
function initGMap() 
{		
	if (GBrowserIsCompatible()) 
	{
		map = new GMap2(document.getElementById("map"));
		pathPanel = document.getElementById("route");
						
		gDir = new GDirections(map, pathPanel);
		GEvent.addListener(gDir, "load", onGDirectionLoad);
						
		map.setCenter(new GLatLng(48.36537369040198, 10.885562896728516), 13);
		map.addControl(new GLargeMapControl());
		geocoder = new GClientGeocoder();
		
		getAndShowAddress("Augsburg, Ludwigstr.2");
						
		//call standard onLoad()
		//count_amount();
    }
}		

function getAndShowAddress(address) 
{
	if (address == "")
		return;
				
	if (geocoder) 
	{
		geocoder.getLatLng(address, 
		function(point) 
		{
			if (!point) 
			{
				alert(address + " not found");
			} 
			else 
			{
				var string = "<h5>Location:</h5><br>" + 
				"<img src='" + imageHash[address] + "' width='75' height='75' border='0' align='right' alt=Grafik>" +
				nameHash[address]
								
				map.setCenter(point, 14);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(string);
				
				//setStreetView(point);
			}
		});
	}
}

function setStreetView(point)
{
	var ltPos = new GLatLng(point.x, point.y);
	svOptions = { latlng:ltPos };
	
	streeView = new GStreetviewPanorama(document.getElementById("m_StreeViewPanel"), svOptions);
	GEvent.addListener(streetView, "error", onStreetViewError);
}

function onStreetViewError(error)
{
	if (error == FLASH_UNAVAILABLE)
	{
		alert("Error: Flash doesn't appear to be supported by your browser");
		return;
	}
}

function calcRoute(from)
{
	gDir.load("from: " + from + " to: Augsburg, Ludwigstr.2", { "locale": "en_EN"});
}
				
function onGDirectionLoad()
{
					
}

function openRailTravellingSite()
{	
	var date = document.getElementById("m_Date").value;
	var time = document.getElementById("m_Time").value;
									
	if (date == "" || date == "dd/mm/yy") {
		alert("Please set date");
		return false;
	}
	if (time == "" || time == "hh/mm") {
		var curTime = new Date();
		time = "" + curTime.getHours() + "/" + curTime.getMinutes();
	}
				
	var control = document.getElementById("cb_StartingPoint");
	var id = document.getElementById("cb_StartingPoint").selectedIndex;
	var source = control.options[id].value;
					
	if (source == "")
	{
		alert("You must select a starting point");
		return;
	}	
	
	var query = "http://reiseauskunft.bahn.de/bin/query.exe/en?S=" + source + "!&Z=Augsburg Hauptbahnhof!&date=" + date + "&time=" + time + "&start=1";
	window.open(query,"Information","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes"); 
}
