// JavaScript Document
// Function  by Giuseppe Sciascia

  function vai_a(id)
  {
    $('html,body').animate({scrollTop: $("#"+id).offset().top},2700);
  }


//<![CDATA[
function svuota(oggetto)
 {
   $(oggetto).attr('value','');
    ripopola($(oggetto).attr('id'));
 }
 
 
 function ripopola(id)
 {

												  
	if	( ($('#mnome').val()=='') && ('mnome'!=id) )
     { 	$('#mnome').val('nome e cognome'); }									  
 
 	if	( ($('#mmail').val()=='') && ('mmail'!=id) )
     { 	$('#mmail').val('mail'); }	
 
  	if	( ($('#mtelefono').val()=='') && ('mtelefono'!=id) )
     { 	$('#mtelefono').val('telefono'); }


	if	( ($('#nome').val()=='') && ('nome'!=id) )
     { 	$('#nome').val('nome e cognome'); }	
	 
	 	 
  	if	( ($('#email').val()=='') && ('email'!=id) )
     { 	$('#email').val('mail'); }
	 
	 
 

 } 



function iscrivi()
{
//email_disponibilita
var email_=$('#email').val();
var nome=$('#nome').val();

if($('#privacy').is(':checked')  )
{
privacy='on';
}
else
{
privacy='off';
}

$.post("salva_email_newsletter.php", 
           { email : email_,
		     nominativo : nome,
			 privacy  : privacy,
			 cap  :$('#cap').val()
		   },
           function(dati_ricevuti)
  		   {
//------------		
            
              var x=dati_ricevuti.split("||");

			   var esito=x[0];
			   var errori=x[1];	

			   if( (esito=='2') )
			    { 
				   if(errori.substring(0,1)==1)
				   {
				     // errore nel campo nominativo
					 $('#nome').css('color','red').effect("pulsate", { times:2 }, 1000);
				   }
				   else
				   {
				    $('#nome').css('color','#666666');
				   }
				   

				 
			       if(errori.substring(1,2)==1)
				   {
				     // errore nel campo email
					 $('#email').css('color','red').effect("pulsate", { times:2 }, 1000);
				   }
				   else
				   {
				    $('#email').css('color','#666666');
				   }				   
				   
			       if(errori.substring(2,3)==1)
				   {
				     // errore nel campo privacy
					 $('#aprivacy').css('color','red').effect("pulsate", { times:2 }, 1000);
				   }				   
				   else
				   {
				    $('#aprivacy').css('color','#586e08');
				   }			   
				}

			   if(esito=='1')
			    { $('#form').fadeOut(50);
				  $('#esito').fadeIn(1000).html('<div class="form_ok"></div>');
				//nscondo il box
				 if (this.timer1) clearTimeout(this.timer1);
				 this.timer1 = setTimeout(function () 
										{ 	$('#esito').fadeOut(1000);},3000);

				 if (this.timer2) clearTimeout(this.timer2);
				 this.timer2 = setTimeout(function () 
										{ 	 $('#form').fadeIn(1000);},4500);
										
										
				}
	

//------------	
				
		   }

     );
	
	
}
//]]


//--------

function invia_email()
{
//email_disponibilita
var emailm=$('#mmail').val();
var nomem=$('#mnome').val();
var telefonom=$('#mtelefono').val();
var messaggiom=$('#mmessaggio').val();


if($('#mprivacy').is(':checked')  )
{
privacym='on';
}
else
{
privacym='off';
}

$.post("invia_email.php", 
           { email : emailm,
		     nominativo : nomem,
			 telefono : telefonom,
			 messaggio : messaggiom,
			 privacy  : privacym,
			 cap  :$('#capm').val()
		   },
           function(dati_ricevuti)
  		   {
//------------		
            
              var x=dati_ricevuti.split("||");

			   var esito=x[0];
			   var errori=x[1];	

			   if( (esito=='2') )
			    { 
				   if(errori.substring(0,1)==1)
				   {
				     // errore nel campo nominativo
					 $('#mnome').css('color','red').effect("pulsate", { times:2 }, 1000);
				   }
				   else
				   {
				    $('#mnome').css('color','#666666');
				   }
				   

				 
			       if(errori.substring(1,2)==1)
				   {
				     // errore nel campo email
					 $('#mmail').css('color','red').effect("pulsate", { times:2 }, 1000);
				   }
				   else
				   {
				    $('#mmail').css('color','#666666');
				   }				   
				   
			       if(errori.substring(2,3)==1)
				   {
				     // errore nel campo privacy
					 $('#mmessaggio').css('color','red').effect("pulsate", { times:2 }, 1000);
				   }				   
				   else
				   {
				    $('#mmessaggio').css('color','#586e08');
				   }	
				   
				   
				   
				   
			       if(errori.substring(3,4)==1)
				   {
				     // errore nel campo privacy
					 $('#amprivacy').css('color','red').effect("pulsate", { times:2 }, 1000);
				   }				   
				   else
				   {
				    $('#amprivacy').css('color','#586e08');
				   }				   
				   
				   		   
				}

			   if(esito=='1')
			    { $('#mform').fadeOut(50);
				  $('#mesito').fadeIn(1000).html('<div class="form_ok_2"></div>');
				//nscondo il box
				 if (this.timer1) clearTimeout(this.timer1);
				 this.timer1 = setTimeout(function () 
										{ 	$('#mesito').fadeOut(1000);},3000);

				 if (this.timer2) clearTimeout(this.timer2);
				 this.timer2 = setTimeout(function () 
										{ 	 $('#mform').fadeIn(1000);},4500);
										
										
				}
	

//------------	
				
		   }

     );
	
	
}


function carica_testo(servizio)
{

$.post("carica_testo.php", 
           { servizio : servizio },
           function(dati_ricevuti)
  		   {
//------------		
              var x=dati_ricevuti.split("||");
		      var nome_servizio=x[0];
			  var descrizione_servizio=x[1];
			  
			  $("#nome_servizio").fadeIn(2000).html(''); 
			  $("#descrizione_servizio").fadeIn(2000).html('') ;	
			  
			  $("#nome_servizio").fadeIn(2000).html(nome_servizio) ;	
			  $("#descrizione_servizio").fadeIn(2000).html(descrizione_servizio) ;	
//------------	
		   }
     );
	 
	 return false;
}



//-------

// Funzione bounce per menu
$(document).ready(function(){
	
	
 if ($.browser.msie && $.browser.version.substr(0,1)<7) {
 var url = "http://www.epidemialab.it/ie6";    
$(location).attr('href',url);
}
			
						   
/* funzione bounce */							   
	var bouncespeed = 900;
	
	function bounce(currentA) {
		//newy = Math.floor(10*Math.random());
		//newspeed = bouncespeed + Math.floor(150*Math.random());
		var dato=$(currentA).css('marginTop').split('p');

		if(dato[0] > 0)
		 {   newy=-5;	 }
		 else
		 {  newy=5;	 }

	$(currentA).animate({marginTop:  newy + 'px '}, bouncespeed, 'linear', function() { bounce(currentA);});
	}
	
	
		$("div[class*=ballon]").each(
		function () {
		//alert($(this).attr("class"));
		//	$(this).css({marginTop: '0px '});
			bounce(this);
		}
	);	
		
/* Fine funzione bounce */	
	
		/* Apply fancybox to multiple items */
$(".iframe").fancybox();
	
	
			$("#easyslider").easySlider({
										prevId: 'prevBtn',
										prevText: '',
										nextId: 'nextBtn',	
										nextText: '',
										controlsShow: true,
										controlsBefore: '',
										controlsAfter: '',	
										controlsFade: true,
										firstId: 'firstBtn',
										firstText: 'First',
										firstShow: false,
										lastId: 'lastBtn',	
										lastText: 'Last',
										lastShow: false,				
										vertical: false,
										speed: 400,
										auto: false,
										pause: 2000,
										continuous: false
									});
									
									
									
									
		$("#guestbook_slider").easySlider({
										prevId: 'prevBtn2',
										prevText: '',
										nextId: 'nextBtn2',	
										nextText: '',
										controlsShow: true,
										controlsBefore: '',
										controlsAfter: '',	
										controlsFade: true,
										firstId: 'firstBtn2',
										firstText: 'First2',
										firstShow: false,
										lastId: 'lastBtn2',	
										lastText: 'Last2',
										lastShow: false,				
										vertical: false,
										speed: 800,
										auto: false,
										pause: 2000,
										continuous: false
								});									

	
 $(".menu_portfolio li a").eq(0).css("backgroundPosition","bottom right");	
})



// New
function loadPage(number){

	 //effettuo la chiamata Ajax
            $.ajax({
            type: "POST",
            url: "php/loadPage.php",
            data: ({ start:number }) ,
	success : function (data){  
	                         
							 $('#newsAjax').html('<img src="img/loader2.gif" />');
							 
								setTimeout(function () {
	                          $('#newsAjax').html(data);
                              $(".iframe").fancybox(); 
							}, 1500);

	
						  
							  
							  
							  }
			 });
	
	
}


