// Intradus Google Maps Plugin
var directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();  
var map;

function initialize() {
	// Coordinates for map view
	var myLatlng = new google.maps.LatLng(parseFloat(IGMSettings.map_lat), parseFloat(IGMSettings.map_lng));
	
	// Options for map object
	var myOptions = {
		zoom: parseInt(IGMSettings.map_zoom),
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	
	// Create new map object
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	if (IGMSettings.marker_show == 'true')
	{
		// Coordinates for marker
		var myMarkerLatlng = new google.maps.LatLng(parseFloat(IGMSettings.marker_lat), parseFloat(IGMSettings.marker_lng));
		
		// Create new marker object
		var marker = new google.maps.Marker({
			position: myMarkerLatlng, 
			map: map,
			title: IGMSettings.marker_title
		});
		
		// Create new info window object
		var info = new google.maps.InfoWindow({
			content: IGMSettings.marker_content
		});
		
		// Open info window
		info.open(map, marker);
	}
	
	// Create new renderer object
	directionsDisplay.setMap(map);
	directionsDisplay.setPanel(document.getElementById("directionsPanel"));
}

function setDirections(fromAdress, toAdress) {
	// Create request
	var request = {
		origin: fromAdress, 
		destination: toAdress,
		travelMode: google.maps.DirectionsTravelMode.DRIVING
	};
	
	// Calculate route and show result
	directionsService.route(request, function(response, status) {
		if (status == google.maps.DirectionsStatus.OK) {
			directionsDisplay.setDirections(response);
		}
	});
}

window.onload = initialize;
window.onunload = GUnload;