function initEvents()
{
	initListeHippodromes();
	showGoogleMapLoading();
	loadGoogleMap();
	//initDepartements();
	initFederation();	
}

var oMap = null;
var oGeoCoder = null;
var oBaseIcon = null;

// Variantes des disciplines
var oBaseIconTrot = null;
var oBaseIconObstacle = null;
var oBaseIconPlat = null;
var oBaseIconTrotObstacle = null;
var oBaseIconTrotPlat = null;
var oBaseIconObstaclePlat = null;
var oBaseIconTrotObstaclePlat = null;

// Taille des icônes
var iIconWidth = 25;
var iIconHeight = 20;


/**
 * Hippodromes
 */

var aHippodromes = new Array();

/**
 * Affichage du 'Chargement...'
 */
function showGoogleMapLoading()
{
	// Element affichant la carte
	var oGoogleMap = $("#google_map");
	
    // Element 'Chargement...'
    var oLoading = $("#google_map_loading");	
    
    // Element 'Chargement...' : img
    var oLoadingImg = $("#google_map_loading_img");	
	
	// Position et dimension
	var aMapPosition = oGoogleMap.offset();
	var mapWidth = oGoogleMap.width();
	var mapHeight = oGoogleMap.height();
	
	var loadingImgWidth = 66;
	var loadingImgHeight = 66;
    
    // Positionement du 'Chargement...'
	oLoadingImg.css("left", ((mapWidth - loadingImgWidth) / 2) + "px");
    oLoadingImg.css("top", ((mapHeight - loadingImgHeight) / 2) + "px");
	
	oLoading.css("left", aMapPosition.left + "px");
    oLoading.css("top", aMapPosition.top + "px");
    
    oLoading.css("width", mapWidth + "px");
    oLoading.css("height", mapHeight + "px");
	
    // Affichage du 'Chargement...'
    oLoading.fadeIn("fast");
    oLoadingImg.fadeIn("fast");
}

/**
 * Cache 'Chargement...'
 */
function hideGoogleMapLoading()
{
    // Element 'Chargement...'
    var oLoading = $("#google_map_loading");	
	
    // Cache 'Chargement...'
    oLoading.fadeOut();
}

/**
 * Création d'un nouveau marqueur
 * @param point
 * @param aDisciplines
 * @param tabInfo
 * @return
 */
function createMarker(point, aDisciplines, html)
{
	// Icône du marqueur

	var icon = new GIcon(oBaseIcon);
	
	/*
	
	if 		( aDisciplines['trot'] && !aDisciplines['obstacle'] && !aDisciplines['plat'])
	{
		var icon = new GIcon(oBaseIconTrot);
	}
	else if (!aDisciplines['trot'] &&  aDisciplines['obstacle'] && !aDisciplines['plat'])
	{
		var icon = new GIcon(oBaseIconObstacle);
	}	
	else if (!aDisciplines['trot'] && !aDisciplines['obstacle'] &&  aDisciplines['plat'])
	{
		var icon = new GIcon(oBaseIconPlat);
	}
	else if ( aDisciplines['trot'] &&  aDisciplines['obstacle'] && !aDisciplines['plat'])
	{
		var icon = new GIcon(oBaseIconTrotObstacle);
	}
	else if ( aDisciplines['trot'] && !aDisciplines['obstacle'] &&  aDisciplines['plat'])
	{
		var icon = new GIcon(oBaseIconTrotPlat);
	}	
	else if (!aDisciplines['trot'] &&  aDisciplines['obstacle'] &&  aDisciplines['plat'])
	{
		var icon = new GIcon(oBaseIconObstaclePlat);
	}
	else
	{
		var icon = new GIcon(oBaseIconTrotObstaclePlat);
	}
	
	*/
	
    // Création de l'objet GMarker (voir http://code.google.com/intl/fr/apis/maps/documentation/reference.html#GMarker2)
	var marker = new GMarker(point, icon);
	
	// Evènement du clique sur le marqueur
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindow(html);
	});
	
	return marker;
}

/**
 * Chargement des marqueurs (Ajax / JSON)
 */
function loadMarkers()
{
	// Requête AJAX
    $.ajax({
    	// Fichier cible php :
    	url : "ajax/ajax.google_map_hippodromes.php",
    	// Type de requête
    	type : "GET",
    	// Type de données renvoyées : JSON
    	dataType : "json",
    	// Paramètres :
    	data : {type: 'hippodromes'},
    	// Callback :    	
    	success : load_markers_callback
    });
}

/**
 * Création des marqueurs après chargement (Ajax / JSON)
 */
function load_markers_callback (oJson)
{
	// Element affichant la carte
	var oGoogleMap = $("#google_map");
    var aDisciplines = null;
	
    aHippodromes = new Array();
    
	for (i in oJson.hippodromes)
	{
		aHippodromes[oJson.hippodromes[i].hippodrome_id] = oJson.hippodromes[i];
		
		// Création de l'objet GLatLng (voir http://code.google.com/intl/fr/apis/maps/documentation/reference.html#GLatLng)
		var point = new GLatLng(parseFloat(oJson.hippodromes[i].hippodrome_latitude), parseFloat(oJson.hippodromes[i].hippodrome_longitude));

		// Fiche de description de l'hippodrome
		var html = '';
		
		html += "<div class=\"google_map_details\">\n";
		html += "	<strong>" + oJson.hippodromes[i].hippodrome_nom2 + " / " +  oJson.hippodromes[i].hippodrome_nom + "</strong>\n";
		html += "	" + oJson.hippodromes[i].hippodrome_adresse + "<br />\n";
		
		if (oJson.hippodromes[i].hippodrome_telephone != '')
			html += "	T&eacute;l. : " + oJson.hippodromes[i].hippodrome_telephone + "<br />\n";
		
		if (oJson.hippodromes[i].hippodrome_fax != '')
			html += "	Fax : " + oJson.hippodromes[i].hippodrome_fax + "<br />\n";
		
		if (oJson.hippodromes[i].hippodrome_email != '')
			html += "	<a class=\"email\" href=\"" + oJson.hippodromes[i].hippodrome_email + "\">" + oJson.hippodromes[i].hippodrome_email + "<br />\n";
		
		html += "	<a class=\"home\" href=\"" + oJson.hippodromes[i].href + "\">Voir la fiche Hippodrome<br />\n";
		html += "</div>\n";
		
		aDisciplines = new Array();
		aDisciplines['trot'] = oJson.hippodromes[i].hippodrome_trot;
		aDisciplines['obstacle'] =  oJson.hippodromes[i].hippodrome_obstacle;
		aDisciplines['plat'] =  oJson.hippodromes[i].hippodrome_plat;
		
		aHippodromes[oJson.hippodromes[i].hippodrome_id].oPoint = point;
		aHippodromes[oJson.hippodromes[i].hippodrome_id].oMarker = createMarker(point, aDisciplines, html);
		
		// Ajout du marqueur sur la carte
		oMap.addOverlay(aHippodromes[oJson.hippodromes[i].hippodrome_id].oMarker);
	}

	hideGoogleMapLoading();
	
	// Zoom sur l'hippodrome de l'Url
	if ((typeof(hippodrome_id) != 'undefined') && (typeof(depart) == 'undefined') && (typeof(arrivee) == 'undefined'))
	{
		$("#google_map_hippodromes").val(hippodrome_id);
		zoomOnHippodrome(hippodrome_id);
	}
}

/**
 * Departements
 */

var aDepartements = new Array();
var aDepartementsOptions = null;

/**
 * Initialise les valeurs des options pour l'affichage des départements
 */
function initDepartementsOptions()
{
	/* Options définies par défaut pour les départements */
	aDepartementsOptions = {
		/* Couleur des bordures */
		strokeColor : '#2E741F',
		/* Largeur des bordures */
		strokeWeight : 0,
		/* Opacité des bordures */
		strokeOpacity : 0.2,
		/* Couleur de remplissage */
		fillColor : '#2E741F',
		/* Opacité de remplissage */
		fillOpacity : 0.3
	};
}

/**
 * Initialise l'affichage des départements
 */
function initDepartements()
{
	initDepartementsOptions();
	loadDepartements();
}

/**
 * Chargement des départements
 */
function loadDepartements()
{
	// Requête AJAX
    $.ajax({
    	// Fichier cible php :
    	url : "ajax/ajax.google_map_departements.php",
    	// Type de requête
    	type : "GET",
    	// Type de données renvoyées : JSON
    	dataType : "json",
    	// Paramètres :
    	data : {type: 'departements'},
    	// Callback :    	
    	success : load_departements_callback
    });
}

/**
 * Création des departements après chargement (Ajax / JSON)
 */
function load_departements_callback(oJson)
{
	var i = null;
	
	for (i in oJson.departements)
	{
		// Si le département n'a pas été chargé
		if (!aDepartements[oJson.departements[i].departement_id])
		{
			aDepartements[oJson.departements[i].departement_id] = oJson.departements[i];
			loadDepartement(oJson.departements[i].departement_id);		
		}
	}
	
	//loadDepartement(98);	
}

/**
 * Chargement d'un département
 */
function loadDepartement(departement_id)
{
	// Requête AJAX
    $.ajax({
    	// Fichier cible php :
    	url : "ajax/ajax.google_map_departements.php",
    	// Type de requête
    	type : "GET",
    	// Type de données renvoyées : JSON
    	dataType : "json",
    	// Paramètres :
    	data : {type: 'departement', departement_id: departement_id},
    	// Callback :    	
    	success : load_departement_callback
    });
}

/**
 * Création du departements/Modification après chargement (Ajax / JSON)
 */
function load_departement_callback(oJson)
{
	aDepartements[oJson.departement_id] = oJson;
	
	var aLinesStrings = oJson.departement_gmap_poly.split('@');
	
	aDepartements[oJson.departement_id].aPolys = new Array();
	
	for (k in aLinesStrings)
	{
		var aPoints = new Array();
		
		var aPointsStrings = aLinesStrings[k].split('|');
		
		for (i in aPointsStrings)
		{
			aPointCoords = aPointsStrings[i].split(',');
			aPoints.push(new GLatLng(parseFloat(aPointCoords[1]), parseFloat(aPointCoords[0])));
		}
		
		aDepartements[oJson.departement_id].aPolys.push(new GPolygon(	aPoints,
																		aDepartementsOptions.strokeColor,
																		aDepartementsOptions.strokeWeight,
																		aDepartementsOptions.strokeOpacity,
																		aDepartementsOptions.fillColor,
																		aDepartementsOptions.fillOpacity));
	}
	
	for (k in aDepartements[oJson.departement_id].aPolys)
		oMap.addOverlay(aDepartements[oJson.departement_id].aPolys[k]);
}

/**
 * Fédérations
 */

var sel_federation_id = null;
var aFederations = new Array();

/**
 * Initialise l'affichage de la fédération
 */
function initFederation()
{
	initDepartementsOptions();
	loadFederation(sel_federation_id);
}

/**
 * Chargement de la fédération
 * @param federation_id
 */
function loadFederation(federation_id)
{
	// Requête AJAX
    $.ajax({
    	// Fichier cible php :
    	url : "ajax/ajax.google_map_federations.php",
    	// Type de requête
    	type : "GET",
    	// Type de données renvoyées : JSON
    	dataType : "json",
    	// Paramètres :
    	data : {type: 'federation', federation_id: federation_id},
    	// Callback :    	
    	success : load_federation_callback
    });
}

/**
 * Création de la fédération après chargement (Ajax / JSON)
 */
function load_federation_callback(oJson)
{
	var i = null;
	
	oMap.clearOverlays();
		
	sel_federation_id = oJson.federation_id;
	
	aFederations[oJson.federation_id] = oJson;
		
	for (i in aFederations[oJson.federation_id].departements)
	{
		var aLinesStrings = aFederations[oJson.federation_id].departements[i].departement_gmap_poly.split('@');

		aFederations[oJson.federation_id].departements[i].oPoint = new GLatLng(parseFloat(oJson.departements[i].departement_latitude), parseFloat(oJson.departements[i].departement_longitude));
		aFederations[oJson.federation_id].departements[i].aPolys = new Array();
		
		//alert(aFederations[oJson.federation_id].departements[i].departement_nom);
		
		for (k in aLinesStrings)
		{
			var aPoints = new Array();
			
			var aPointsStrings = aLinesStrings[k].split('|');
			
			for (j in aPointsStrings)
			{
				aPointCoords = aPointsStrings[j].split(',');
				aPoints.push(new GLatLng(parseFloat(aPointCoords[1]), parseFloat(aPointCoords[0])));
			}
			
			aFederations[oJson.federation_id].departements[i].aPolys.push(new GPolygon(	aPoints,
																			aDepartementsOptions.strokeColor,
																			aDepartementsOptions.strokeWeight,
																			aDepartementsOptions.strokeOpacity,
																			aDepartementsOptions.fillColor,
																			aDepartementsOptions.fillOpacity));
		}
		
		for (k in aFederations[oJson.federation_id].departements[i].aPolys)
			oMap.addOverlay(aFederations[oJson.federation_id].departements[i].aPolys[k]);
	}
	
	var aDisciplines = null;
	
	for (i in oJson.hippodromes)
	{
		// Création de l'objet GLatLng (voir http://code.google.com/intl/fr/apis/maps/documentation/reference.html#GLatLng)
		var point = new GLatLng(parseFloat(oJson.hippodromes[i].hippodrome_latitude), parseFloat(oJson.hippodromes[i].hippodrome_longitude));

		// Fiche de description de l'hippodrome
		var html = '';
		
		html += "<div class=\"google_map_details\">\n";
		html += "	<strong>" + oJson.hippodromes[i].hippodrome_nom2 + " / " +  oJson.hippodromes[i].hippodrome_nom + "</strong>\n";
		html += "	" + oJson.hippodromes[i].hippodrome_adresse + "<br />\n";
		
		if (oJson.hippodromes[i].hippodrome_telephone != '')
			html += "	T&eacute;l. : " + oJson.hippodromes[i].hippodrome_telephone + "<br />\n";
		
		if (oJson.hippodromes[i].hippodrome_fax != '')
			html += "	Fax : " + oJson.hippodromes[i].hippodrome_fax + "<br />\n";
		
		if (oJson.hippodromes[i].hippodrome_email != '')
			html += "	<a class=\"email\" href=\"" + oJson.hippodromes[i].hippodrome_email + "\">" + oJson.hippodromes[i].hippodrome_email + "<br />\n";
		
		html += "	<a class=\"home\" href=\"" + oJson.hippodromes[i].href + "\">Voir la fiche Hippodrome<br />\n";
		html += "</div>\n";
		
		aDisciplines = new Array();
		aDisciplines['trot'] = oJson.hippodromes[i].hippodrome_trot;
		aDisciplines['obstacle'] =  oJson.hippodromes[i].hippodrome_obstacle;
		aDisciplines['plat'] =  oJson.hippodromes[i].hippodrome_plat;

		aFederations[oJson.federation_id].hippodromes[i].oPoint = point;
		aFederations[oJson.federation_id].hippodromes[i].oMarker = createMarker(point, aDisciplines, html);
		
		// Ajout du marqueur sur la carte
		oMap.addOverlay(aFederations[oJson.federation_id].hippodromes[i].oMarker);
	}
	
	zoomFederation(oJson.federation_id);
	
	hideGoogleMapLoading();
}

/**
 * Centre et zoom sur la fédération
 * @param federation_id
 */
function zoomFederation(federation_id)
{
	if (!aFederations[federation_id])
		return;
	
	var aLatLngBounds = new GLatLngBounds();
	
	for (i in aFederations[federation_id].departements)
	{
		aLatLngBounds.extend(aFederations[federation_id].departements[i].oPoint);
	}
	
	for (i in aFederations[federation_id].hippodromes)
	{
		aLatLngBounds.extend(aFederations[federation_id].hippodromes[i].oPoint);
	}
	
	oMap.setCenter(aLatLngBounds.getCenter(), oMap.getBoundsZoomLevel(aLatLngBounds));
}

/**
 * Chargement de Google Map
 * @return
 */
function loadGoogleMap()
{
	// Test la compatibilité
	if (GBrowserIsCompatible())
	{
		// Création de l'objet GMap2 (voir http://code.google.com/intl/fr/apis/maps/documentation/reference.html#GMap2)
		oMap = new GMap2(document.getElementById("google_map"));
		
		// Ajout des controlleurs
		oMap.addControl(new GLargeMapControl());
		oMap.addControl(new GMapTypeControl());
		
		// Centrer sur le point
		oMap.setCenter(new GLatLng(46.95, 1.62), 5);
		
		// Icône du marqueur
		oBaseIcon = new GIcon();
		
		// Images, taille...
		oBaseIcon.image = "images/google_map/cursor.png";
		oBaseIcon.shadow = "images/google_map/cursor_shadow.png";
		oBaseIcon.iconSize = new GSize(12, 20);
		oBaseIcon.shadowSize = new GSize(22, 20);
		//oBaseIcon.iconSize = new GSize(24, 24);
		//oBaseIcon.shadowSize = new GSize(22, 20);
		oBaseIcon.iconAnchor = new GPoint(6, 20);
		oBaseIcon.infoWindowAnchor = new GPoint(5, 1);
		
		// Variantes des disciplines
		
		/*
		
		// Trot
		oBaseIconTrot = new GIcon();
		
		// Images, taille...
		oBaseIconTrot.image = "images/google_map/cursor_R.png";
		oBaseIconTrot.iconSize = new GSize(iIconWidth, iIconHeight);
		oBaseIconTrot.iconAnchor = new GPoint(parseInt(iIconWidth / 2), parseInt(iIconHeight / 2));
		oBaseIconTrot.infoWindowAnchor = new GPoint(parseInt(iIconWidth / 2) - 1, 1);
		
		// Obstacle
		oBaseIconObstacle = new GIcon();
		
		// Images, taille...
		oBaseIconObstacle.image = "images/google_map/cursor_V.png";
		oBaseIconObstacle.iconSize = new GSize(iIconWidth, iIconHeight);
		oBaseIconObstacle.iconAnchor = new GPoint(parseInt(iIconWidth / 2), parseInt(iIconHeight / 2));
		oBaseIconObstacle.infoWindowAnchor = new GPoint(parseInt(iIconWidth / 2) - 1, 1);
		
		// Plat
		oBaseIconPlat = new GIcon();
		
		// Images, taille...
		oBaseIconPlat.image = "images/google_map/cursor_B.png";
		oBaseIconPlat.iconSize = new GSize(iIconWidth, iIconHeight);
		oBaseIconPlat.iconAnchor = new GPoint(parseInt(iIconWidth / 2), parseInt(iIconHeight / 2));
		oBaseIconPlat.infoWindowAnchor = new GPoint(parseInt(iIconWidth / 2) - 1, 1);
		
		// Trot, Obstacle
		oBaseIconTrotObstacle = new GIcon();
		
		// Images, taille...
		oBaseIconTrotObstacle.image = "images/google_map/cursor_RV.png";
		oBaseIconTrotObstacle.iconSize = new GSize(iIconWidth, iIconHeight);
		oBaseIconTrotObstacle.iconAnchor = new GPoint(parseInt(iIconWidth / 2), parseInt(iIconHeight / 2));
		oBaseIconTrotObstacle.infoWindowAnchor = new GPoint(parseInt(iIconWidth / 2) - 1, 1);
		
		// Trot, Plat
		oBaseIconTrotPlat = new GIcon();
		
		// Images, taille...
		oBaseIconTrotPlat.image = "images/google_map/cursor_BR.png";
		oBaseIconTrotPlat.iconSize = new GSize(iIconWidth, iIconHeight);
		oBaseIconTrotPlat.iconAnchor = new GPoint(parseInt(iIconWidth / 2), parseInt(iIconHeight / 2));
		oBaseIconTrotPlat.infoWindowAnchor = new GPoint(parseInt(iIconWidth / 2) - 1, 1);
		
		// Obstacle, Plat
		oBaseIconObstaclePlat = new GIcon();
		
		// Images, taille...
		oBaseIconObstaclePlat.image = "images/google_map/cursor_BV.png";
		oBaseIconObstaclePlat.iconSize = new GSize(iIconWidth, iIconHeight);
		oBaseIconObstaclePlat.iconAnchor = new GPoint(parseInt(iIconWidth / 2), parseInt(iIconHeight / 2));
		oBaseIconObstaclePlat.infoWindowAnchor = new GPoint(parseInt(iIconWidth / 2) - 1, 1);
		
		// Trot, Obstacle, Plat
		oBaseIconTrotObstaclePlat = new GIcon();
		
		// Images, taille...
		oBaseIconTrotObstaclePlat.image = "images/google_map/cursor_BRV.png";
		oBaseIconTrotObstaclePlat.iconSize = new GSize(iIconWidth, iIconHeight);
		oBaseIconTrotObstaclePlat.iconAnchor = new GPoint(parseInt(iIconWidth / 2), parseInt(iIconHeight / 2));
		oBaseIconTrotObstaclePlat.infoWindowAnchor = new GPoint(parseInt(iIconWidth / 2) - 1, 1);

		*/

		/*
		
		// Légende
		oMap.addControl(new GLegendeControl());
		
		*/
		
		// Chargement des marqueurs (Ajax / JSON)
		//loadMarkers();
		
		// Création de l'objet GClientGeocoder (voir http://code.google.com/intl/fr/apis/maps/documentation/reference.html#GClientGeocoder)
		oGeoCoder = new GClientGeocoder();		

		// Evènement : Fin du glissement de la carte : Centrer sur le point
		GEvent.addListener(oMap, "moveend", function() {
			var center = oMap.getCenter();
		});
	}
}

/**
 * Initialisation du combobox des hippodromes
 */
function initListeHippodromes()
{
	$("#google_map_hippodromes").change( function() {
		if (this.value != 0)
			zoomOnHippodrome(this.value);
	});
}

/**
 * Chargement d'un hippodrome pour zoom (Ajax / JSON)
 * @param hippodrome_id
 */
function zoomOnHippodrome(hippodrome_id)
{
	showGoogleMapLoading();
	
	// Requête AJAX
    $.ajax({
    	// Fichier cible php :
    	url : "ajax/ajax.google_map_hippodromes.php",
    	// Type de requête
    	type : "GET",
    	// Type de données renvoyées : JSON
    	dataType : "json",
    	// Paramètres :
    	data : {type: 'hippodrome', hippodrome_id: hippodrome_id},
    	// Callback :    	
    	success : zoom_on_hippodrome_callback
    });
}

/**
 * Zoom sur l'hippodrome (Ajax / JSON)
 */
function zoom_on_hippodrome_callback(oJson)
{
	zoomOnGoogleMap(oJson.hippodrome_latitude, oJson.hippodrome_longitude, 15);
	
	hideGoogleMapLoading();
}

/**
 * Zoom sur la carte au lieu indiqué
 * @param latitude
 * @param longitude
 * @param zoom
 */
function zoomOnGoogleMap(latitude, longitude, zoom)
{
	if (!zoom)
		zoom = 15;
	
	oMap.setCenter(new GLatLng(latitude, longitude), zoom);
}


/**
 * Zoom sur la carte au lieu indiqué par un point
 * @param point
 * @param zoom
 */
function zoomOnGoogleMapPoint(point, zoom)
{
	if (!zoom)
		zoom = 15;
	
	oMap.setCenter(point, zoom);
}


function refreshFiltres()
{
	var trot = ($("#googlemap_checkbox_trot").attr("checked"));
	var obstacle = ($("#googlemap_checkbox_obstacle").attr("checked"));
	var plat = ($("#googlemap_checkbox_plat").attr("checked"));
	
	var display = null;

	if (sel_federation_id != null)
	{
		for (i in aFederations[sel_federation_id].hippodromes)
		{	
			display = false;
			
			if (trot && aFederations[sel_federation_id].hippodromes[i].hippodrome_trot)
				display = true;
			
			if (obstacle && aFederations[sel_federation_id].hippodromes[i].hippodrome_obstacle)
				display = true;
			
			if (plat && aFederations[sel_federation_id].hippodromes[i].hippodrome_plat)
				display = true;
			
			if (display)
				oMap.addOverlay(aFederations[sel_federation_id].hippodromes[i].oMarker);
			else
				oMap.removeOverlay(aFederations[sel_federation_id].hippodromes[i].oMarker);
		}
	}
	else
	{
		if (aHippodromes.length > 0)
		{
			for (i in aHippodromes)
			{	
				display = false;
				
				if (trot && aHippodromes[i].hippodrome_trot)
					display = true;
				
				if (obstacle && aHippodromes[i].hippodrome_obstacle)
					display = true;
				
				if (plat && aHippodromes[i].hippodrome_plat)
					display = true;
				
				if (display)
					oMap.addOverlay(aHippodromes[i].oMarker);
				else
					oMap.removeOverlay(aHippodromes[i].oMarker);
			}
		}
	}
}

/**
 * Classe GControl : Légende des hippodromes 
 * @return GLegendControl
 */
function GLegendeControl() {}

GLegendeControl.prototype = new GControl();

GLegendeControl.prototype.initialize = function(map)
{
	var oDivContainer = document.createElement("div");
	
	oDivContainer.style.padding = "3px 7px 3px 7px";
	oDivContainer.style.border = "1px solid #000";	
	oDivContainer.style.backgroundColor = "#EBEBEB";
	oDivContainer.style.fontSize = "10px";
	oDivContainer.style.fontFamilly = "Arial";
	oDivContainer.style.color = "#3B302E";
	oDivContainer.style.fontSize = "10px";
	
	var oDivTrot = document.createElement("div");
	var oDivObstacle = document.createElement("div");
	var oDivPlat = document.createElement("div");
	
	var oImgTrot = document.createElement("img");
	var oImgObstacle = document.createElement("img");
	var oImgPlat = document.createElement("img");

	var oCheckboxTrot = document.createElement("input");
	var oCheckboxObstacle = document.createElement("input");
	var oCheckboxPlat = document.createElement("input");
	
	oCheckboxTrot.setAttribute("type", "checkbox");	
	oCheckboxTrot.setAttribute("id", "googlemap_checkbox_trot");
	oCheckboxTrot.style.verticalAlign = "-2px";
	oCheckboxTrot.style.margin = "0px";
	
	oImgTrot.style.width = "30px";
	oImgTrot.style.height = "24px";
	oImgTrot.style.margin = "0px";
	oImgTrot.style.verticalAlign = "-7px";
	oImgTrot.setAttribute("src", "images/google_map/cursor_R.png");
	
	oCheckboxObstacle.setAttribute("type", "checkbox");	
	oCheckboxObstacle.setAttribute("id", "googlemap_checkbox_obstacle");
	oCheckboxObstacle.style.verticalAlign = "-2px";
	oCheckboxObstacle.style.margin = "0px";
	
	oImgObstacle.style.width = "30px";
	oImgObstacle.style.height = "24px";
	oImgObstacle.style.margin = "0px";
	oImgObstacle.style.verticalAlign = "-7px";
	oImgObstacle.setAttribute("src", "images/google_map/cursor_V.png");
	
	oCheckboxPlat.setAttribute("type", "checkbox");
	oCheckboxPlat.setAttribute("id", "googlemap_checkbox_plat");
	oCheckboxPlat.style.verticalAlign = "-2px";
	oCheckboxPlat.style.margin = "0px";
	
	oImgPlat.style.width = "30px";
	oImgPlat.style.height = "24px";
	oImgPlat.style.margin = "0px";
	oImgPlat.style.verticalAlign = "-7px";
	oImgPlat.setAttribute("src", "images/google_map/cursor_B.png");
	
	// Trot
		
	oDivTrot.appendChild(oCheckboxTrot);
	oDivTrot.appendChild(oImgTrot);
	oDivTrot.appendChild(document.createTextNode("Trot"));
	
	oDivContainer.appendChild(oDivTrot);
	
	GEvent.addDomListener(oCheckboxTrot, "change", function() {
		refreshFiltres();
	});
	
	GEvent.addDomListener(oCheckboxTrot, "click", function() {
		refreshFiltres();
	});
	
	// Obstacle
	oDivObstacle.appendChild(oCheckboxObstacle);
	oDivObstacle.appendChild(oImgObstacle);
	oDivObstacle.appendChild(document.createTextNode("Obstacle"));
	
	oDivContainer.appendChild(oDivObstacle);
	
	GEvent.addDomListener(oCheckboxObstacle, "change", function() {
		refreshFiltres();
	});
	
	GEvent.addDomListener(oCheckboxObstacle, "click", function() {
		refreshFiltres();
	});
	
	// Plat
	
	oDivPlat.appendChild(oCheckboxPlat);
	oDivPlat.appendChild(oImgPlat);
	oDivPlat.appendChild(document.createTextNode("Plat"));
	
	oDivContainer.appendChild(oDivPlat);
	
	GEvent.addDomListener(oCheckboxPlat, "change", function() {
		refreshFiltres();
	});
	
	GEvent.addDomListener(oCheckboxPlat, "click", function() {
		refreshFiltres();
	});
	
	map.getContainer().appendChild(oDivContainer);
	
	// IE..
	oCheckboxTrot.setAttribute("checked", "checked");	
	oCheckboxObstacle.setAttribute("checked", "checked");
	oCheckboxPlat.setAttribute("checked", "checked");

	return oDivContainer;
}

GLegendeControl.prototype.getDefaultPosition = function()
{
  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(7, 20));
}

