// richiamo le google api ed avvio tutto
google.load("maps","2.x"); google.load("jquery","1.4.2");google.setOnLoadCallback(function(){$(function(){
	// slideSwitch
	$.fn.slideSwitch=function(options){if($(this).lengh!==0){var config={'speed':'5000','active':'active'};if(options)$.extend(config,options);$(this).find(':last').addClass(config.active).css({'z-index':10,'position':'absolute'});$(this).find('img:not(:last)').css({'z-index':8,'position':'absolute'});$this=$(this);loop=function(){var $active=$this.find('.'+config.active);var $next=$active.next().length?$active.next():$this.find(':first');$active.addClass('last-'+config.active).css({'z-index':9});$next.css({opacity:0.0}).addClass(config.active).css({'z-index':10}).animate({opacity:1.0},(config.speed/5),function(){$active.removeClass(config.active+' last-'+config.active).css({'z-index':8});});}
	window.setInterval(loop,config.speed);}}
	// Google Maps
	if($('div#gmap').length>0){
		// funzione per il markers popup
		function FApopup(markers,FAmapmarker,i){
			markers[i].openInfoWindowHtml('<div class=fagmap>'+FAmapmarker[i]['html']+'</div>');
		}
		// ONLOAD
		// genero mappa
		var map = new GMap2($('#gmap').get(0));
		
		// richiamo il centro della mappa
		map.setCenter(FAcentromappa, FAcentromappazoom);
		
		// tipo di controlli
		map.addControl(new GLargeMapControl());
		
		// Creo marker di base
		var FAicon = new GIcon(G_DEFAULT_ICON);
		FAicon.image = FAiconadiprovincia;
		//FAicon.shadow = 'http://www.google.com/mapfiles/shadow50.png';
		FAicon.iconSize = new GSize(29,28);
		FAicon.shadowSize = new GSize(45, 28);
		FAicon.iconAnchor = new GPoint(-15,28);
		FAicon.infoWindowAnchor = new GPoint(9, 2);
		markerOptions = { icon:FAicon };
		
		// Genero i Markers
		var markers = [];
		for (var i = 0; i<FAmapmarker.length; i++) {
			var point = new GLatLng(FAmapmarker[i]['latitude'],FAmapmarker[i]['longitude']); 
			var marker = new GMarker(point, markerOptions);
			map.addOverlay(marker); 
			markers[i] = marker;
		}
		
		// Genero Ballon
		$(markers).each(function(i,marker){
			GEvent.addListener(markers[i], "click", function(){FApopup(markers,FAmapmarker,i)});
		});
		
		// Abilito i titoli dei post ad aprire i rispettivi Ballon
		$('.postitolo h3 a').click(function(){
			FApopup(markers,FAmapmarker,$(this).attr('rel'));
			return false;
		});
	}
	// Attivo lo slidewitch
	$('#frame div').slideSwitch();
})});
