/* Copyright 2007-2009 SCube NewMedia. */
/** ============ API ============= */

/** ============ VARIABILI ============= */

/** ============ EVENTI ============= */
//gestione evento "onload"
if (window.addEventListener) {
	window.addEventListener("load", loadTemplate, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", loadTemplate);
};

/**
 * Gestione evento "load".
 */
function loadTemplate() {
	// creazione mappa e gestione parti comuni
	initialize();
	
	// Creates a control with buttons to zoom in and zoom out.
	Gmap.addSmallZoomControl();
	// Closes the info window, if it is open, and disables the opening of a new info window.
	Gmap.disableInfoWindow();
	
	// definizione controllo per la velina di attesa
	function LoadingControl(){}
	LoadingControl.prototype = new GControl();
	LoadingControl.prototype.initialize = function(map) {
		var loading = document.getElementById("loading");
		var parentNode = loading.parentNode;
		parentNode.removeChild(loading);
		map.getContainer().appendChild(loading);
		return loading;
	}
	LoadingControl.prototype.getDefaultPosition = function() {return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(8, 30));}
	// velina di attesa
	Gmap.addControl(new LoadingControl());
	
	// caricamento layer porgetto per definizione stili grafici 
	Gmap.getListLayerAsync(function(){});
	
	// settaggio posizione mappa
	Gmap.setCenter(LATITUDINE, LONGITUDINE, ZOOM);
	
	// gestione caricamento secondo parametri
	var idByURL = ParamByURL["id"];
	var layerByURL = ParamByURL["l"];
	if ((idByURL != null && idByURL.length > 0) && (layerByURL != null && layerByURL.length > 0)) {
		
		// caricamento contenuti secondo parametri
		Gmap.showObjectAsync(/*layer*/layerByURL, /*id*/idByURL, /*frontend*/null, function (objectLoaded) {
			if (objectLoaded == null) {
				alert("Spiacenti.\nLa ricerca non ha prodotto risultati.")
			} else {
				// settaggio focus su mappa
				Gmap.setDataLoadedFocus(/*layerToSkip*/null, /*layerToFocus*/[layerByURL]);
			}	
		});
	}
}
/** ============ FUNZIONI ============= */

