
/*var GoogleMap = {
	init : function(div_name,latidine, longitudine, info,address) {
		if (!document.getElementById || !document.createTextNode) {
			return;
		}
		// Verifica il supporto per il DOM
		var div = this.getElementsByClassName(document, 'div', div_name)[0];
		if (GBrowserIsCompatible()) {
			var map = new GMap2(div);
			//alert(latidine + " " + longitudine + " " + info);
			if(latidine==0&&longitudine==0){
				geocoder = new GClientGeocoder();
				var point = geocoder.getLatLng(address,function(point){latidine =  point.x;});
				alert(latidine)
				GLatLng =  new GLatLng(point.y,point.x); 	
				//this.geocode(address);
			}else{
				GLatLng =  new GLatLng(latidine, longitudine); 
			}
			map.setCenter(GLatLng, 7);
			map.addControl(new GLargeMapControl());
			//map.addControl(new GMapTypeControl());
			map.enableContinuousZoom();
			infoon = true;
			/*if(info!=""){
			map.addOverlay(this.createMarker(
					GLatLng, "<strong>" + info
							+ "</strong>"));
			map.openInfoWindow(map.getCenter(),
	                   "<strong>" + info + "</strong>");
			}else{
				map.addOverlay(this.createMarker(GLatLng));
			}
		}

	},
	createMarker : function(point, description) {
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(description);
		});
		
		return marker;
	},

	getElementsByClassName : function(oElm, strTagName, strClassName) {

		var arrElements = (strTagName == "*" && document.all) ? document.all
				: oElm.getElementsByTagName(strTagName);
		var arrReturnElements = new Array();
		strClassName = strClassName.replace(/\-/g, "\\-");
		var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
		var oElement;
		for ( var i = 0; i < arrElements.length; i++) {
			oElement = arrElements[i];
			if (oRegExp.test(oElement.className)) {
				arrReturnElements.push(oElement);
			}
		}
		return (arrReturnElements)
	},
	addEvent : function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e" + type + fn] = fn;
			obj[type + fn] = function() {
				obj["e" + type + fn](window.event);
			}
			obj.attachEvent("on" + type, obj[type + fn]);
		}
	},
	 geocode:function(indirizzo){
		geocoder = new GClientGeocoder();
		geocoder.getLatLng(indirizzo,
		function(point){
			if (!point){alert(indirizzo + " non trovato!");}
			else { alert(indirizzo + "\n" +"Longitudine: " + point.x + "\n" + "Latitudine: " + point.y);}
		});
}
};
*/
var GoogleMap = function(class_div,class_point,class_indirizzo,lat,longi,indirizzo,zoom){
	this.class_point = class_point; 
	this.class_indirizzo = class_indirizzo; 
	this.lat = lat; 
	this.longi = longi; 
	this.zoom = zoom; 

	this.indirizzo = indirizzo; 
	this.geocoder = new GClientGeocoder();
	this.div = $(class_div);
	this.GLatLng = null; 
 };
 
GoogleMap.prototype = {
	init : function(){
		
		if(this.lat==0&&this.longi==0){
			this.geocoder.getLatLng(this.indirizzo,function(point){
				this.initMap(point.y, point.x);
			}.bind(this));
		}else{
			this.initMap(this.lat, this.longi); 
		}	
	},
	initMap: function(lat, longi){
		this.GLatLng =  new GLatLng(lat, longi); 
		var map = new GMap2(this.div);
		map.setCenter(this.GLatLng, this.zoom);
		this.initPoints(map);
		map.addControl(new GLargeMapControl());
		//map.addControl(new GMapTypeControl());
	},
	initPoints: function(map){
		/*var point = this.geocoder.getLatLng()
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml("");
		});
		
		return marker;*/
		var points_div = $$('div.js_google_luogo');	
		points_div.each(function (item, index){this.initPoint(item,map)}.bind(this)); 
	},initPoint: function(item,map){
		var lat =item.getElement('div.js_google_address_lat'); 
		lat.set("class",lat.get("class") + " hidden");
		var longi =item.getElement('div.js_google_address_longi');
		longi.set("class",longi.get("class") + " hidden");
		
		var point =  new GLatLng(lat.innerHTML, longi.innerHTML); 
		var marker = new GMarker(point);
		var text = item.innerHTML; 
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(text);
		});
		map.addOverlay(marker);
		item.destroy();
	}
};

