/*********************************************************
 * 
 * Appel des fonctions au chargement
 * 
 ********************************************************/
$(document).ready(function(){
	initStyleFix();
	initGMap();
});


/*********************************************************
 * initStyleFix
 * Corrige certains styles (bordures etc.)
 ********************************************************/
function initStyleFix(){
	$(".sidebar_left_2cols .agenda .events_small .left .event:last-child").css({"border-bottom-width":0});
	$(".sidebar_left_2cols .agenda .events_small .right .event:last-child").css({"border-bottom-width":0});
}

/**
 * Gestion de la Google Map
 */
var map = null;
var geocoder = null;
var themeurl = null;
var baseIcon = null;

// Creates a marker whose info window displays the letter corresponding
// to the given index.
function createMarker(point, index) {
	// Create a lettered icon for this point using our icon class
	var letter = String.fromCharCode("A".charCodeAt(0) + index);
	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = themeurl+"front/img/interface/gmap_marqueur.png";
	
	// Set up our GMarkerOptions object
	markerOptions = { icon:letteredIcon };
	var marker = new GMarker(point, markerOptions);
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml("Marker <b>" + letter + "</b>");
	});
	
	return marker;
}

function initGMap() {
	// Initialise la GMap
	var lattitude = $('.gps').attr('lattitude');
	var longitude = $('.gps').attr('longitude');
	themeurl = $('.gps').attr('themeurl');
	
	if ( (lattitude!=0 || longitude!=0) && GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("gmap_container"));
		map.setCenter(new GLatLng(longitude, lattitude), 15);
		
		var extLargeMapControl = new ExtLargeMapControl();
		map.addControl(extLargeMapControl);
		
		// Create a base icon for all of our markers that specifies the
		// shadow, icon dimensions, etc.
		baseIcon = new GIcon(G_DEFAULT_ICON);
		// baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(47, 60);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		
		var point = new GLatLng(longitude, lattitude);
		map.addOverlay(createMarker(point, 0));
	}
	
}
