
/* Gesto V7 - ALL RIGHTS RESERVED Gabriel Andrei - email: gabrielandrei@yahoo.it
 * COPIA CONCESSA IN USO ALLA Locanda della Luna Tuoro sul Trasimeno(PG)
 * */
var GGmaps = new Class({
	Implements: [Options,Events],
	
	options:{
		contenitore:'mappa_google',
		infoCentrale:'Centro',
		lat:0,
		lng:0,
		zoom:0,
		settaOnload:true,
		tipoMappa: 0,
		settaMarkerAlCentro:true,
		markeri:Array()
	},
	
	initialize: function(options){
        this.setOptions(options);
        if(this.options.settaOnload) this.centroMappa();
	},
	
	centroMappa: function(){
		var centro = new GLatLng(this.options.lat,this.options.lng);
		map = new GMap2($(this.options.contenitore));
		map.setCenter(centro, this.options.zoom);
		map.setUIToDefault();
		
		baseIcon = new GIcon();
        
        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        baseIcon.iconSize = new GSize(20, 34);
        baseIcon.shadowSize = new GSize(37, 34);
        baseIcon.iconAnchor = new GPoint(9, 34);
        baseIcon.infoWindowAnchor = new GPoint(9, 2);
        baseIcon.infoShadowAnchor = new GPoint(18, 25);
		
		if(this.options.tipoMappa==1){
			map.setMapType(G_HYBRID_MAP);
		}
		
		if(this.options.settaMarkerAlCentro){
			var markerCentro = this.creaMarker(centro, 0,this.options.infoCentrale,false);
			map.addOverlay(markerCentro);
			
		}
		
	},
	
	creaMarker: function(point, index,info, selettera) {
		if(selettera){
	        var letter = String.fromCharCode("A".charCodeAt(0) + index);
			var letteredIcon = new GIcon(baseIcon);
			letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
			markerOptions = { icon:letteredIcon };
		}else{
			baseIcon.image = "http://www.google.com/mapfiles/marker.png";
			markerOptions = { icon:baseIcon };
		}
		
		var marker = new GMarker(point, markerOptions);
		
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(info);
		});
		return marker;
	},
	
	procArrayMarkeri: function(arr){
		prop=this;
		arr.each(function(item,id){
			cen= new GLatLng(item['lat'],item['lng']);
			ma=prop.creaMarker(cen,id,item['info'],true);
			map.addOverlay(ma);
			prop.options.markeri.include(ma);
		});
	},
	
	apriInfoMarker:function(i){
		var myFx = new Fx.Scroll(window).toElement(this.options.contenitore);
		GEvent.trigger(this.options.markeri[i], "click");
	}
	
});