// Carte de Bretagne
// Eric Quillévéré  27/05/2009
/*jsl:import js_rewrite.js */
/*jsl:import googleMaps.js */
var listeIcones=Array();
var zoomDepartement='tous';
var tabCateg=Array(); // Liste des catégories
var tabCategVisibles=Array(); // Catégories visibles

// Google Maps ; ajoute les points
even_Cree(window, Array('load'), function() 
		{
		googleMaps_cree('carteGoogle', false, true);
		
		if (mapGoogle)
			{
			mapGoogle.setCenter(new GLatLng(47.95222519664455,-3.052825927734375),8);
			Zoom_Dept(zoomDepartement);
			var listePoints=ListeDesPoints();
			for (var i=0;i<tabCategVisibles.length;i++)
				ajoutePointsCategorie(listePoints, tabCategVisibles[i]);
			CocherTous_FixeEtat(listePoints)
			}
		
		});

// Zoom sur le département
function Zoom_Dept(categ) 
	{
	if (!mapGoogle) return;
	
	var pointzoom=null;
	var nivZoom;
	switch (categ)
		{
		case 'tous': pointzoom = new GLatLng(47.95222519664455,-3.052825927734375);nivZoom=8;	break;
		case '29':	pointzoom = new GLatLng(48.246625590713826,-4.229736328125);nivZoom=9;break;
		case '35': pointzoom = new GLatLng(48.111737,-1.680230);nivZoom=9;break;
		case '56': pointzoom = new GLatLng(47.79839667295524,-2.977294921875);nivZoom=9; break;
		case '22':	pointzoom = new GLatLng(48.59659225145668,-2.999267578125);	nivZoom=9;break;
		case '44':	pointzoom = new GLatLng(47.2549998709802,-1.54632568359375); nivZoom=9;break;
		default:break;
		}
	if (pointzoom)
		{
		mapGoogle.panTo(pointzoom);
		mapGoogle.setZoom(nivZoom);
		mapGoogle.setCenter(pointzoom); 
		}
	}
	
// Cacher tous les points	
function carte_CocherDecocherTous(supprimer)
	{
	if (supprimer)
		{
		// Supprime les points visibles
		for (var i=0;i<tabCategVisibles.length;i++)
			{
			googleMaps_afficheCachePoint(tabCategVisibles[i], null, true);	
			// Inverse la coche
			var objet=obj('point'+tabCategVisibles[i]);
			if (objet) objet.checked=false;
			}
		tabCategVisibles=Array();
		
		}
	else
		{
		// Ajoute les points manquants
		var listePoints=ListeDesPoints();
		for (var i=0;i<tabCateg.length;i++)
			{
			if (tab_Recherche(tabCategVisibles, tabCateg[i])===null)
				{
				ajoutePointsCategorie(listePoints, tabCateg[i]);
				tab_Ajoute(tabCategVisibles, tabCateg[i]);
				}
			}
		
		}
		

	}
	
// Cacher tous les points d'une catégorie	
function carte_AfficherCacherCateg(numCategorie)
	{
	if (tab_Recherche(tabCategVisibles, numCategorie)!==null)
		{
		
		googleMaps_afficheCachePoint(numCategorie, null, true);
		tab_Supprime(tabCategVisibles, numCategorie);
		}
	else
		{
		ajoutePointsCategorie(ListeDesPoints(), numCategorie);
		tab_Ajoute(tabCategVisibles, numCategorie);
		}
	
	}	

// Coche ou pas la case "tous les points sont cochés"
function CocherTous_FixeEtat(listePoints)
	{
	var nbCases=0, nbCoches=0;
	for (var categ in listePoints)
		{
		var objet=obj('point'+categ);
		if (objet) 
			if (objet.checked) nbCoches++;
		nbCases++
		}		
	if (nbCases==nbCoches) 
		obj('cocherTous').checked=true;
	else
		obj('cocherTous').checked=false;
	}		
	
		
// Ajoute les points d'une certaine catégorie
function ajoutePointsCategorie(listePoints, numCategorie)
	{
	var nbAjouts=0;
	for (var categ in listePoints)
		{
		if (numCategorie==categ)
			{
			var objet=obj('point'+categ);
			if (objet) objet.checked=true;
			for (var points in listePoints[categ])
				{
				nbAjouts++; 
				var infosPoint=listePoints[categ][points];

				googleMaps_ajoutePoint(infosPoint[0], infosPoint[1], infosPoint[2],
					listeIcones[numCategorie], 14, 26,
					null, null,  null,
					null,null, numCategorie, 'affiche_onglet.php?id=' + infosPoint[3],
					'<div align="center">Chargement...</div>', true);
					
				}
			break;
			}
		}		
	}	
