/**
 * Javascript for TYPO3 extension "chm_hiking"
 * 
 * @author Chris MŸller <chm@gmx.li> 
 * @version $Id$
 * @package tx_chmhiking
 */ 

/*jslint
	bitwise: true,
	browser: true,
	eqeqeq: true,
	immed: true,
	newcap: true,
	nomen: true,
	onevar: true,
	plusplus: true,
	regexp: true,
	undef: true
*/
/*global
	$,
	ChmHikingConfig,
	G_DEFAULT_ICON,
	GIcon,
	GLatLng,
	GMap2,
	GSize,
	LabeledMarker
*/


/***** Processing *************************************************************/

function ChmHiking() {
	/***** Object variables ***************************************************/

	/**
	 * Map object
	 * @type GMap2
	 * @private
	 */
	var map = null;



	/***** Initializing *******************************************************/

	/**
	 * Initializing
	 * This function will be called, when the html page is loaded
	 * @public
	 */	
	this.init = function () {
		/**
		 * Coordinates of the center of the map
		 * @type GLatLng
		 */
		var coordinates,
		
		/**
		 * Icon of a POI
		 * @type GIcon
		 */
		icon,
		
		/**
		 * Options for a icon
		 * @type Object
		 */
		iconOpts,

		/**
		 * Marker
		 * @type LabeledMarker
		 */
		marker,

		/**
		 * Helping variables
		 * @type Number
		 */
		len, i;


		// Neue Karte innerhalb des HTML-Containers erstellen
		map = new GMap2($(ChmHikingConfig.map.id), {mapTypes: ChmHikingConfig.map.types});
//		map.addControl(new GLargeMapControl3D());
//		map.addControl(new GMenuMapTypeControl());

		// Set coordinates and zoom level
		coordinates = new GLatLng(ChmHikingConfig.map.centerLat, ChmHikingConfig.map.centerLng);
		map.setCenter(coordinates, ChmHikingConfig.map.zoomlevel);

		if (ChmHikingConfig.pois) {

			// set icon
			icon = new GIcon(G_DEFAULT_ICON);
			icon.image = ChmHikingConfig.pois.img.standard;
			icon.mozPrintImage = ChmHikingConfig.pois.img.standardPrintMoz;
			icon.printImage = ChmHikingConfig.pois.img.standardPrint;
			iconOpts = { 
				'icon': icon,
				'clickable': true,
				'labelText': '',
				'labelOffset': new GSize(-7, -32)
			};

			if (map.isLoaded()) {
				len = ChmHikingConfig.pois.marker.length;
				for (i = 0; i < len; i += 1) {
	
					iconOpts.labelText = (i + 1);
	
					marker = new LabeledMarker(
						new GLatLng(ChmHikingConfig.pois.marker[i][0], ChmHikingConfig.pois.marker[i][1]),
						iconOpts
					);
	
					marker.bindInfoWindowHtml(ChmHikingConfig.pois.marker[i][2]);
					map.addOverlay(marker);
				}
	
			}
		}
	};
}



/***** Start *****************************************************************/

document.observe('dom:loaded', function() {
	var chmHiking = new ChmHiking();
	chmHiking.init();
});


