var GMAP        = false;
var GMAP_POINTS = {};
var GSTART_LAT  = "18.220221";
var GSTART_LNG  = "-66.486511";
var GSTART_ZOOM = 9;

/* ---------------------------------------------- */
function initMap(){

	//new Effect.KeepFixed('map');
	GMAP = new GMap2(document.getElementById("map"));
	GMAP.addControl( new GSmallMapControl() );
	GMAP.addControl( new GOverviewMapControl() );
	GMAP.addControl( new GMapTypeControl() );
	GMAP.enableContinuousZoom();
	GMAP.setCenter(new GLatLng( GSTART_LAT, GSTART_LNG ), GSTART_ZOOM );
}		
/* ---------------------------------------------- */
function addPoint( id , lat , lng , text ){
	GMAP_POINTS[id] = { 'lat' : lat , 'lng': lng , 'text' : text  };

}
/* ---------------------------------------------- */
function renderPoints(){

	var x , point, marker;

	for( x in GMAP_POINTS ){
		if( !GMAP_POINTS.hasOwnProperty( x ) ) continue;

		point  = new GLatLng( GMAP_POINTS[x].lat , GMAP_POINTS[x].lng );
		marker = GMAP_POINTS[x].marker = new GMarker(point);
		GMAP.addOverlay( marker );
		GEvent.addListener( marker , "click" , showPoint.bind( this , x ) );

	}
}
/* ---------------------------------------------- */
function showPoint( id ){
	var marker , text;
	marker = GMAP_POINTS[id].marker;
	text   = GMAP_POINTS[id].text;
	marker.openInfoWindow( text );
}
/* ---------------------------------------------- */
document.observe("dom:loaded" , function(){
	initMap();
	renderPoints();
});
