// Google Maps api by Eduardo
// uso della mappa
/*----------------------------------------*/
// all'onload del documento 
// usare la funzione: showmaps();
// per richiamare un indirizzo nella pagina usare:
//
// per un indirizzo usare 
// showAddress('via aniello falcone 300, napoli italia',true,'nascar studios','dati testuali',false);
//comandi 
//indirizzo di default | attivare il segnaposto | nome della nuvoletta (richiede che activemarker sia true) | testo della nuvoletta (richiede che activemarker sia true) | apertura della nuvoletta in automatico (richiede che activemarker sia true)
//
// per delle latutudini e longitudini usare
// showlatlng(latitudine,longitudine);
// espresse in questo modo 37.4419 (utilizzare maps.google.it per ricavarle precisamente)
// 
/*----------------------------------------*/

//campi modificabili
// google maps api code
var apicode = 'ABQIAAAAHq-rE-o8kcYo_jPam8dROBQoPz7t5VZqZubImwKLeK-NS--LSxRqcEhg4ffpdfFjJycomj-3CJnvnA';
//var apicode = 'ABQIAAAAm8Hf8q0lWMPr4JZHtpE1kRROTXEr0-BCMW1IZRALLDLSJxCHXBQxvtzeYbD7BdGZovDbZ9J9kBcyOw';

//ID del div della mappa
var idfrommaps = 'map'; 

//controlli della mappa || 0 - disattivo, 1 - piccolo, 2 - larghi, 3 - solo zoom
var mapscontroll=2;

//tipologie della mappa || 0 - disattivo, 1 - attivo
var mapsoptions=0;

//scala della mappa || 0 - disattivo, 1 - attivo
var mapscale=0;

//navigatore della mappa || 0 - disattivo, 1 - attivo
var mapsnavi=0;

//scroll della mappa con con la rotellina del mouse || 0 - disattivo, 16 - attivo
var mapscroll=1;

//livello dello zoom || 13 - citta, 16 - strada
var zoomlevel=15;
//fine campi modificabili

var map = null;
var geocoder = null;
var icon = null;
var textindivAD = new Array();
var textindivLL = new Array();
var textindivMM = new Array();


function loadinner(divmaps){
	var el = divmaps.childNodes[0];
	i=0;
	z=0;
	k=0;
	while (el) {
		if((el.nodeName.toLowerCase())=="p"){
			switch(el.className){
				case "address":
					textindivAD[i]=el.innerHTML;
					i++;
				break;
				case "latlong":
					textindivLL[z]=el.innerHTML;
					z++;
				break;
				case "mostra":
					textindivMM[k]=el.innerHTML;
					k++;
				break;
			}
		}
		el = el.nextSibling;
	}
}
function insertaddress(){
	for(i=0;i<textindivMM.length;i++){
		finale=textindivMM[i];
	}
	for(i=0;i<textindivAD.length;i++){
		showAddress(textindivAD[i],true,'whereIsIt',finale,false);
	}
	for(i=0;i<textindivLL.length;i++){
		latlon=textindivLL[i].split(",");
		showlatlng(latlon[0],latlon[1]);
	}
}
function googlesapi_load() {
	if(document.getElementById(idfrommaps)){
		divmaps=document.getElementById(idfrommaps);
		loadinner(divmaps);
		if (GBrowserIsCompatible() && divmaps) {
			map = new GMap2(divmaps);
			geocoder = new GClientGeocoder();
			/*
			switch(mapscontroll){
				case 1:
					map.addControl(new GSmallMapControl());
					break;
				case 2:
					map.addControl(new GLargeMapControl());
					break;
				case 3:
					map.addControl(new GSmallZoomControl());
					break;
			}
			switch(mapsoptions){
				case 1:
					map.addControl(new GMapTypeControl());
					break;
			}
			switch(mapscale){
				case 1:
					map.addControl(new GScaleControl());
					break;
			}
			switch(mapsnavi){
				case 1:
					map.addControl(new GOverviewMapControl());
					break;
			}
			*/
			map.setUIToDefault();
			map.enableContinuousZoom();
			switch(mapscroll){
				case 1:
					GEvent.addDomListener(divmaps, "DOMMouseScroll", wheelZoom);
					GEvent.addDomListener(divmaps, "mousewheel",     wheelZoom);
					break;
			}
		}
		insertaddress();
	}
}    
function showAddress(address,setmarker,tabname,tabtext,opentab) {
	if(geocoder){
		geocoder.getLatLng(address,
			function(point) {
			if(!point){
				idmap=document.getElementById(idfrommaps);
				idmap.innerHTML = 'Google Maps error<br /><strong>' + address + '</strong> not found';
				idmap.style.width = '610';
				idmap.style.height = '0';
				idmap.style.border = '0';
				idmap.style.background = '#fff';
				//alert(address + " not found");
			}else{
				map.setCenter(point, zoomlevel);
				map.setMapType(G_NORMAL_MAP);
				if(setmarker){
					// Create our "cafe" marker icon
					var cafeIcon = new GIcon();
					cafeIcon.image = "http://www.tuevacanze.com/images/gmap.png";
					cafeIcon.shadow = "http://www.carpisa.it/img/ombra.png";
					cafeIcon.iconSize = new GSize(45, 44);
					cafeIcon.shadowSize = new GSize(45, 44);
					cafeIcon.iconAnchor = new GPoint(6, 29);
					cafeIcon.infoWindowAnchor = new GPoint(6, 0);
					// Set up our GMarkerOptions object literal
					markerOptions = { icon:cafeIcon };
					marker = new GMarker(point, {icon: cafeIcon});
					infoTabs = [ new GInfoWindowTab(tabname, tabtext)];
					GEvent.addListener(marker, "click", function() {
						marker.openInfoWindowTabsHtml(infoTabs);
					});
					map.addOverlay(marker);
					marker.openInfoWindowTabsHtml(infoTabs);
				}
			}
		});
	}
}
function showlatlng(latshow,lonshow){
	map.setCenter(new GLatLng(latshow, lonshow), zoomlevel);
	map.setMapType(G_NORMAL_MAP);
}
function wheelZoom(a){
	if (a.detail){
		if (a.detail < 0){ 
			map.zoomIn(); 
		}else if (a.detail > 0){
			map.zoomOut(); 
		}
	}else if (a.wheelDelta){
		if (a.wheelDelta > 0){
			map.zoomIn(); 
		}else if (a.wheelDelta < 0){
			map.zoomOut(); 
		}
	}
}
function showmaps(){
	googlesapi_load();
}
document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key='+apicode+'&amp;hl=en" type="text/javascript"></script>');

//window.addEvent('load',showmaps)
