<!-- début -->


var map;

function TextualZoomControl() {}
TextualZoomControl.prototype = new GControl();
TextualZoomControl.prototype.initialize = function(map)
	{
	var container = document.createElement("div");
	var zoomInDiv = document.createElement("div");
	this.setButtonStyle_(zoomInDiv);
	container.appendChild(zoomInDiv);
	zoomInDiv.appendChild(document.createTextNode("Agrandir 800"));
	GEvent.addDomListener(zoomInDiv, "click", function()
		{
		window.open('index_graphique_G.asp?t=800','zap','toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,history=no,resizable=no,width=800,height=600');
		});

	var plus = document.createElement("div");
	this.setButtonStyle_(plus);
	container.appendChild(plus);
	plus.appendChild(document.createTextNode("Agrandir 1024"));
	GEvent.addDomListener(plus, "click", function() 
		{
		window.open('index_graphique_G.asp?t=1024','zap','toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,history=no,resizable=no,width=1024,height=768');
		});

	map.getContainer().appendChild(container);
	return container;
	}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
TextualZoomControl.prototype.getDefaultPosition = function() 
	{
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
	}

// Sets the proper CSS for the given button element.
TextualZoomControl.prototype.setButtonStyle_ = function(button)
	{
	button.style.textDecoration = "underline";
	button.style.color = "#AA0000";
	button.style.backgroundColor = "#FFFFFF";
	button.style.font = "11px Verdana";
	button.style.weight = "bold";
	button.style.border = "1px solid black";
	button.style.padding = "2px";
	button.style.marginBottom = "3px";
	button.style.textAlign = "center";
	button.style.width = "6em";
	button.style.cursor = "pointer";
	}
var Center1 = new Array();
var Center2 = new Array();
var Zoom = new Array();

var existingMarkers = {};


Center1["1000"]	= '46.70973594407157';
Center2["1000"]	= ' -72.53173828125';
Zoom["1000"]		= '8';
	
Center1["2000"]	= '48.74894534343293';
Center2["2000"]	= ' -73.14697265625';
Zoom["2000"]		= '6';
	
Center1["3000"]	= '50.604159488560995';
Center2["3000"]	= ' -66.11572265625';
Zoom["3000"]		= '6';
	
Center1["4000"]	= '48.26125565204099';
Center2["4000"]	= ' -66.02783203125';
Zoom["4000"]		= '6';
	
Center1["5000"]	= '46.80428964656369';
Center2["5000"]	= ' -71.26968383789062';
Zoom["5000"]		= '10';
	
Center1["6000"]	= '46.48704700597017';
Center2["6000"]	= ' -75.9429931640625';
Zoom["6000"]		= '7';
	
Center1["7000"]	= '48.23199134320962';
Center2["7000"]	= ' -78.343505859375';
Zoom["7000"]		= '7';
	
Center1["8000"]	= '45.64092778836502';
Center2["8000"]	= ' -73.67431640625';
Zoom["8000"]		= '9';
	
Center1["9000"]	= '45.4947963896697';
Center2["9000"]	= ' -71.47979736328125';
Zoom["9000"]		= '8';
	
Center1["10000"]	= '46.13036330589103';
Center2["10000"]	= ' -74.3609619140625';
Zoom["10000"]		= '7';
	
Center1["11000"]	= '45.53136488027206';
Center2["11000"]	= ' -73.30078125';
Zoom["11000"]		= '8';
	

function loadCarteGoogle()
	{
		
	if (!GBrowserIsCompatible())
		{
		alert('Votre navigateur est incompatible avec l\'API de Google maps');
		return;
		}
	map = new GMap2(document.getElementById("map"));
	//doc	= document.location.href;
	//doc	= doc.toLowerCase();
	//if (doc.indexOf('graphique',0)<0) map.addControl(new TextualZoomControl());

	// Restreindre le ZOOM
	var mt = map.getMapTypes();
	for (var i=0; i<mt.length; i++)
		{
		mt[i].getMinimumResolution = function() {return 7;}
		mt[i].getMaximumResolution = function() {return 12;}
		}

	var parms = getQueryVariable("pk")
	if (parms)
		{
		Points	= new GLatLng(Center1[eval(parms)],Center2[eval(parms)]);
		Zoom2	= Zoom[eval(parms)];
		}
	else
		{
		if (PKRegion)
			{
			Points	= new GLatLng(Center1[eval(PKRegion)],Center2[eval(PKRegion)]);
			Zoom2	= Zoom[eval(PKRegion)];
			}
		else
			{
			Points	= new GLatLng(Center1[8000],Center2[8000]);
			Zoom2	= Zoom[8000];
			}
		}
	map.setCenter(Points, eval(Zoom2));
	map.addControl(new GLargeMapControl());
//	map.addControl(new GOverviewMapControl());
	map.enableScrollWheelZoom();

	// Create our "tiny" marker icon
	var baseIcon  = new GIcon();
	baseIcon .image = "/regions/routes1/img/marker-F.png";
	baseIcon .iconSize = new GSize(15, 26);
	baseIcon .iconAnchor = new GPoint(7, 26);
	baseIcon .infoWindowAnchor = new GPoint(5,10);

	updateMarkers();
	
	GEvent.addListener(map,'zoomend',function() 
		{
		updateMarkers();
		});
	GEvent.addListener(map,'moveend',function() 
		{
		updateMarkers();
		});

	function createMarker(point, number, IconeStr)
		{
		var number1	= number.replace(/ nbsp/g,"&nbsp;");
		var icon = new GIcon(baseIcon);
		icon.image = "/regions/routes1/img/"+IconeStr;
		var marker = new GMarker(point,icon);
		GEvent.addListener(marker, "click", function()
			{
			marker.openInfoWindowHtml("<p class='afficheINFO'>" + number1 + "</p>");
			});
		return marker;
		}

	function updateMarkers()
		{
		var bounds = map.getBounds();

		GDownloadUrl("/regions/routes1/_creeXMLAlaCarte.asp?d="+bounds, function(data, responseCode)
			{

			var xml = GXml.parse(data);
			var markers = xml.getElementsByTagName("marker");

			for(k in existingMarkers)
				{
				if(!bounds.contains(existingMarkers[k].getPoint()))
					{
					map.removeOverlay(existingMarkers[k]);
					delete existingMarkers[k];
					}
				}

			for (var i = 0; i < markers.length; i++)
				{
				var lat	= parseFloat(markers[i].getAttribute("lat"));
				var lng	= parseFloat(markers[i].getAttribute("lng"));
				
				var point = new GLatLng(lat,lng);

				if (!existingMarkers[i] && bounds.contains(point))
					{
					existingMarkers[i]	= createMarker(point, markers[i].getAttribute("descr").replace(/#\|#/g,"<br/>"), markers[i].getAttribute("marqueur"));
					map.addOverlay(existingMarkers[i]);
					/*alert( markers[i].getAttribute("lat"))
						map.addOverlay(new GMarker(point));*/
					}
				}
			});
		}

	}
	
function bougedela(coordonee)
	{
	var Coord=coordonee.split(',');
	if (Coord[0].length != 0)
		{
		map.setCenter(new GLatLng(Coord[0],Coord[1]),eval(Coord[2]));
		}
	}

var qsParm = new Array();

function getQueryVariable(variable)
	{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++)
		{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
			{
			return pair[1];
			}
		} 
	}


