    //  Copyright SalentoVIP.it (R)

	// ELENCO DELLE ICONE USATE COME BANDIERINE DAL SISTEMA
	var elencoBandierine = new Array();
	var errore = "";
	try {
		var ic_mangiare					= new google.maps.MarkerImage("salentomap/img/marker_verde.png");
		var ic_dormire					= new google.maps.MarkerImage("salentomap/img/marker_blu.png");
		var ic_divertirsi				= new google.maps.MarkerImage("salentomap/img/marker_rosso.png");		
		var ic_location					= new google.maps.MarkerImage("salentomap/img/marker_giallo.png");		
		var ic_specialcat				= new google.maps.MarkerImage("salentomap/img/marker_giallo.png");		
		var ic_shopcat					= new google.maps.MarkerImage("salentomap/img/marker_giallo.png");		
		} catch (err) {
		errore = "problemi col collegamento a google maps. \n riprovare.\n\n";
		errore+="Dettaglio errore: " + err.description + "\n";
		alert(errore);
	}

	// MARKER (bandierina) di GOOGLE. 
	var BandierinaGoogle = function(x, y, struttura, icona, linka) {
		this.posizioneX = x;
		this.posizioneY = y;
		this.struttura = struttura;
		this.icon = icona;
		this.link = linka;

		this.getX = function() {
			return this.posizioneX;
		}
		this.getY = function() {
			return this.posizioneY;
		}
		this.getStruttura = function() {
			return this.struttura;
		}
		this.getIcon = function() {
			return this.icon;
		}
		this.getLink = function() {
			return this.link;
		}
	};
	
	// selcting BANDIERINE
	function caricaBandierine(tipologia) {
		if (tipologia=="tutte") {
			lo_ristoranti();
			lo_ristorantipizzerie();
			lo_trattorieosterie();	
			lo_pubbirrerie();	
			lo_loungewinebar();	
			lo_delicatesse();	
			lo_barpasticceriegelaterie();
			lo_hotelresortandspa();	
			lo_villaggiresidence();	
			lo_agriturismomasserie();	
			lo_bedandbreakfast();	
			lo_villedimore();	
			lo_appartamenti();			
			lo_discoteche();		
			lo_loungebeach();		
			lo_locationricevimenti();		
			lo_special();		
			lo_shop();		
		} else if (tipologia=="ristoranti") {
			lo_ristoranti();
		} else if (tipologia=="ristorantipizzerie") {
			lo_ristorantipizzerie();
		} else if (tipologia=="trattorieosterie") {
			lo_trattorieosterie();
		} else if (tipologia=="pubbirrerie") {
			lo_pubbirrerie();
		} else if (tipologia=="loungewinebar") {
			lo_loungewinebar();
		} else if (tipologia=="delicatesse") {
			lo_delicatesse();
		} else if (tipologia=="barpasticceriegelaterie") {
			lo_barpasticceriegelaterie();
		} else if (tipologia=="hotelresortandspa") {
			lo_hotelresortandspa();
		} else if (tipologia=="villaggiresidence") {
			lo_villaggiresidence();
		} else if (tipologia=="agriturismomasserie") {
			lo_agriturismomasserie();
		} else if (tipologia=="bedandbreakfast") {
			lo_bedandbreakfast();
		} else if (tipologia=="villedimore") {
			lo_villedimore();
		} else if (tipologia=="appartamenti") {
			lo_appartamenti();
		} else if (tipologia=="discoteche") {
			lo_discoteche();
		} else if (tipologia=="loungebeach") {
			lo_loungebeach();
		} else if (tipologia=="locationricevimenti") {
			lo_locationricevimenti();
		} else if (tipologia=="specialcat") {
			lo_special();
		} else if (tipologia=="shopcat") {
			lo_shop();
		}
	}
	
	var markerArray = new Array();
	var map;
	var latlng;
	var latlngCentro;

	// drawing MAP
	function disegnaMappa (centroX, centroY, zoomScelto) {
		// Elimino tutte le bandierine
		for (i=0; i<markerArray.length; i++) {
			markerArray[i].setMap(null);
		}
		//pb=null;
		elencoBandierine = null;
		elencoBandierine = new Array();
		if (errore!="") {
			document.getElementById('popupMappe').style.display="none";
		} else {
			var nomeCheckBox="";
			if (document.getElementById('popupMappe').style.display=="none") {
				var larghezzaFinestraBrowser = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
				var altezzaFinestraBrowser = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
				var leftMarginDivMappa = 0;
				var topMarginDivMappa = 0;
				if (larghezzaFinestraBrowser>800)
					leftMarginDivMappa = (larghezzaFinestraBrowser-800)/2;
				if (altezzaFinestraBrowser>600)
					topMarginDivMappa = (altezzaFinestraBrowser-600)/2;
				var divDellaMappa = document.getElementById('popupMappe');
				divDellaMappa.style.marginLeft=leftMarginDivMappa;
				divDellaMappa.style.marginTop=topMarginDivMappa;
				//alert(altezzaFinestraBrowser);
				document.getElementById('popupMappe').style.display="block";
				caricaBandierine('tutte');
			} else {
				for (i=1; i<19; i++) {
					nomeCheckBox="opt"+i;
					if (document.getElementById(nomeCheckBox).checked) {
						caricaBandierine(document.getElementById(nomeCheckBox).value);
					}
				}
			}
			latlngCentro = new google.maps.LatLng(centroX, centroY);
			
			var myOptions = {
				zoom: zoomScelto,
				center: latlngCentro,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			}
			
			if (map==null)
				map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

		    //var pb = progressBar("map_canvas");
			//map.controls[google.maps.ControlPosition.RIGHT].push(pb.getDiv());
			//pb.start(13);

			for (j=0; j<elencoBandierine.length; j++) {
				var bandiera = elencoBandierine[j];

				latlng = new google.maps.LatLng(bandiera.getX(), bandiera.getY());

				var marker = new google.maps.Marker({ position:latlng,map:map,title:bandiera.getStruttura(),icon:bandiera.getIcon(),url:bandiera.getLink() });

				markerArray.push(marker);
				addListnerToMarker(marker);

				//pb.updateBar(1);
			}
			//pb.hide();
		}
	}

	function addListnerToMarker(marker) {
		google.maps.event.addListener(marker, 'click', function() {
			window.location.href = marker.url;
		});

	}


	// ALL
	function selezionaTutte () {
		if (document.getElementById("opt0").checked) {
			for (i=1; i<19; i++) {
				document.getElementById("opt"+i).checked=true;
			}
			disegnaMappa(40.11694, 18.290634, 9);
		} else {
			for (i=1; i<19; i++) {
				document.getElementById("opt"+i).checked=false;
			}
			disegnaMappa(40.11694, 18.290634, 9);		
		}
	}
	
	// EXIT
	function esci() {
		pb=null;
		map = null;
		elencoBandierine = null;
		document.getElementById('popupMappe').style.display="none"
		for (i=0; i<19; i++) {
			document.getElementById("opt"+i).checked=true;
		}
	}
	
	// fixing RELOAD
	function loadF5() {
        for (i=0; i<19; i++) {
            document.getElementById("opt"+i).disabled=false;
            document.getElementById("opt"+i).checked=true;
        }
        disegnaMappa(40.11694, 18.290634, 9);
    }
