$(document).ready(function() {

//nascondo il wrapper
$('body').css('overflow', 'hidden');

$('#page-wrapper').fadeOut();

//mostro lo slideshow
$('#supersized').show();

// ingresso al click del logo
$('#logo-start').click(function () {

	$('body').css('overflow', 'visible');
	
	$('#enter').fadeOut();
 	
 	$('#logo-start').fadeOut();
 	
 	$('#less').fadeOut();
  	
  	$('#supersized').animate({
    left: 3000
 	}, 1000, function() {
    // Animation complete.
  	});
    
    $('#more').fadeIn();
    
    $('#screen').animate({
    left: 3000
    }, 1000, function() {
    // Animation complete.
    });
    
    $('#start-bg').animate({
    left: 3000
    }, 1000, function() {
    // Animation complete.
    $('#page-wrapper').fadeIn(); 
    $('.wrap').masonry();  
    });
   
});	    


//ingresso al click di enter	
$('#enter').click(function () {

	$('body').css('overflow', 'auto');
	
	$('#enter').fadeOut();
 	
 	$('#logo-start').fadeOut();
 	
 	$('#less').fadeOut();
  	
  	$('#supersized').animate({
    left: 3000
 	}, 1000, function() {
    // Animation complete.
  	});
    
    $('#more').fadeIn();
    
    $('#screen').animate({
    left: 3000
    }, 1000, function() {
    // Animation complete.
    });
    
    $('#start-bg').animate({
    left: 3000
    }, 1000, function() {
    // Animation complete. 
    $('#page-wrapper').fadeIn(); 
    $('.wrap').masonry();  
  	});
  	
});


//richiamo fotoslide
$('#more').click(function () {
	$('#page-wrapper').fadeOut();
	
  $(this).hide();
	
  $('body').css({
    overflow: 'hidden'
  }, 1000, function() {
    // Animation complete.
  });
  
  $('#screen').animate({
    left: 0
  }, 1000, function() {
    // Animation complete.
  });
  
  $('#start-bg').animate({
    left: 0
  }, 1000, function() {
    // Animation complete.
  });
  
  $('#supersized').animate({
    left: 0
  }, 1000, function() {
    // Animation complete.
    $(this).show();
    $('#logo-start').fadeIn();
    $('#less').fadeIn();
  });
   
});

//nascondo fotoslide
$('#less').click(function () {

	$(this).hide();

	$('body').css({
    overflow: 'visible'
    }, 1000, function() {
    // Animation complete.
    });
	
	$(this).fadeOut();
 	$('#logo-start').fadeOut();
  
    $('#supersized').animate({
     left: 3000
    }, 1000, function() {
    // Animation complete.
    $('#more').fadeIn();
    });
  
    $('#screen').animate({
      left: 3000
    }, 1000, function() {
     // Animation complete.
    });
  
    $('#start-bg').animate({
      left: 3000
    }, 1000, function() {
    // Animation complete.
    $('#page-wrapper').fadeIn(); 
    $('.wrap').masonry(); 
    });
});



// slider immagini nei post
$('.immagini').cycle({
		fx: 'scrollUp', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 4000,
		speed: 400,
		pause:   true
});
	

//fine domready
});






$(window).load(function(){

	var
  	speed = 500,  // animation speed
  	$wall = $('#content').find('.wrap')
	;

	$wall.masonry({
  	columnWidth: 1, 
  	// only apply masonry layout to visible elements
  	itemSelector: '.box:not(.invis)',
  	animate: true,
  	animationOptions: {
    duration: speed,
    queue: true
  	}
	});
	 
 	$('loading').fadeOut(); 
  
});


//AJAX start
$(document).ajaxStart(function() {

$('#loading').fadeIn();

});

//AJAX COMPLETE
$(document).ajaxComplete(function() {
	
	var
  	speed = 500,  // animation speed
  	$wall = $('#content').find('.wrap')
	;

	$wall.masonry({
  	columnWidth: 1, 
  	// only apply masonry layout to visible elements
  	itemSelector: '.box:not(.invis)',
  	animate: true,
  	animationOptions: {
    duration: speed,
    queue: true
  	}
  	
    }); 


	$('.immagini').cycle({
		fx: 'scrollUp', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 4000,
		speed: 400,
		pause:   true
	});
 
//FINE AJAX COMPLETE
});


$(document).ajaxStop(function() {


	$('#loading').fadeOut();

	setTimeout(function(){
	
	  	var
  		speed = 500,  // animation speed
  		$wall = $('#content').find('.wrap')
		;

		$wall.masonry({
  		columnWidth: 1, 
  		// only apply masonry layout to visible elements
  		itemSelector: '.box:not(.invis)',
  		animate: true,
  		animationOptions: {
   		duration: speed,
    	queue: true
  		}
		});
	 
	}, 3000);
	

});






