jQuery(document).ready(function(){    
     
     var url = document.location.href;
     str = url.substr(url.lastIndexOf("/"), url.length);
     if(str != '/index.html' && str != '/'){
       $('body').scrollTo({ top: 470, left:'0' }, 1000);
     }
     
     $(document).scroll(function(){
       of = $(document).scrollTop();
       if(of < 200){
         $('#scrolltop').fadeOut("2000");
       }else{
         $('#scrolltop').fadeIn("2000");
       }
     });
     
     $('#scrolltop').click(function(){
       $('body').scrollTo({ top: 0, left:'0' }, 1000);
     });
     
     $(".toptext li a").hover(function(){
     			      $(this).find('.hide').fadeIn("slow");
     			    },
     			    function(){
     			      $(this).find('.hide').fadeOut("fast");
     			    }
     			    );
     			    
     $(".rightext li a").hover(function(){
     			      $(this).find('.hider').fadeIn("slow");
     			    },
     			    function(){
     			      $(this).find('.hider').fadeOut("fast");
     			    }
     			    );
     			    
     $("#showbody a").tooltip({
     		       track: true,
     		       delay: 0,
     		       showURL: true,
     		       showBory: " - ",
     		       fade: 250
     		     });
     		     
     $(".lavori img").tooltip({
     		       track: true,
     		       delay: 0,
     		       showURL: true,
     		       showBory: " - ",
     		       fade: 250
     		     });
     		     
     $(".lavori").hover(function(){
     			  $(this).find('.image').delay(200).animate({height:296}, 500, 'linear');
     			  $(this).delay(200).animate({height:550}, 500, 'linear');
     			},
     			function(){
     			  $(this).find('.image').delay(200).animate({height:110}, 500, 'linear');
     			  $(this).delay(200).animate({height:200}, 500, 'linear');
     			}
     			);
     			
     $("#errorid").click(function(){
               $(".error").toggle("slow");
     });
     
     $("#welldoneid").click(function(){
               $(".welldone").toggle("slow");
     });
     
     function sendmail(){
       $("#wait").html('<img src="img/loader.gif" alt="wait" class="valign" />');
       $("#invia").attr("disabled", "disabled");
       
       $.ajax({
             url: 'ajax/get/contact.ajx',
	     type: 'POST',
	     data: $('#formcontatti').serialize(),
	     
	     error: function(response){
	       alert('Errore imprevisto');
	       $("#invia").removeAttr("disabled");
	     },
	     
	     success: function(response){
	       var data = eval('(' + response + ')');
	       if(data.succ == 'ERROR'){
	         alert(data.res);
	         $("#wait").html('');
	         $("#invia").removeAttr("disabled");
	       }else{
	         $("#resajax").html(data.res).fadeIn("slow");
	         $('body').scrollTo( { top: 470, left:'0' }, 500);
	         $("#wait").html('');
	       }
	     }
       });
       return false;
     }
     
     function about(){
       $('body').scrollTo({ top: 470, left:'0' }, 1000);
     }     
     
     $("#formcontatti").bind("submit", sendmail);
     			        			    
});

