$(document).ready(function(){
	if($("ul.sf-menu").length > 0){
		$("ul.sf-menu").superfish();
	}
	if($(".articoli_rilievo").length > 0){
		$(".articoli_rilievo").tabs();
	}
	if($("#apblog").length > 0){
		$("#apblog").tabs();
	}
});

function ricerca(){
	
	var ricerca = $("#testo_search").val().replace(" ","+");
	if(ricerca.length == 0){
		alert('non hai inserito il testo da ricercare!');
		return false;
	}
	if($("#tipo_ricerca_roma")[0].checked)
		document.location.href='/tags/'+ricerca;
	else if ($("#tipo_ricerca_italia")[0].checked)
		document.location.href='/italia/tags/'+ricerca;
	else{
		var cx = "partner-pub-6370795429173542:6utf7mxkuaj";
		var cof = "FORID:10";
		var ie = "ISO-8859-1";
		var q = "31";
		var sa = "Cerca";
		document.location.href='http://www.romaexplorer.it/ricerca_google.html?cx='+cx+'&cof='+cof+'&ie='+ie+'&q='+ricerca+'&sa='+sa+'&siteurl=http://www.romaexplorer.it';
	}
		
	
	return false;
}

function genera_mappa(data) {	
	var mapOpts = {
	  mapTypeId: google.maps.MapTypeId.ROADMAP,
	  scaleControl: true,
	  scrollwheel: false
	}
	var map = new google.maps.Map(document.getElementById("map"), mapOpts);
	
	var infoWindow = new google.maps.InfoWindow();
	var markerBounds = new google.maps.LatLngBounds();
	var markerArray = [];
	 
	function makeMarker(options){
	  var pushPin = new google.maps.Marker({map:map});
	  pushPin.setOptions(options);
	  google.maps.event.addListener(pushPin, "click", function(){
	    infoWindow.setOptions(options);
	    infoWindow.open(map, pushPin);
	  });
	  markerBounds.extend(options.position);
	  markerArray.push(pushPin);
	  return pushPin;
	}
	
	google.maps.event.addListener(map, "click", function(){
	  infoWindow.close();
	});

	count = data.length;	
	for (var i = 0; i < count; i++) {
		var azienda = data[i];
		makeMarker({
		  position: new google.maps.LatLng(azienda.lat,azienda.lng),
		  title: azienda.azienda_nome,
		  content: azienda.azienda_contenuto
		});  
	}	
	map.fitBounds(markerBounds);	
}
