// JavaScript Document
google.load("maps", "2");
var GoogleMaps_class = function(){
	var GM = {
		map: null,
		geocoder: null,
		geocoder_alert: false,
		nSR: 0, //numero strutture ricettive aggiunte
		iD: 0, //per debug
		initialize: function() {
			if(GBrowserIsCompatible()) {
				this.map = new google.maps.Map2(document.getElementById("Mappa"));
				this.map.addControl(new GMapTypeControl());
				if(arguments[0]=="small"){
					this.map.addControl(new GSmallMapControl());
				}else{
					this.map.addControl(new GLargeMapControl());
				}
				this.geocoder = new GClientGeocoder();
				
				//this.map.setCenter(new google.maps.LatLng(42.87999,12.623291), 5);
			}else{}
		},
		addSR: function(latitudine,longitudine,address,html,icon){
			var This = this;
			var addPoint = function(point){
				This.nSR++;

				var baseIcon = new GIcon(G_DEFAULT_ICON);
				baseIcon.image = icon.image;
				baseIcon.iconSize = new GSize(icon.width,icon.height);
				baseIcon.shadow = false;
				
				var markerOptions = { icon:baseIcon, clickable:true, shadow: false};
				
				var marker = new GMarker(point, markerOptions);
				//var marker = new GMarker(point);

				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(html);
				  });
				
				This.map.addOverlay(marker);
			};
			if(latitudine!="" && longitudine!=""){
				var point = new google.maps.LatLng(latitudine, longitudine);
				addPoint(point);
			}else{
				if(this.geocoder){
					this.geocoder.getLatLng(
						address,
						function(point) {
							if (!point) {
								//alert(address + " not found");
							}else{
								addPoint(point);
							}
						}
					);
				}else if(!this.geocoder_alert){
					this.geocoder_alert=true;
					alert("geocoder non settato");
				}
			}
		},
		showAddress:function(address) {
			if (this.geocoder) {
				this.geocoder.getLatLng(
					address,
					function(point) {
						if (!point) {
							alert(address + " not found");
						}else{
							this.map.setCenter(point, 16);
							var baseIcon = new GIcon(G_DEFAULT_ICON);
							baseIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
							
							var markerOptions = { icon:baseIcon, clickable:true};
							
							var marker = new GMarker(point, markerOptions);
							//var html="ciao";
							
							GEvent.addListener(marker, "click", function() {
								marker.openInfoWindowHtml(html);
							  });
							
							
							map.addOverlay(marker);
							//marker.openInfoWindowHtml("Questa qui");
						}
					}
				);
			}else{
				alert("geocoder non settato");
			}
		}
	};
	return GM;
}
var GM = new GoogleMaps_class();
//google.setOnLoadCallback(GM.initialize);