$(document).ready(function(){ 
 $('#portfolioShowreel .image li:first-child').css({display: 'block'});
  $('#slides').codaSlider();

	$("a[rel=fancybox1]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});

	$("a[rel=fancybox2]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox3]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox4]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox5]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox6]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox7]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox8]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox9]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox10]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


	$("a[rel=fancybox11]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


  $('#payoff p').textShadow({
  	color:   "#ccc",
  	opacity: "20"
  });


  // customizzazione del validate
  $('#contactForm').validate({
  	errorPlacement: function(error, element) {
  		error.appendTo( element.parents('p').addClass('error') );
  	},
  	highlight: function( element, errorClass ) {
  		$( element ).addClass( errorClass ).parents('p').removeClass('success').addClass('error');
  	},
  	unhighlight: function( element, errorClass ) {
  		$( element ).removeClass( errorClass ).parents('p').removeClass('error').addClass('success');
  	}
  });


  // stile per il notice
  if( $('.notice').length > 0){   
    $(".notice").animate({ opacity: 1000 }, 4000 );
    $(".notice").delay(2000).animate({ opacity: 0 });

  }  
  if( $('#messages').length > 0){
     //$('#messages').hide();
    // $("#messages").delay(1200).slideToggle();
     $('#messages a') .click(function () { 
       $('#messages').slideUp(); 
     });    
  }

 if( $('.claim').length > 0){
     $('.claim').hide();
     $(".claim").delay(600).fadeIn(1000);
 }
 
 if( $('#illustration').length > 0){
     $('#illustration').hide();
     $("#illustration").delay(1200).fadeIn(1000);
 }
 
 if( $('#text .textContent').length > 0){
     $('#text .textContent').hide();
     $("#text .textContent").delay(1000).fadeIn(600);
 }


if( $('#contactForm').length > 0){
  $('#contactForm').submit(function() {

  	// controllo che i fields non abbiano valore di default
  	// in caso positivo ne svuoto il valore
    // for (var i = 0; i < fields.length; i++){
    //        if ( $(fields[i].id).val() == fields[i].message )
    //          $(fields[i].id).val('');
    //      }
  
  	if ($("#contactForm").valid()){
  		// submit the form
  		/*
  	$.post(
  			"",
  			{
  				ajax: "yes",
  				create: "lead",
  				autore: $('#autore').val(),
  				email: $('#email').val(),
  				url: $('#url').val(),
  				comment: $('#comment').val()
  			},
  	
  		);
  		*/
  	}
  	// return false;

  });
}

var cloudMoved = false;
var cloud2Moved = false;
var cloud3Moved = false;

$(init);

function init()
{
	cloudMove();
	cloud2Move();
	cloud3Move();
	
}

function cloudMove(){
  if( $('#cloud').length > 0){
   	if (!cloudMoved){
  		$("#cloud")
  			.css("left", $("#cloud").offset().left)
  	}

  	$("#cloud").animate(
  			{
  				left: $("").width()
  			},
  			cloudMoved ? 180000 : 150000,"linear",
  			function(){
  				$(this).css("left", -parseInt($(this).css("width")))
  				cloudMoved = true;
  				cloudMove();
  			}
  		)
  } 
}

function cloud2Move(){
  if( $('#cloud2').length > 0){
    if (!cloud2Moved)	{
  		$("#cloud2")
  			.css("left", $("#cloud2").offset().left)
  	}
  	$("#cloud2")
  		.animate(
  			{
  				left: $("").width()
  			},
  			cloud2Moved ? 120000 : 60000,
  			"linear",
  			function()
  			{
  				$(this)
  					.css("left", -parseInt($(this).css("width")))
  				cloud2Moved = true;
  				cloud2Move();
  			}
  		)
	}
}

function cloud3Move(){
  if( $('#cloud3').length > 0){
    if (!cloud3Moved)
  	{
  		$("#cloud3")
  			.css("left", $("#cloud3").offset().left)
  	}
  	$("#cloud3")
  		.animate(
  			{
  				left: $("").width()
  			},
  			cloud3Moved ? 400000 : 150000,
  			"linear",
  			function()
  			{
  				$(this)
  					.css("left", -parseInt($(this).css("width")))
  				cloud3Moved = true;
  				cloud3Move();
  			}
  		)
	}
}





}); 



