$(document).ready(function() {
	$('#slideshow').cycle({
		pause: true,
		fx: 'fade',
		before: function() {
			$('#caption p').remove();
			if(this.title != ''){
				$('#caption').append('<p style="display: none">'+this.title+'</p>');
				$('#caption p').fadeIn(400);
			}
		}
	});
	
	$(".banner-1 a, .banner-2 a").hover(
		function () {
			$('img', this).animate({
				opacity: 0.6
			}, 200);
		}, 
		function () {
			$('img', this).animate({
				opacity: 1
			}, 200);
		}
	);
	
	$(".gallery a, .galleryNav a").not('.active').hover(
		function () {
			$('img', this).animate({
				opacity: 1
			}, 200);
		}, 
		function () {
			$('img', this).animate({
				opacity: 0.6
			}, 200);
		}
	);
	
	$('.gallery a').live('click', function(e) {
		e.preventDefault();
		var link = $(this).attr('rel');
		var caption = $(this).children('img').attr('alt');
		$(this).parent().siblings('li').children('a').removeClass("active");
		$(this).addClass("active");
		$('#largeImage *').remove();
		$('#largeImage').prepend('<img src="'+link+'" alt="'+caption+'"><p class="caption">'+caption+'</p>');
	});
	
	$('#largeImage img').live('click', function(e) {
		e.preventDefault();
		if ($('.gallery ul li .active').parent('li').is(':last-child')) {
			var el = $('.gallery ul li:first-child a');
			var link = $('.gallery ul li:first-child a').attr('rel');
			var caption = $('.gallery ul li:first-child a img').attr('alt');
			$('#largeImage *').remove();
			$('#largeImage').prepend('<img src="'+link+'" alt="'+caption+'"><p class="caption">'+caption+'</p>');
			$('.gallery ul li .active').removeClass('active');
			el.addClass('active');
		} else {
			var el = $('.gallery ul li .active').parent().next().children('a');
			var link = $('.gallery ul li .active').parent().next().children('a').attr('rel');
			var caption = $('.gallery ul li .active').parent().next().children('a').children('img').attr('alt');
			$('#largeImage *').remove();
			$('#largeImage').prepend('<img src="'+link+'" alt="'+caption+'"><p class="caption">'+caption+'</p>');
			$('.gallery ul li .active').removeClass('active');
			el.addClass('active');
		};
	});
	
	$("#newsletterForm input").focus(function () {
    	if($(this).val() == ''){ 
			$(this).prev("label").animate({
				opacity: '0.4'
			}, 300);	
    	} else {
    		$(this).prev("label").animate({
    			opacity: '0'
    		}, 0);
    	}
    });

	$("#newsletterForm input").blur(function () {
    	if($(this).val() == ''){ 
    		$(this).prev("label").animate({
    			opacity: '1'
    		}, 300);
    	} else {
    		$(this).prev("label").animate({
    			opacity: '0'
    		}, 0);
    	}
    });

	$("#newsletterForm input").keypress(function() {
		$(this).prev("label").animate({
			opacity: '0'
		}, 0);
    });

	$("#newsletterForm").validate({
		rules: {
			field1: {
				required: true,
				email: true
			}
		}
	});
	
	$("#donationForm").validate({
		rules: {
			nome: "required",
			cognome: "required",
			email: {
				required: true,
				email: true
			},
			citta: "required",
			regione: "required",
			provincia: "required",
			telefono: "required",
			indirizzo: "required",
            privacy: "required"
		}
	});


	$("#contactForm").validate({
		rules: {
			field1: "required",
			field2: "required",
			field3: {
				required: true,
				email: true
			},
			field5: "required",
			field6: "required"
		}
	});


window.fbAsyncInit = function() {
        FB.init({appId: '133521176678371', status: true, cookie: true,
                 xfbml: true});
      };
      (function() {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
          '//connect.facebook.net/it_IT/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
      }());


});





