var map;
var center = new google.maps.LatLng(54.48143,9.04629);
var myLocation;
var directionsService;
var directionsDisplay;

function initialize() {
	
	// Map
	var myOptions = { zoom: 14, center: center, mapTypeId: google.maps.MapTypeId.ROADMAP };
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	var image = 'index/img/hotel_icon.png';
	var cinema_image = 'index/img/cinema_icon.png';
	
	// Jever-Stube
	pos = new google.maps.LatLng(54.47743153756406,9.049623424652111);
	marker1 = new google.maps.Marker({position: pos, map: map,icon: image, title: ''});
	infowindow1 = new google.maps.InfoWindow({content: "<b>Jever-Stube</b> Hotel und Restaurant<br/>Großstr. 10, 25813 Husum<br/>Tlf. 04841 62900<br/><a href='http://www.jever-stube.de/' target='_blank'>www.jever-stube.de/</a>"});
	google.maps.event.addListener(marker1, 'click', function(){ infowindow1.open(map,this); });
	
	// Wohlert
	pos = new google.maps.LatLng(54.47717,9.05149);
	marker2 = new google.maps.Marker({position: pos, map: map,icon: image, title: ''});
	infowindow2 = new google.maps.InfoWindow({content: "<b>Hotel Wohlert</b><br/>Markt 30, D-25813 Husum<br/>Tlf. +49 (0) 4841 2229<br/><a href='http://www.hotel-wohlert.de' target='_blank'>www.hotel-wohlert.de</a>"});
	google.maps.event.addListener(marker2, 'click', function(){ infowindow2.open(map,this); });
	
	// Schloßpark
	pos = new google.maps.LatLng(54.482069,9.044495);
	marker3 = new google.maps.Marker({position: pos, map: map,icon: image, title: ''});
	infowindow3 = new google.maps.InfoWindow({content: "<b>Hotel am Schloßpark</b> ***<br/>Hinter der Neustadt 74-86, 25813 Husum<br/>Tlf. +49 (0) 4841 2022<br/><a href='http://www.hotel-am-schlosspark-husum.de' target='_blank'>www.hotel-am-schlosspark-husum.de</a>"});
	google.maps.event.addListener(marker3, 'click', function(){ infowindow3.open(map,this); });
	
	// Altes Gym
	pos = new google.maps.LatLng(54.475674,9.052777);
	marker4 = new google.maps.Marker({position: pos, map: map,icon: image, title: ''});
	infowindow4 = new google.maps.InfoWindow({content: "<b>Romantikhotel Altes Gymnasium</b> *****<br/>Süderstrasse 2-10, 25813 Husum<br/>Tlf. +49 (0) 4841 8330<br/>Telefax +49 (0) 4841 83312<br/><a href='http://www.altes-gymnasium.de' target='_blank'>www.altes-gymnasium.de</a>"});
	google.maps.event.addListener(marker4, 'click', function(){ infowindow4.open(map,this); });
	
	// Hostel
	pos = new google.maps.LatLng(54.489436,9.038572);
	marker5 = new google.maps.Marker({position: pos, map: map,icon: image, title: ''});
	infowindow5 = new google.maps.InfoWindow({content: "<b>Youth Hostel</b> Jugendherberge Husum<br/>Schobüller Str. 34, 25813 Husum<br/>Tlf. +49 (0) 4841 2714<br/><a href='http://www.jugendherberge.de/jh/husum' target='_blank'>www.jugendherberge.de/jh/husum</a>"});
	google.maps.event.addListener(marker5, 'click', function(){ infowindow5.open(map,this); });
	
	// Husum Hus
	pos = new google.maps.LatLng(54.481084,9.046962);
	marker6 = new google.maps.Marker({position: pos, map: map, title: ''});
	infowindow6 = new google.maps.InfoWindow({content: "<b>HUSUM HUS</b><br/>Neustadt 95, 25813 Husum"});
	google.maps.event.addListener(marker6, 'click', function(){ infowindow6.open(map,this); });
	
	// Kino Center
	marker = new google.maps.Marker({position: center, map: map,icon: cinema_image, title: 'European Minority Film Festival'});
	infowindow = new google.maps.InfoWindow({content: '<b>Kino Center Husum<'+'/b><br/>Neustadt 114, D-25813 Husum<br/>Phone +49 (0) 4841 2569'});
	google.maps.event.addListener(marker, 'click', function(){ infowindow.open(map,this); });
	infowindow.open(map,marker);
	
	// Directions
	directionsService = new google.maps.DirectionsService();
	directionsDisplay = new google.maps.DirectionsRenderer();
	directionsDisplay.setPanel(document.getElementById("map_directions"));
	
	//$(".section#map").hide();
}

function show(id) {
	$("#menu li").removeClass("active");
	$("#menu li#"+id).addClass("active");
	$(".section").slideUp();
	$(".section#"+id).slideDown();
}
function toggle(id) {
	$("#"+id).slideToggle();
}

function find_route() {
	raw_address = $("input#location").val();
	var geocoder = new google.maps.Geocoder();
	geocoder.geocode({'address': raw_address}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			if (results[0]) {
				//new_address = results[0].formatted_address;
				var request = {
					origin: results[0].geometry.location,
					destination: center,
					travelMode: google.maps.DirectionsTravelMode.DRIVING
				};
				directionsService.route(request,function(result,status) {
					if (status == google.maps.DirectionsStatus.OK) {
						directionsDisplay.setMap(map);
						directionsDisplay.setDirections(result);
					}
				});
			}
		}
	});
	
}



