

$(document).ready(function() {
	
	/* CUBODORO */
	
	$("#closecubo").click(function(){
		$("#cubodoro").hide();
		});
	
	
	/* FOTOGALLERY VARIE --- FOTOGALLERY VARIE --- FOTOGALLERY VARIE --- FOTOGALLERY VARIE --- FOTOGALLERY VARIE --- FOTOGALLERY VARIE --- FOTOGALLERY VARIE --- FOTOGALLERY VARIE --- FOTOGALLERY VARIE */
		
	
	$('#fotogallery ul li').click(function() {
		$('#mainimage').attr('src', $(this).find('img').attr('src'));
	});
	
	$('#fotogallery_investimenti ul li').click(function() {
		$('#mainimage4').attr('src', $(this).find('img').attr('src'));
	});
	
	$('#fotogallery_abitativi ul li').click(function() {
		$('#mainimage').attr('src', $(this).find('img').attr('src'));
	});
	
	$('#fotogallery_commerciali ul li').click(function() {
		$('#mainimage2').attr('src', $(this).find('img').attr('src'));
	});
	
	$('#fotogallery_ampliamenti ul li').click(function() {
		$('#mainimage3').attr('src', $(this).find('img').attr('src'));
	});




	/* MAPPA DI GOOGLE --- MAPPA DI GOOGLE --- MAPPA DI GOOGLE --- MAPPA DI GOOGLE --- MAPPA DI GOOGLE --- MAPPA DI GOOGLE --- MAPPA DI GOOGLE --- MAPPA DI GOOGLE --- MAPPA DI GOOGLE --- MAPPA DI GOOGLE */
	 
	var initialize = function()
	{
	    var latlng = new google.maps.LatLng(45.6793328,12.369063);
		
	    var options = {
	        zoom: 11,
	        center: latlng,
	        mapTypeId: google.maps.MapTypeId.ROADMAP
	    }; 
	    var map = new google.maps.Map(document.getElementById('map'), options);   
	    var marker = new google.maps.Marker(
	        {
	            position: latlng,
	            map: map,
	            icon: 'images/apple-icon.png',
	            flat: true
	        }
	    );
	    var tooltip = '<span id="tooltip">'+
	        'Natural Building'+
	        '</span>';
	    var infowindow = new google.maps.InfoWindow({
	        content: tooltip
	    });
	    google.maps.event.addListener(marker, 'click', function() {
	        infowindow.open(map,marker);
	    });
	}
	window.onload = initialize;
	

	var createMap = function()
	{
	   searchAddress();
	    var address = document.getElementById("address").value;
	    var geocoder = new google.maps.Geocoder();
	    geocoder.geocode( {'address': address}, function(results,status) {
	        if (status == google.maps.GeocoderStatus.OK) {
	            var options = {
	                zoom: 12,
	                center: results[0].geometry.location,
	                mapTypeId: google.maps.MapTypeId.ROADMAP
	            };
	        var map = new google.maps.Map(document.getElementById('map'), options);
	        var marker = new google.maps.Marker({position: results[0].geometry.location, map: map});
	        } else {
	            alert("Problema nella ricerca dell'indirizzo: " + status);
	        }
	    });
	}
	
	
	
	$("#accordion_foglie").accordion();
	$("#accordion_tecnica").accordion();
	
	

	/* TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE --- TIKER FIERE */




	var ticker = function()
	{
		n_elementi= $("#ticker").find("li").length;
		if(n_elementi>1)
		{
		setTimeout(function(){
			$('#ticker li:first').animate( {marginTop: '-60px'}, 800, function()
			{
				$(this).detach().appendTo('ul#ticker').removeAttr('style');	
			});
			ticker();
		}, 3000);
		}
	};
	ticker();
	
	
	
	/* GESTIONE RETE COMMERCIALE --- GESTIONE RETE COMMERCIALE --- GESTIONE RETE COMMERCIALE --- GESTIONE RETE COMMERCIALE --- GESTIONE RETE COMMERCIALE --- GESTIONE RETE COMMERCIALE --- GESTIONE RETE COMMERCIALE */
	
	
	/* nascondo tutte le foto degli agenti */
	$(".foto_agent").hide();
	$(".map_active").css({opacity:0});
	$(".map_active").css('filter', 'alpha(opacity=0)');
	
	
	
	/* se hover sull'elenco degli agenti */
	$("ul.agenti li").hover(
	
	function() {
			$(".foto_agent").hide();
			var age=$(this).attr('id');
			var agente="#foto_agenti #"+age+"2";
			var reg=$(this).attr('class');
			var regione="#"+reg;
		$(agente).show();
		$(this).removeClass("disactive");
		$(this).siblings().addClass("disactive");
		$(regione).css({opacity:1});
		$(regione).css('filter', 'alpha(opacity=100)');
		
		}, 
		function(){
			$("ul.agenti li").removeClass("disactive");
			$(".foto_agent").hide();
			$(".map_active").css({opacity:0});
			$(".map_active").css('filter', 'alpha(opacity=0)');
		}
		
		);
		
	/* se hover sulla mappa */	
		
	$(".map_active").hover(
		function(){
			$(this).css({opacity:1});
			$(this).css('filter', 'alpha(opacity=100)');
			var regi=$(this).attr('id');
			var region="ul.agenti li."+regi;
			$("ul.agenti li").addClass("disactive");
			$(region).removeClass("disactive");
			var fotografia="#foto_agenti ."+regi;
			$(fotografia).show();

			
			
			},
		function(){
			
			$(".map_active").css({opacity:0});
			$(".map_active").css('filter', 'alpha(opacity=0)');
			$("ul.agenti li").removeClass("disactive");
			$(".foto_agent").hide();
			
			
			}	
			
			);
	
	/* GESTIONE DEL FORM PER LA RICHIESTA DI INFORMAZIONI --- FORM INFORMAZIONI --- FORM INFORMAZIONI --- FORM INFORMAZIONI --- FORM INFORMAZIONI --- FORM INFORMAZIONI --- FORM INFORMAZIONI --- FORM INFORMAZIONI */
	
	
		$("#submit").click(function(){					   				   
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		
		var emailFromVal = $("#emailFrom").val();
		if(emailFromVal == '') {
			$("#emailFrom").after('<span class="error">Indirizzo mail mancante.</span>');
			hasError = true;
		} else if(!emailReg.test(emailFromVal)) {	
			$("#emailFrom").after('<span class="error">Indirizzo mail non valido.</span>');
			hasError = true;
		}
		
		var nomeVal = $("#nome").val();
		if(nomeVal == '') {
			$("#nome").after('<span class="error">Nome e Cognome mancanti.</span>');
			hasError = true;
		}
		
		var messageVal = $("#message").val();
		if(messageVal == '') {
			$("#message").after('<span class="error">Messaggio mancante.</span>');
			hasError = true;
		}
		
		
		if(hasError == false) {
			$(this).hide();
			$("#privacy").hide();
			$("#titolo_form").hide();
			
			$.post("inviaemail.php",
   				{ emailFrom: emailFromVal, nome: nomeVal, message: messageVal },
   					function(data){
						$("#sendEmail").slideUp("normal", function() {				   
							
							$("#sendEmail").before('<h3>Richiesta inviata</h3><p>Verrai contattato al pi&ugrave; presto.</p>');											
						});
   					}
				 );
		}
		
		return false;
	});
	
	
	/* LINK E PARTNER a comparsa/scomparsa nel footer --- LINK & PARTNER --- LINK & PARTNER --- LINK & PARTNER --- LINK & PARTNER --- LINK & PARTNER --- LINK & PARTNER --- LINK & PARTNER --- LINK & PARTNER */
	
	$("#linkpart_button").click(function(){
		$("#linkpart").slideToggle("fast");
		$('html, body').animate({scrollTop: 99999});
		
		});
		
	
});

