// JavaScript Document
//déclaration des variables
var map = null;
var geocoder = null;
var etbl = null;
var etbl1 = null;
var good = "true";


function recupereArray(tableau,tableau2)
{
	etbl = tableau;
	etbl1 = tableau2;
	map.clearOverlays();
	createMarkersEtbl(1);
}

function recupereArray2(tableau,tableau2)
{
	etbl = tableau;
	etbl1 = tableau2;
	mapBig.clearOverlays();
	createMarkersEtbl2(1);
}

//la fonction createMarkersEtbl fonctionne semsiblement de la même manière que la fonction createMarkerPays a l'exception de mgr.refresh à la fin
function createMarkersEtbl(i) {
	geocoder.getLatLng(etbl1[i][0],function(point) {
		if (point)
		{
			good = "true";
			var baseIcon      = new GIcon(G_DEFAULT_ICON);
				
			baseIcon.image      = "icon-home.png";
				
			baseIcon.iconSize   = new GSize(26, 21);
			baseIcon.iconAnchor = new GPoint(-5, 14);
			baseIcon.shadow     = "";
			var markerOptions = { icon:baseIcon, title:etbl[i][2] };
			var marker=new GMarker(point, markerOptions);
			
			var infoTabs = [
				new GInfoWindowTab("Informations", etbl[i][0])
			];
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowTabsHtml(infoTabs);
			});
			
			map.addOverlay(marker);
		}
		else
		{
			withAdress(etbl[i][1],"non",i);
		}
	});
	
	z=i+1;
	
	if (z<etbl.length) {
		setTimeout("createMarkersEtbl("+z+")",300);
	}
}

function createMarkersEtbl2(i) {
	geocoder.getLatLng(etbl1[i][0],function(point) {
		if (point)
		{
			good = "true";
			var baseIcon      = new GIcon(G_DEFAULT_ICON);
				
			baseIcon.image      = "icon-home.png";
				
			baseIcon.iconSize   = new GSize(26, 21);
			baseIcon.iconAnchor = new GPoint(0, 14);
			baseIcon.shadow     = "";
			var markerOptions = { icon:baseIcon, title:etbl[i][2] };
			var marker=new GMarker(point, markerOptions);
			
			var infoTabs = [
				new GInfoWindowTab("Informations", etbl[i][0])
			];
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowTabsHtml(infoTabs);
			});
			
			mapBig.addOverlay(marker);
		}
		else
		{
			withAdress2(etbl[i][1],"non",i);
		}
	});
	
	z=i+1;
	
	if (z<etbl.length) {
		setTimeout("createMarkersEtbl2("+z+")",400);
	}
}

function withAdress(adress,aff,i)
{
	geocoder.getLatLng(adress,function(point) {
		if (point)
		{
			if(aff=="oui")
			{
				map.setCenter(point, 9);
			}
			
			
			var baseIcon      = new GIcon(G_DEFAULT_ICON);
			
			baseIcon.image      = "icon-home.png";
				
			baseIcon.iconSize   = new GSize(26, 21);
			baseIcon.iconAnchor = new GPoint(0, 14);
			baseIcon.shadow     = "";
			var markerOptions = { icon:baseIcon, title:etbl[i][2] };
			var marker=new GMarker(point, markerOptions);
			
			var infoTabs = [
				new GInfoWindowTab("Informations", etbl[i][0])
			];
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowTabsHtml(infoTabs);
			});
			
			map.addOverlay(marker);
		}
		else
		{
			map.setCenter(new GLatLng(48.4711, -71.496277), 9);
		}
	});
}

function withAdress2(adress,aff,i)
{
	geocoder.getLatLng(adress,function(point) {
		if (point)
		{
			if(aff=="oui")
			{
				mapBig.setCenter(point, 9);
			}
			
			
			var baseIcon      = new GIcon(G_DEFAULT_ICON);
			
			baseIcon.image      = "icon-home.png";
				
			baseIcon.iconSize   = new GSize(26, 21);
			baseIcon.iconAnchor = new GPoint(0, 14);
			baseIcon.shadow     = "";
			var markerOptions = { icon:baseIcon, title:etbl[i][2] };
			var marker=new GMarker(point, markerOptions);
			
			var infoTabs = [
				new GInfoWindowTab("Informations", etbl[i][0])
			];
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowTabsHtml(infoTabs);
			});
			
			mapBig.addOverlay(marker);
		}
		else
		{
			mapBig.setCenter(new GLatLng(48.4711, -71.496277), 9);
		}
	});
}
