﻿var map;
var geocoder;
var polyline = false;

function load_map() {
	map = new GMap2($("map"));
	map.setCenter(new GLatLng(34, 0), 15);
	//map.setMapType(G_HYBRID_MAP);
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	//map.setCenter(new GLatLng(48.856667, 2.350987), 15);
	geocoder = new GClientGeocoder();
}

//------------------------------------------------------------------------------------API
/*
itinerary = false;
start_addr = '';
end_addr  = '';
*/
function erazeLines (conserve_itinerary) {
	if (itinerary && !conserve_itinerary) {
		itinerary.clear();
	}
	if (polyline) {
		map.removeOverlay(polyline);
		polyline = null;
	}
}
function erazeMarkers () {
	map.clearOverlays();
}

function showDrivingItinerary(start_addr, end_addr, onSuccessItinerary, onFailledItinerary) {
	driving_itinerary_Panel = $('itinerary_panel_drive');
	//erazeMarkers();
	//erazeLines ();
	//alert(onSuccessItinerary);
	var itinerary = new GDirections(map, driving_itinerary_Panel);
	
	if (start_addr.length && end_addr.length) {
		G_DEFAULT_ICON.image = "http://media.interfaces.fr/www/media/map/dot.gif";
		G_DEFAULT_ICON.shadow = "http://media.interfaces.fr/www/media/map/dot.gif";
		G_DEFAULT_ICON.iconSize = new GSize(1, 1);
		G_DEFAULT_ICON.shadowSize = new GSize(1, 1);
		//G_END_ICON.image = "http://media.interfaces.fr/www/media/map/dot.gif";
		t_addr_f_road_itinerary = new Array();
		t_addr_f_road_itinerary[0] = start_addr;
		t_addr_f_road_itinerary[1] = end_addr;
		//alert(t_addr_f_road_itinerary)
	
		GEvent.addListener(itinerary, "error", function() {
                        if (onFailledItinerary) {
                        	onFailledItinerary();
                        }
                  }); 
	
		GEvent.addListener(itinerary, "load", function() {
                        //alert("Directions Failed: "+itinerary.getStatus().code);
                        
                        if (onSuccessItinerary) {
                        	get_driving_center = function () {
								 current_zoom = map.getZoom();
								 bounds = map.getBounds();
								 southWest = bounds.getSouthWest();
								 northEast = bounds.getNorthEast();
								 center_lng = (northEast.lng() + southWest.lng()) / 2;
								 center_lat = (northEast.lat() + southWest.lat()) / 2;
								//alert(bounds + '\n' + center_lng + '\n' + center_lat + '\n');
							}
                        	setTimeout(get_driving_center, 100);

                        	//onSuccessItinerary();
                        	setTimeout(onSuccessItinerary, 110);
                        	
                        	setdrivingcenter = function () {
                        		map.setCenter(new GLatLng(center_lat, center_lng), current_zoom);
                        	}
                        	setTimeout(setdrivingcenter, 2000)
                        }
                        
                        /*alert(bounds + '\n')
                        alert(lngSpan + ' = ' + northEast.lng() + ' - ' + southWest.lng());
                        alert(latSpan + ' = ' + northEast.lat() + ' - ' + southWest.lat());*/
						//map.setCenter(new GLatLng(center_lat, center_lng), current_zoom);
						

                        
                        //alert(itinerary.getRoute(0).numSteps);
                        /*var html_description = '';
                        i = 0;
                        while (itinerary.getRoute(0).getStep(i)) {
                        	var step = itinerary.getRoute(0).getStep(i);
                        	var description = step.getDescriptionHtml();
                        	html_description += description + '<br />' + "\n";
                        	i++;
                        } */
                  }); 
		itinerary.loadFromWaypoints(t_addr_f_road_itinerary, { "locale": "fr_FR"});
	}
	else {
		alert('Verify showDrivingItinerary() entry!');
	}
}

function changeItineraryColor () {
	temp_text = $('itinerary_panel_walk').innerHTML;
	pedestrian_itinerary_temp.clear()
	$('itinerary_panel_walk').innerHTML = temp_text;
}

function showWalkingItinerary(start_addr, end_addr, onSuccessItinerary, onFailledItinerary) {
	walking_itinerary_Panel = $('itinerary_panel_walk');
	var pedestrian_itinerary = new GDirections(map, walking_itinerary_Panel);
	//alert(onSuccessItinerary);
	
	if (start_addr.length && end_addr.length) {
		G_DEFAULT_ICON.image = "http://media.interfaces.fr/www/media/map/dot.gif";
		G_DEFAULT_ICON.shadow = "http://media.interfaces.fr/www/media/map/dot.gif";
		G_DEFAULT_ICON.iconSize = new GSize(1, 1);
		G_DEFAULT_ICON.shadowSize = new GSize(1, 1);
		//G_END_ICON.image = "http://media.interfaces.fr/www/media/map/dot.gif";
		t_addr_f_pedestrian_itinerary = new Array();
		t_addr_f_pedestrian_itinerary[0] = start_addr;
		t_addr_f_pedestrian_itinerary[1] = end_addr;
		//alert(t_addr_f_pedestrian_itinerary)
		
		GEvent.addListener(pedestrian_itinerary, "error", function() {
						//alert("Directions Failed: "+pedestrian_itinerary.getStatus().code + "\n\n" + start_addr + "\n" + end_addr);
						//verifLocation(start_addr);
					if (onFailledItinerary) {
						onFailledItinerary();
					}
                  }); 
		
		GEvent.addListener(pedestrian_itinerary, "load", function() {
				i_polyline = 0;
				var poly = pedestrian_itinerary.getPolyline().copy();
				//newpoly = poly;
				pedestrian_itinerary_temp = pedestrian_itinerary;
				setTimeout("changeItineraryColor()", 1000);
				var points = new Array();
				for (var i = 0; i < poly.getVertexCount(); i++) { 
					points[i] = poly.getVertex(i); 
				} 
				var newpoly = new GPolyline(points, "#00bb00", 4); 
				map.addOverlay(newpoly);
				
				if (onSuccessItinerary) {
					onSuccessItinerary();
				}
				//alert(itinerary.getRoute(0).numSteps);
				/*var html_description = '';
				i = 0;
				while (itinerary.getRoute(0).getStep(i)) {
					var step = itinerary.getRoute(0).getStep(i);
					var description = step.getDescriptionHtml();
					html_description += description + '<br />' + "\n";
					i++;
				} */
			}); 
		//$('itinerary_panel').innerHTML += "<br />pedestrian_itinerary.loadFromWaypoints(" + t_addr_f_pedestrian_itinerary + ", {getPolyline:true,travelMode:G_TRAVEL_MODE_WALKING});";
		pedestrian_itinerary.loadFromWaypoints(t_addr_f_pedestrian_itinerary, {getPolyline:true,travelMode:G_TRAVEL_MODE_WALKING, "locale": "fr_FR"});
		//alert(google_request);
		//pedestrian_itinerary.load(google_request, {travelMode:G_TRAVEL_MODE_DRIVING});
		//pedestrian_itinerary.load(google_request);

	}
	else {
		alert('Verify showWalkingItinerary() entry!');
	}
}

activateMarker_isRunning = false;
total_marker = false;
function activateMarker (t, valid_finished, valid_marker) {//useful only if some markers do not have lat & lng set
	/*if (activateMarker_isRunning) {
		alert('Application try to run more than one instance of activateMarker().');
		return false;
	}*/
	activateMarker_isRunning = true;
		
	if (!total_marker) {
		total_marker = t.length;
		total_ok     = 0;
	}
	delayt_between_check = 100;
	t_marker = t;
	new_t = new Array();
	new_t_key = 0;
	for (a = 0 ; a < t_marker.length ; a++) {
		if (false == t_marker[a].status/* && t_marker[a].tryToAddPoint <= 100*/) {
			setTimeout('t_marker[' + a + '].addr2point()', a * delayt_between_check);
			new_t[new_t_key] = t_marker[a]
			new_t_key++;
		}
		else if (true == t_marker[a].status) {
			total_ok++;
			if (valid_marker) {
				percent_progress = Math.ceil(total_ok / total_marker * 100);
				valid_marker(percent_progress);
			}
		}
	}
	if (new_t.length > 0) {
		time2wait = t_marker.length * delayt_between_check;
		setTimeout('activateMarker_isRunning = false;activateMarker(new_t, ' + valid_finished + ', ' + valid_marker + ')', time2wait);
	}
	else {
		if (valid_marker) {
			valid_marker(100);
		}
		if (valid_finished) {
			valid_finished();
		}
		total_marker = false;
		activateMarker_isRunning = false;
	}
	
}

function mapMarker (addr, printed_addr, window_content, marker_options, onload_icon, onload_window, lat, lng) {//lat & lng are optional. Set ONLY if values are sure (get_addr_point.php?addr=...)
	this.goToAddr = function (to_addr, travel_mode_pedestrian, keep_map_intact) {
		if (!keep_map_intact) {
			map.clearOverlays();
		}
		if (travel_mode_pedestrian) {
			showWalkingItinerary(this.addr, to_addr);
		}
		else {
			showDrivingItinerary(this.addr, to_addr);
		}
	}
	
	this.driveToMarker = function (to_marker, keep_map_intact, onSuccessItinerary, onFailledItinerary) {
		this.goToMarker(to_marker, false, keep_map_intact, onSuccessItinerary, onFailledItinerary);
	}
	
	this.walkToMarker = function (to_marker, keep_map_intact, onSuccessItinerary, onFailledItinerary) {
		this.goToMarker(to_marker, true, keep_map_intact, onSuccessItinerary, onFailledItinerary);
	}
	
	this.goToMarker = function (to_marker, travel_mode_pedestrian, keep_map_intact) {
		if (!keep_map_intact) {
			map.clearOverlays();
		}
		to_addr = to_marker.addr
		to_marker.loadIcon();
		this.goToAddr(to_addr, travel_mode_pedestrian, true);
	}
	
	this.refreshMarker = function () {
		this.point = new GLatLng(this.lat, this.lng);
		if (this.marker_options) {
			this.marker = new GMarker(this.point, this.marker_options);
		}
		else {
			this.marker = new GMarker(this.point);
		}
	}
	
	this.checkStatus = function () {
		if (!this.status) {
			alert("ERROR :\n" + "Unsuable marker\n" + '"' + this.printed_Addr + '"' + " not set correctly.");
			
		}
	}
	if (onload_icon) {
		this.loadedIcon = function () {
			setTimeout(onload_icon[0], onload_icon[1])
		}
	}
	else {
		this.loadedIcon = function () {};
	}
	
	if (onload_window) {
		this.openedWindow = function () {
			setTimeout(onload_window[0], onload_window[1])
		};
	}
	else {
		this.openedWindow = function () {};
	}
	
	this.loadIcon = function (additional_content) {
		var total_content = this.window_content;
		if (additional_content) {
			total_content += additional_content;
		}
		map.addOverlay(this.marker);
		var this_marker = this;
		GEvent.addListener(this.marker, "click", function() {
			this_marker.openWindow(additional_content);
			this_marker.loadedIcon();
		});
		this.loadedIcon();
	}
	this.openWindow = function (additional_content) {
		var total_content = this.window_content;
		if (additional_content) {
			total_content += additional_content;
		}
		this.loadIcon(additional_content);
		this.marker.openInfoWindowHtml(total_content);
		this.openedWindow();
	}
	this.centerToThis = function (zoom) {
		map.setCenter(this.point);
	}
	this.actualLatLng = function () {
		alert('lat = ' + this.lat + "\n" + 'lng = ' + this.lng);
	}
	this.markerDetails = function () {
		details_text  = 'status : ' + "\n\t" + this.status + "\n";
		details_text += 'lat : ' + "\n\t" + this.lat + "\n";
		details_text += 'lng : ' + "\n\t" + this.lng + "\n";
		details_text += 'addr : ' + "\n\t" + this.addr + "\n";
		details_text += 'printed_addr : ' + "\n\t" + this.printed_addr + "\n";
		
		return details_text;
	}
	this.addr2point = function () {
		this.tryToAddPoint++;
		url = 'get_addr_point.php?addr=' + this.addr;
		var objMarker = this;
		new Ajax.Request(url, {method: 'get'
		,onComplete: function(transport) {
				if (transport.responseText.length && '0' != transport.responseText) {
					t_latlng = transport.responseText.split(',');
					objMarker.lat = t_latlng[0];
					objMarker.lng = t_latlng[1];
					objMarker.refreshMarker();
					objMarker.status = true;
				}
			}
		});
	}
	this.addr = addr;
	this.printed_addr = printed_addr;
	this.window_content  = window_content;
	this.marker_options  = marker_options;
	this.onload_icon     = onload_icon;
	this.onload_window   = onload_window;
	this.zoom = 15;
	this.tryToAddPoint = 0;
	if (lat && lng) {
		this.lat    = lat;
		this.lng    = lng;
		this.refreshMarker();
		this.status = true;
	}
	else {
		this.lat    = false;
		this.lng    = false;
		this.status = false;
	}
	
}

//-------------------------INTERFACES SITE PARAMETERS

function setSmallIcon (color) {
	var smallIcon = new GIcon(); 
	if (!color) {
		color= 'red'; 
	}
	smallIcon.image = 'http://labs.google.com/ridefinder/images/mm_20_' + color + '.png';
	smallIcon.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	smallIcon.iconSize = new GSize(12, 20);
	smallIcon.shadowSize = new GSize(22, 20);
	smallIcon.iconAnchor = new GPoint(6, 20);
	smallIcon.infoWindowAnchor = new GPoint(5, 1);
	markerOptions = { icon:smallIcon }; 
	
	return markerOptions;
}

function setVelibIcon () {
	var IFIcon = new GIcon();
	IFIcon.image = "http://media.interfaces.fr/www/media/map/picto_velib.gif";
	IFIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	IFIcon.iconSize = new GSize(12, 20);
	IFIcon.shadowSize = new GSize(22, 20);
	IFIcon.iconAnchor = new GPoint(6, 20);
	IFIcon.infoWindowAnchor = new GPoint(5, 1);
	markerOptions = { icon:IFIcon }; 
	
	return markerOptions;
}

function setInterFacesIcon () {
	var IFIcon = new GIcon();
	IFIcon.image = "http://media.interfaces.fr/www/media/map/puce16.png";
	//IFIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	IFIcon.iconSize = new GSize(16, 16);
	IFIcon.shadowSize = new GSize(16, 16);
	IFIcon.iconAnchor = new GPoint(6, 6);
	IFIcon.infoWindowAnchor = new GPoint(8, 1);
	markerOptions = { icon:IFIcon }; 
	
	return markerOptions;
}

function verifyZoomLevel (required_zoom) {
	actual_zoom = map.getZoom();
	if (actual_zoom != required_zoom) {
		map.setZoom(required_zoom);
	}
}

function alertIfNotFound(response) {
	if (!response || response.Status.code != 200) {
		message = 'Google n\'est pas capable de g&eacute;olocaliser l\'adresse "' + response.name + '"';
		$('link_detailed_map').innerHTML = '<span class="error">' + message + '</span>';
	}
	else {
		message = 'Google n\'est pas capable de cr&eacute;er un itin&eacute;raire avec l\'adresse "' + response.name + '"';
		$('link_detailed_map').innerHTML = '<span class="error">' + message + '</span>';
	}
}

function verifLocation(address) {
	geocoder.getLocations(address, alertIfNotFound);
}

actual_velib_sation = false;
function getVelibStationStatus (station_number) {
	$('station_status_' + station_number).innerHTML = '<img src="http://media.interfaces.fr/www/media/a_loading_small.gif" />';
	url_submited = 'velib/station_status.html?station=' + station_number;
	new Ajax.Request (url_submited, 
	                  {method:'get', 
	                   onComplete:function (transport) {
	                              	html_content = transport.responseText
	                              	$('station_status_' + station_number).innerHTML = html_content;
	                              }
	                 });
}
function itineraryDetailLink (start_addr, end_addr) {
	return '<a href="http://maps.google.fr/maps?saddr=' + start_addr + '&daddr=' + end_addr + '" onclick="showItinerarySteps();return false;">Voir les d&eacute;tails du parcours</a>';
}
function itineraryLegend (is_driving, is_walking) {
	var legend_text = '';
	legend_text += '<div style="float:left;clear:right;">';
	if (is_driving) {
		legend_text += "<span class=\"legend_color_road\"></span>&nbsp;itin&eacute;raire routier<br />";
	}
	if (is_walking) {
		legend_text += "<span class=\"legend_color_pedestrian\"></span>&nbsp;itin&eacute;raire pi&eacute;ton";
	}
	//alert(legendtext)
	legend_text += '</div>';
	
	return legend_text;
}

map_hide = false;
function submitIfReady () {
	if (true == map_hide) {
		load_map();
		map_hide = false;
	}
	$('link_detailed_map').innerHTML = '<img src=\"http://media.interfaces.fr/www/media/a_loading_small.gif\" />';
	$('itinerary_panel_drive').innerHTML = '';
	$('itinerary_panel_walk').innerHTML = '';
	input_object = $('f_start_address');
	marker_selected = $('f_end_address').value;
	if (input_object.value.length != 0/* && marker_selected >= 0 && marker_selected < */) {
		map.clearOverlays();
		start_addr = input_object.value;
		end_addr   = t_map_marker[marker_selected].addr;
		showSuccess = function () {
			google_addr    = start_addr;
			printed_addr   = start_addr;
			if (0 != marker_selected) {
				driving_itinerary = true;
				walking_itinerary = true;
			}
			else {
				driving_itinerary = true;
				walking_itinerary = false;
			}
			
			window_content = '<fieldset><legend>Point de d&eacute;part</legend><strong>' + start_addr + '</strong></fieldset><p>' + itineraryDetailLink (start_addr, end_addr) + itineraryLegend (driving_itinerary, walking_itinerary) + '</p></div>';
			//window_content += '<p><a href="#" onclick="showItinerarySteps()">Voir les &eacute;tapes</a></p>'
			//marker_option  = setSmallIcon();
			t_start_point = Array(new mapMarker(google_addr, printed_addr, window_content, setSmallIcon('red')));
			fct_start_loaded = function () {
				t_start_point[0].loadIcon();
				t_map_marker[marker_selected].openWindow(itineraryLegend (driving_itinerary, walking_itinerary));
			}
			activateMarker (t_start_point, fct_start_loaded, false);
			$('link_detailed_map').innerHTML = itineraryDetailLink (start_addr, end_addr);
			if (0 != marker_selected) {
				t_map_marker[marker_selected].goToMarker(t_map_marker[0], true, true, t_map_marker[0].loadIcon);
			}
			else {
				t_map_marker[0].loadIcon(/*itineraryLegend (driving_itinerary, walking_itinerary)*/);
			}
		}
		showFailled = function () {
			verifLocation(start_addr);
		}
		showDrivingItinerary(start_addr, end_addr, showSuccess, showFailled);
	}
	else {
		document.getElementById('link_detailed_map').innerHTML = '<span class="error">Saisissez une adresse de d&eacute;part !</span>';
	}
}

map_hide = false;
function showItinerarySteps () {
	if (false == map_hide) {
		map_content = $('map').innerHTML;
		$('map').innerHTML = $('itinerary_panel_drive').innerHTML + $('itinerary_panel_walk').innerHTML + '<p><a href="#" onclick="$(\'map\').scrollTop=0;return false;">D&eacute;but du parcours</a></p>';
		$('link_detailed_map').innerHTML = '<a href="#" onclick="showItineraryMap();return false;">Retour à la carte</a>';
		map_hide = true;
	}
}

function showItineraryMap () {
	load_map();
	input_object.value = start_addr;
	submitIfReady();
}

function walkToInterFaces (marker_number) {
	verifyZoomLevel (16)
	t_map_marker[marker_number].goToMarker(t_map_marker[0], true);
	driving_itinerary = false;
	walking_itinerary = true;
	t_map_marker[marker_number].openWindow(itineraryLegend (driving_itinerary, walking_itinerary));
	
	return true;
}


load_map();

station_status_loading = "<img src=\"http://media.interfaces.fr/www/media/a_loading_small.gif\" />";

t_map_marker = new Array();
num_marker = -1;

num_marker++;//0
google_addr    = "16 rue de la fontaine au roi 75011 Paris France";
printed_addr   = "InterFaces, 16 rue de la fontaine, Paris 11&egrave;me";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/interfaces.jpg\" width=\"97\" height=\"71\" /></td><td>InterFaces<br />16 rue de la fontaine au roi<br />75011 Paris</td></tr></table>";
marker_option  = setInterFacesIcon();
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, false, 48.8684192, 2.3701384);

num_marker++;//1
google_addr    = "Station Goncourt 75011 Paris France";
printed_addr   = "Station Goncourt";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/ratp.png\" width=\"50\" height=\"60\" /></td><td>Station Goncourt<br /><img class=\"metro\" src=\"http://media.interfaces.fr/www/media/map/metro/11.png\" alt=\"Ligne 11\" /></td></tr></table>";
marker_option  = setSmallIcon('green');
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, false, 48.8699655, 2.3709226);

num_marker++;//2
google_addr    = "Place de la R&eacute;publique 75011 Paris France";
printed_addr   = "Station R&eacute;publique";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/ratp.png\" width=\"50\" height=\"60\" /></td><td>Station R&eacute;publique<br /><img class=\"metro\" src=\"http://media.interfaces.fr/www/media/map/metro/03.png\" alt=\"Ligne 3\" /><img class=\"metro\" src=\"http://media.interfaces.fr/www/media/map/metro/05.png\" alt=\"Ligne 5\" /><img class=\"metro\" src=\"http://media.interfaces.fr/www/media/map/metro/08.png\" alt=\"Ligne 8\" /><img class=\"metro\" src=\"http://media.interfaces.fr/www/media/map/metro/09.png\" alt=\"Ligne 9\" /><img class=\"metro\" src=\"http://media.interfaces.fr/www/media/map/metro/11.png\" alt=\"Ligne 11\" /></td></tr></table>";
marker_option  = setSmallIcon('green');
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, false, 48.8675034, 2.3638109);

num_marker++;//3
google_addr    = "11 rue des Trois Bornes 75011 Paris France";
printed_addr   = "Garage des trois bornes";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/parking.png\" /></td><td>Garage des trois bornes<br />11 rue des trois bornes<br />75011 Paris</td></tr></table>";
marker_option  = setSmallIcon('blue');
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, false, 48.8663861, 2.3718720);

num_marker++;//4
google_addr    = "46 Rue Oberkampf 75011 Paris";
printed_addr   = "Garage Oberkampf";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/parking.png\" /></td><td>Garage Oberkampf<br />46 rue Oberkampf<br />75011 Paris</td></tr></table>";
marker_option  = setSmallIcon('blue');
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, false, 48.8646348, 2.3723722);

num_marker++;//5
google_addr    = "50 rue de Malte 75011 Paris France";
printed_addr   = "Vinci Park Services";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/parking.png\" /></td><td>Vinci Park Services<br />50 rue de Malte<br />75011 Paris</td></tr></table>";
marker_option  = setSmallIcon('blue');
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, false, 48.8667475, 2.3668566);

num_marker++;//6
num_velib_station = 11034;
google_addr    = "124 avenue Parmentier 75011 Paris France";
printed_addr   = "124 avenue Parmentier";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/velib.png\" /></td><td>140 avenue Parmentier<br />75011 Paris</td></tr></table><div id=\"station_status_" + num_velib_station + "\" class=\"station_status\">" + station_status_loading + "</div>";
marker_option  = setVelibIcon();
onload_window = new Array('getVelibStationStatus(' + num_velib_station + ')', 1000);
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, onload_window, 48.8680433, 2.3724710);

num_marker++;//7
num_velib_station = 11036;
google_addr    = "28 rue Jules Ferry 75011 Paris France";
printed_addr   = "28 rue Jules Ferry";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/velib.png\" /></td><td>28 rue Jules Ferry<br />75011 Paris</td></tr></table><div id=\"station_status_" + num_velib_station + "\" class=\"station_status\">" + station_status_loading + "</div>";
marker_option  = setVelibIcon();
onload_window = new Array('getVelibStationStatus(' + num_velib_station + ')', 1000);
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, onload_window, 48.8687461, 2.3676697);

num_marker++;//7
num_velib_station = 11035;
google_addr    = "140 avenue Parmentier 75011 Paris France";
printed_addr   = "140 avenue Parmentier";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/velib.png\" /></td><td>140 avenue Parmentier<br />75011 Paris</td></tr></table><div id=\"station_status_" + num_velib_station + "\" class=\"station_status\">" + station_status_loading + "</div>";
marker_option  = setVelibIcon();
onload_window = new Array('getVelibStationStatus(' + num_velib_station + ')', 1000);
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, onload_window, 48.8692150, 2.3716013);

num_marker++;//9
num_velib_station = 11109;
google_addr    = "1 rue de la pierre lev&eacute;e 75011 Paris France";
printed_addr   = "1 rue de la pierre lev&eacute;e";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/velib.png\" /></td><td>1 rue de la pierre lev&eacute;e<br />75011 Paris</td></tr></table><div id=\"station_status_" + num_velib_station + "\" class=\"station_status\">" + station_status_loading + "</div>";
marker_option  = setVelibIcon();
onload_window = new Array('getVelibStationStatus(' + num_velib_station + ')', 1000);
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, onload_window, 48.8662504, 2.3711800);

/*num_marker++;//10
num_velib_station = 11113;
google_addr    = "140 boulevard richard Lenoir 75011 Paris France";
printed_addr   = "140 boulevard richard lenoir";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/velib.png\" /></td><td>140 boulevard richard lenoir paris<br />75011 Paris</td></tr></table><div id=\"station_status_" + num_velib_station + "\" class=\"station_status\">" + station_status_loading + "</div>";
marker_option  = setVelibIcon();
onload_window = new Array('getVelibStationStatus(' + num_velib_station + ')', 1000);
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, onload_window, 48.8665799, 2.3693471);

num_marker++;//11
num_velib_station = 11039;
google_addr    = "121 boulevard Richard Lenoir 75011 Paris France";
printed_addr   = "121 boulevard Richard Lenoir";
window_content = "<table><tr><td><img class=\"logo\" src=\"http://media.interfaces.fr/www/media/map/velib.png\" /></td><td>121 boulevard Richard Lenoir<br />75011 Paris</td></tr></table><div id=\"station_status_" + num_velib_station + "\" class=\"station_status\">" + station_status_loading + "</div>";
marker_option  = setVelibIcon();
onload_window = new Array('getVelibStationStatus(' + num_velib_station + ')', 1000);
t_map_marker[num_marker] = new mapMarker(google_addr, printed_addr, window_content, marker_option, false, onload_window, 48.8656716,2.3693578);*/


validFinished = function finalize_page () {
	t_map_marker[0].centerToThis();t_map_marker[0].openWindow();
};
$('itinerary_panel_drive').show();
$('itinerary_panel_walk').show();
activateMarker (t_map_marker, validFinished);
//-----------------------------------------------------------------

if (navigator.geolocation) {
	function addLocInfo (position) {
		var latitude = position.coords.latitude;
		var longitude = position.coords.longitude;
		function reverse (addresses) {
			if (addresses.Status.code == 200) {
				var address = addresses.Placemark[0].address;
				$('f_start_address').value = address;
			}
			else {
				alert(addresses.Status.code);
			}
		};
		if (typeof(geocoder) != 'undefined') {
			geocoder.getLocations(new GLatLng(latitude,longitude),reverse);
		}
	}
	function handleError (error) {
		var errorMessage;
		var code = error.code;
		switch (code) {
			case error.PERMISSION_DENIED:
				errorMessage = "Permission denied";
				break;
			case error.POSITION_UNAVALAIBLE:
				errorMessage = "Position unavalaible";
				break;
			case error.TIMEOUT:
				errorMessage = "Timeout";
				break;
			case error.UNKNOWN_ERROR:
				errorMessage = "Unknown error";
				break;
		}
	}
	
	//navigator.geolocation.watchPosition(addLocInfo, handleError, {enableHighAccuracy:true,timeout:5000,maximumAge:60000});
	navigator.geolocation.getCurrentPosition(addLocInfo, handleError, {enableHighAccuracy:true,timeout:5000,maximumAge:60000});
	try {
		var geocoder = new GClientGeocoder();
	}
	catch (err) {}
	
}
