/**
	@file This file contains the initialization routines for use in
	the Google Maps implementation used by RRP.

	USES:
		/maps/scripts/markers.js
		/maps/scripts/regions.js

	USED BY:
		/maps.php
	
	INCLUDED BY:
		/maps.php
 */

/*--------------------------------------------------------------------------*/
// CONSTANTS /* {{{ */
var REQUEST_REGIONS_URL = MAPS_BASE_URL + 'maps/points.xml';
var REQUEST_MARKERS_URL = MAPS_BASE_URL + 'maps/points.xml';

/* }}} */

/*--------------------------------------------------------------------------*/
/**
	@brief This function initializes the Google Map interface.

	@note Called From:
		/maps.php
 */
function Maps_Initialize() { /* {{{ */

	// initialize the various pieces of the system
	InitMap();
	InitRegions();
	InitMarkers();
	InitLinks();

	return;
} /* }}} */

/*--------------------------------------------------------------------------*/
/**
	@brief This function initializes the GMap2 Google Map object that
	controls the Map itself.
 */
function InitMap() { /* {{{ */

	// create Google Map object
	g_map = new GMap2(document.getElementById('map'));

	/*
		After creating the map, it must be centered on a point before anything
		else can be done.
	*/
	g_map.setCenter(DEFAULT_MAP_CENTER, DEFAULT_MAP_ZOOM, DEFAULT_MAP_TYPE);

	/*
		Enable features and controls.
	*/
	g_map.enableContinuousZoom(); // enable continuous zoom
	g_map.addControl(new TextualZoomControl()); // add zoom buttons
	g_map.addControl(new AreaControl('area-control-primary', 'area-control-primary-button', 7, 7, 'Primary', 'Primary', ToggleRegions, 'primary')); // add Primary Area button
	g_map.addControl(new AreaControl('area-control-secondary', 'area-control-secondary-button', 97, 7, 'Secondary', 'Secondary', ToggleRegions, 'secondary')); // add Secondary Area button
	g_map.addControl(new AreaControl('area-control-tertiary', 'area-control-tertiary-button', 187, 7, 'Tertiary', 'Tertiary', ToggleRegions, 'tertiary')); // add Tertiary Area button
	g_map.addControl(new GMapTypeControl()); // add controls for changing the map type

	/*
		Add event handlers.
	*/
	// No event handlers
	
	return;
} /* }}} */

/*--------------------------------------------------------------------------*/
/**
	@brief This function initializes the region overlays for the Google Map.
 */
function InitRegions() { /* {{{ */

	// request and load the regions onto the map
	LoadRegions(REQUEST_REGIONS_URL);
	return;
} /* }}} */

/*--------------------------------------------------------------------------*/
/**
	@brief This function initializes the marker overlays for the Google Map.
 */
function InitMarkers() { /* {{{ */

	// request and load the markers onto the map
	LoadMarkers(REQUEST_MARKERS_URL);
	return;
} /* }}} */


/*--------------------------------------------------------------------------*/
/**
	@brief This function initializes the page links to the map markers.
 */
function InitLinks() { /* {{{ */

	// if enabled, add links to the page from the marker data
	if (true == g_state.markers_enabled) {
		AddMarkerLinks();
	}

	return;
} /* }}} */

