


	var mgrAziendaMarker;
	var map;
	var geocoder; 
	var indirizziMancanti='';

	
	function initialize() {
	
	    if (GBrowserIsCompatible()) {
	    	    
		    //override dei metodi per nascondere e mostrare i markers
			    GMarker.prototype.hide = function ()
			  {	
			    if (this.getPoint().lat() < 90)
			      try {
			        this.savePoint = this.getPoint();
			        this.setPoint(new GLatLng(90, 0));
			      } catch(e) {}
			  }
			  GMarker.prototype.show = function ()
			  {	  	
			    if (this.getPoint().lat() == 90)
			    if (this.savePoint)
			      try {	      	
			        this.setPoint(this.savePoint);
			        this.savePoint = null;
			      } catch(e) {}
			  }
			  
			    GMarker.prototype.isHidden = function ()
			  {
			    if (this.getPoint().lat() == 90)
				     return true;
				else return false;
			  }
			  
		
		      map = new GMap2(document.getElementById("map_canvas"));
		      geocoder = new GClientGeocoder(); 
		      var center = new GLatLng(0, 0);	
		      map.setCenter(center, 12);			            
			 map.addControl(new GLargeMapControl());
		      
		    
			  
			  
		      map.addControl(new GMapTypeControl());			  
			  mgrAziendaMarker = new GMarkerManager(map, {trackMarkers:true});
	
	    }   
  }
  
  
   function setMessageStaticAziendaMarker(markerTarget) {        
  		setCoordsMessageStaticAziendaMarker(markerTarget) ;  
  }
  
  
   function setCoordsMessageStaticAziendaMarker(markerTarget) {
	
	
		var denominazione=markerTarget.denominazione;
		var categoria=markerTarget.categoria;
		var chisiamo=markerTarget.chisiamo;
		var indirizzo=markerTarget.indirizzo;
		var telefono=markerTarget.telefono;
		var sito=markerTarget.sito;
		var attachmentKey=markerTarget.attachmentKey;
		
		var htmlLogo='';
		if(attachmentKey!=''){
			htmlLogo='<img id="image_10" src="/pol/attachment/download/'+attachmentKey+'"></img>';
		}
		
		var htmlScheda='<span class="txMarkerInfoWondow">' + 
		htmlLogo+'<br/>'+
		'<b>'+denominazione+'</b><br/><br/>'+				
	/*	''+chisiamo+ '<br/><br/><br/>'+
		'Categoria: '+categoria+ '<br/>'+ */
		'Indirizzo: '+indirizzo+ '<br/>'+
	/*	'Telefono: '+telefono+ '<br/>'+
		'sito web: <a href="'+sito+'" target="_blank">'+sito+'</a><br/>'+ */
		
		'</span>' ;	
		
		var html=htmlScheda;		
		var iwAnchor = markerTarget.getIcon().infoWindowAnchor;
        var iconAnchor = markerTarget.getIcon().iconAnchor;
        var offset = new GSize(iwAnchor.x-iconAnchor.x,iwAnchor.y-iconAnchor.y);
        map.openInfoWindow(markerTarget.getLatLng(), html, {pixelOffset:offset,maxWidth: 300});    
		
	}
	
	  
  function goToAddress() {
   var address = document.getElementById('address').value;
    if (geocoder) {
  	geocoder.getLatLng(
  	  address,
  	  function(point) {
  		if (!point) {
  		  //alert(address + " not found");
  		} else {  			
  		  map.setCenter(point, 9);   		
  		}
  	  }
  	);
    }
  }  
  
 
   function goToLatLngPoint(index) { 
   		//alert(index);
   		var markerAzienda=aziendeMarkers[index];
	    var point =new  GLatLng(markerAzienda.latitude, markerAzienda.longitude);	      
	     map.setCenter(point, 14); 	 
	     setMessageStaticAziendaMarker(markerAzienda);      	        
  }
  
  
   function goToCity(vicinoa,city,zoom) {
	   
	   
	   var address=''+vicinoa+','+city+ ',italia';  
	 
	   if (geocoder) {
	    	
		   if (city!=null && city!='' && zoom==null){
		   
		  	geocoder.getLatLng(
		  	  address,
		  	  function(point) {
		  		if (!point) {
		  		  alert(address + " not found");
		  		} else {  			
		  		  map.setCenter(point);   		  
		  		}
		  	  }
		  	);
		  	
		   }else  if (city!=null && city!='' && zoom!=null){
			   
			  	geocoder.getLatLng(
			  	  address,
			  	  function(point) {
			  		if (!point) {
			  		  alert(address + " not found");
			  		} else {  			
			  		  map.setCenter(point,zoom);   		  
			  		}
			  	  }
			  	);
			  	
			   }else{
			   
			   geocoder.getLatLng(
					  	  'montallese',
					  	  function(point) {
					  		if (!point) {
					  		  alert(address + " not found");
					  		} else {  			
					  		  map.setCenter(point,6);   		  
					  		}
					  	  }
					  	);
			   
		   } 
		  	
	    }
  }
   
  
/*function goToCity(city) {
	   
	   
	   var address=''+city;  
	    if (geocoder) {
		  	geocoder.getLatLng(
		  	  address,
		  	  function(point) {
		  		if (!point) {
		  		//  alert(address + " not found");
		  		} else {  			
		  		  map.setCenter(point,6);   		  
		  		}
		  	  }
		  	);
	    }
  }
  */


var aziendeMarkers=[];
var aziendeMarkerCount=0;




function insertAziendaMarker(denominazione,categoria, chisiamo, indirizzo, telefono, sito,  latitude, longitude, index, pagina, righeperpagina, attachmentKey){

		if(latitude=='') return;
		

		var point =new  GLatLng(parseFloat(latitude), parseFloat(longitude));       
		var side_bar_html = "";
		var htmls = [];
		var i = 0;      
		// Create some custom icons
		var aziendaIcon=new GIcon();    		
		aziendaIcon = new GIcon();     
	    aziendaIcon.iconSize = new GSize(32, 46);
	    aziendaIcon.shadowSize = new GSize(37, 34);
	    aziendaIcon.iconAnchor = new GPoint(9, 34);
	    aziendaIcon.infoWindowAnchor = new GPoint(9, 2);
	    aziendaIcon.infoShadowAnchor = new GPoint(18, 25);
	    aziendaIcon.image = window.location.protocol+"//"+window.location.hostname+":"+window.location.port+"/pol/risorse/immagini/maps/segnaposto.png";
	    aziendaIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		
//	    alert (window.location.protocol+"//"+window.location.hostname+":"+window.location.port+"/pol/risorse/immagini/maps/segnaposto.png");
	    
		// An array of GIcons, to make the selection easier
		var icons = [];
		icons[0] = aziendaIcon;	   
			   
		var indexInt=parseInt(index);		
		var indexIntShow=indexInt+1;
		
		opts = { 
          "icon": aziendaIcon,
          "clickable": true,
          "title": "Azienda "+index,
          "labelText": indexIntShow ,
          "labelOffset": new GSize(-3,-22),
          "labelClass": "txMarker"

        };
        

		
		var markerAzienda = new AziendaLabeledMarker(point, opts);
		
		markerAzienda.denominazione=denominazione;
		markerAzienda.categoria=categoria;
		markerAzienda.chisiamo=chisiamo;
		markerAzienda.indirizzo=indirizzo;
		markerAzienda.telefono=telefono;
		markerAzienda.sito=sito;
		markerAzienda.attachmentKey=attachmentKey;
		markerAzienda.latitude=parseFloat(latitude);
		markerAzienda.longitude= parseFloat(longitude);

		   
		GEvent.addListener(markerAzienda, "click", function() {    		
			setMessageStaticAziendaMarker(markerAzienda);      
		});     	    
		
		mgrAziendaMarker.addMarker(markerAzienda,  6);     	     
		mgrAziendaMarker.refresh();  	
		aziendeMarkers[aziendeMarkerCount]=markerAzienda;
		aziendeMarkerCount++;
		
		
			
			
		var indexInt=0+ parseInt(index);
		var paginaInt=0+ parseInt(pagina);
		var righeperpaginaInt=0+ parseInt(righeperpagina);
		
		
		var indiceReale= indexInt- (paginaInt * righeperpaginaInt);
		
		//alert("index:"+index+"pagina:"+pagina+ "righeperpagina:"+righeperpagina +"\n indiceReale:"+indiceReale);
		
	
        document.getElementById("aziendaMarker"+index).innerHTML = '<img style="cursor:pointer;" src="risorse/immagini/maps/segnaposto_SFbianco.gif" onclick="goToLatLngPoint('+indiceReale+');hideDetail();" onMouseOver="/*goToLatLngPoint('+indiceReale+');hideDetail();*/" /><div style="position:relative; z-index:100; left:-17px; top:-40px; cursor:pointer;" onclick="goToLatLngPoint('+indiceReale+');hideDetail();" onMouseOver="goToLatLngPoint('+indiceReale+');hideDetail();" >'+indexIntShow+'</div>'; 

  		//document.getElementById("aziendaMarker"+index).innerHTML = '<img style="cursor:pointer;" src="risorse/immagini/maps/segnaposto.png"  onMouseOver="hideDetail();goToLatLngPoint('+index+');" /><div style="position:relative; left:7px; top:-35px;cursor:pointer"  onMouseOver="hideDetail();goToLatLngPoint('+index+');" >'+indexIntShow+'</div>'; 


 		//document.getElementById("aziendaMarker"+index).innerHTML = 'TEST'; 

 

 

     
}



 	 



function insertAziendaMarker_orig(denominazione,categoria, chisiamo, indirizzo, telefono, sito,  latitude, longitude, index, attachmentKey){

		if(latitude=='') return;
		

		var point =new  GLatLng(parseFloat(latitude), parseFloat(longitude));       
		var side_bar_html = "";
		var htmls = [];
		var i = 0;      
		// Create some custom icons
		var aziendaIcon=new GIcon();    		
		aziendaIcon = new GIcon();     
	    aziendaIcon.iconSize = new GSize(32, 46);
	    aziendaIcon.shadowSize = new GSize(37, 34);
	    aziendaIcon.iconAnchor = new GPoint(9, 34);
	    aziendaIcon.infoWindowAnchor = new GPoint(9, 2);
	    aziendaIcon.infoShadowAnchor = new GPoint(18, 25);
	    aziendaIcon.image = "risorse/immagini/maps/segnaposto.png";
	    aziendaIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		
		
		// An array of GIcons, to make the selection easier
		var icons = [];
		icons[0] = aziendaIcon;	   
			   
		var indexInt=parseInt(index);		
		var indexIntShow=indexInt+1;
		
		opts = { 
          "icon": aziendaIcon,
          "clickable": true,
          "title": "Azienda "+index,
          "labelText": indexIntShow ,
          "labelOffset": new GSize(-3,-22),
          "labelClass": "txMarker"

        };
        

		
		var markerAzienda = new AziendaLabeledMarker(point, opts);
		
		markerAzienda.denominazione=denominazione;
		markerAzienda.categoria=categoria;
		markerAzienda.chisiamo=chisiamo;
		markerAzienda.indirizzo=indirizzo;
		markerAzienda.telefono=telefono;
		markerAzienda.sito=sito;
		markerAzienda.attachmentKey=attachmentKey;
		markerAzienda.latitude=parseFloat(latitude);
		markerAzienda.longitude= parseFloat(longitude);

		   
		GEvent.addListener(markerAzienda, "click", function() {    		
			setMessageStaticAziendaMarker(markerAzienda);      
		});     	    
		
		mgrAziendaMarker.addMarker(markerAzienda,  6);     	     
		mgrAziendaMarker.refresh();  	
		aziendeMarkers[aziendeMarkerCount]=markerAzienda;
		aziendeMarkerCount++;
		

	
        document.getElementById("aziendaMarker"+index).innerHTML = '<img style="cursor:pointer;" src="risorse/immagini/maps/segnaposto_SFbianco.gif" onclick="goToLatLngPoint('+index+');hideDetail();" onMouseOver="/*goToLatLngPoint('+index+');hideDetail();*/" /><div style="position:relative; left:7px; top:-35px;cursor:pointer" onclick="goToLatLngPoint('+index+');hideDetail();" onMouseOver="goToLatLngPoint('+index+');hideDetail();" >'+indexIntShow+'</div>'; 

  		//document.getElementById("aziendaMarker"+index).innerHTML = '<img style="cursor:pointer;" src="risorse/immagini/maps/segnaposto.png"  onMouseOver="hideDetail();goToLatLngPoint('+index+');" /><div style="position:relative; left:7px; top:-35px;cursor:pointer"  onMouseOver="hideDetail();goToLatLngPoint('+index+');" >'+indexIntShow+'</div>'; 


 		//document.getElementById("aziendaMarker"+index).innerHTML = 'TEST'; 

 

 

     
}
 


