/**
 * Enregistrement de l'instance de la Gmap dans l'objet window
 */
function regGMapObject(map) {
	this.gmap = map;
}


/**
 * Récupération de l'instance Gmap
 */
function getGmap() {
	return this.gmap;
}


/**
 * Ajoute un nouveau marker bleu
 */
function addBlueMarker(point) {
	//init icône bleue
	var blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
	blueIcon.iconSize = new GSize(32, 32);
	markerOptions = { icon:blueIcon };

	//création marqueur
	var marker = new GMarker(point, markerOptions);
	getGmap().addOverlay(marker);

	return marker;
}


/**
 * Ajoute un nouveau marker bleu
 */
function addLetterMarker(point, index) {
	//init icône lettre
	var baseIcon = new GIcon();
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);

	//création icone
	var letter = String.fromCharCode("A".charCodeAt(0) + index);
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
	//Option letter désactivée.
	//markerOptions = { icon:letteredIcon };
	markerOptions = {};

	//création marqueur
	var marker = new GMarker(point, markerOptions);
	getGmap().addOverlay(marker);

	return marker;
}


//création marqueur depuis tableau
function createMarker(point, index, array_infos, lang) {
	infosSousCarte = '<b>+ d\'infos sous la carte</b>';

	if (lang=='en') {
		infosSousCarte = '<b>More informations below the map<b/>';
	}

	if (lang=='es') {
		infosSousCarte = '<b>+ d\'infos sous la carte</b>';
	}


	var marker = addLetterMarker(point, index);

	GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(
				"<h4>" + array_infos['nom'] + "</h4>" +
				array_infos['adresse'] + "<br/>" +
				array_infos['codePostal'] + " " + array_infos['ville'] + "<br/> " + array_infos['libelle'] + "<br/><br/>" +
				infosSousCarte
			);

	    	get($H({
	    		'action': 'afficherFiche',
	    		'numElement' : array_infos['numElement']
	    	}).toQueryString(), 'divFicheElement', 'html');
		}
	);

	//sauvegarde des marqueurs dans un tab global
	array_gmap_marqueurs[array_infos['numElement']] = marker;

	return marker;
}