$(document).ready(function(){
	
	Cufon.replace('#header #main-navigation li a, #header #secondary-navigation li a', {fontFamily: 'Sansation'});
	Cufon.replace('#header #main-navigation li.selected a', {fontFamily: 'Sansation', textShadow: '#54641d 1px 1px 1px'});
	Cufon.replace('#footer div.box div.title', {fontFamily: 'Sansation', textShadow: '#000 1px 1px 1px'});
	
	Cufon.replace('h1', {fontFamily: 'Tertre', textShadow: '#54641d 1px 1px 1px'});
	Cufon.replace('h1 span', {fontFamily: 'Tertre'});
	Cufon.replace('#team .member .info .name, #wrapper .info .name, h2.title', {fontFamily: 'Tertre'});
	
	if($('body').hasClass('home')){
		$("body.home .main-thumbnail").attr("href", $("body.home .gallery .gallery-item .gallery-icon a:first").attr("href")).attr("title", $("body.home .gallery .gallery-item .gallery-icon a:first").attr("title"));
		$("body.home .gallery .gallery-item:first").remove();
		$("body.home .gallery .gallery-item .gallery-icon a").addClass("fancybox").attr("rel","features");
	}
	
	$('#footer input#form-name').val('Nome')
	$('#footer input#form-email').val('E-mail')
	$('#footer textarea').val('Messaggio')
	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
		$('#twitter').addClass('hidebird');   
	}
	
	$('#footer input#form-name').focus(function(){
		if($(this).val() == "" || $(this).val() == "Nome"){	
			$(this).val("");
		}
	});
	
	$('#footer input#form-email').focus(function(){
		if($(this).val() == "" || $(this).val() == "E-mail"){	
			$(this).val("");
		}
	});
	
	
	$('#footer textarea#form-message').focus(function(){
		if($(this).val() == "" || $(this).val() == "Messaggio"){	
			$(this).val("");
		}
	});
	
	$('#footer input#form-name').focusout(function(){
		if($(this).val() == ""){
			$(this).val("Nome");
		}
	});
	
	$('#footer input#form-email').focusout(function(){
		if($(this).val() == ""){
			$(this).val("E-mail");
		}
	});
	
	$('#footer textarea#form-message').focusout(function(){
		if($(this).val() == ""){
			$(this).val("Messaggio");
		}
	});
	
	$('a.fancybox').fancybox({
		'titlePosition': 'over',
		'centerOnScroll': true
	});
	
	$('li.page-item-449').children('a').attr("href","#footer").attr("rel","scroll");
	
	// jQuery SmoothScroll | Version 10-04-30
	$('a[rel=scroll]').click(function() {
	
	   // duration in ms
	   var duration=2000;
	
	   // easing values: swing | linear
	   var easing='easeInOutExpo';
	
	   // get / set parameters
	   var newHash=this.hash;
	   var target=$(this.hash).offset().top;
	   var oldLocation=window.location.href.replace(window.location.hash, '');
	   var newLocation=this;
	
	   // make sure it's the same location      
	   if(oldLocation+newHash==newLocation)
	   {
	      // animate to target and set the hash to the window.location after the animation
	      $('html:not(:animated),body:not(:animated)').animate({ scrollTop: target }, duration, easing, function() {
	
	         // add new hash to the browser location
	         window.location.href=newLocation;
	      });
	
	      // cancel default click action
	      return false;
	   }
	});
	
	if(!$.browser.msie){
		$('#wrapper').masonry({ singleMode: true });
	}
	
	$("span.bt-company-vat input").keydown(function(event) {
	        // Allow only backspace and delete
	        if ( event.keyCode == 46 || event.keyCode == 8 ) {
	                // let it happen, don't do anything
	        }
	        else {
	                // Ensure that it is a number and stop the keypress
	                if (event.keyCode < 48 || event.keyCode > 57 ) {
	                        event.preventDefault(); 
	                }       
	        }
	    });
	$("span.wpcf7-list-item-label").click(function(){
		if($(this).prev().is(':checked')){
			$(this).prev().attr('checked', false);
		}else{
			$(this).prev().attr('checked', true);
		}
	});
	
});
