$(document).ready(function(){
	$("a.bt-news").click(function () {
		$(".toggle").toggle("normal");
	});

	$(document).pngFix();

	var invalidMailError	= "Este e-mail<br />não é válido.";
	var duplicateMailError	= "Este e-mail<br />já está<br />na lista.";
	var systemError			= "Um erro<br />ocorreu.<br />Por favor,<br />tente novamente.";
	var successMessage		= "Seu e-mail<br />foi adicionado<br />com sucesso!";

	$(".successBalloon").hide();
	$(".errorBalloon").hide();
	$(".resultText").hide();
	$(".loader").hide();

	$('form#fNews').bind('submit', function(e){
		$(".successBalloon").hide();
		$(".errorBalloon").hide();
		$(".resultText").hide();
		$(".loader").show();
		var nome  = $('input#nomeNews').val();
		var email  = $('input#emailNews').val();
		e.preventDefault();

		$.ajax({
			type: 'POST',
			url: 'newsletter.php?email='+email+'&nome='+nome,
			data: '',
			success: function(theResponse){
				$(".resultText").fadeIn("slow");
				$(".resultText").animate({opacity: 1.0}, 3000);
				$(".resultText").fadeOut(1500);

				if (theResponse == 1) {
					$(".successBalloon").fadeIn("slow");
					$(".successBalloon").animate({opacity: 1.0}, 3000);
					$(".successBalloon").fadeOut(1500);
					$(".resultText").html(successMessage);
				}
				if (theResponse == 2) {
					$(".errorBalloon").fadeIn("slow");
					$(".errorBalloon").animate({opacity: 1.0}, 3000);
					$(".errorBalloon").fadeOut(1500);
					$(".resultText").html(invalidMailError);
				}
				if (theResponse == 3) {
					$(".errorBalloon").fadeIn("slow");
					$(".errorBalloon").animate({opacity: 1.0}, 3000);
					$(".errorBalloon").fadeOut(1500);
					$(".resultText").html(duplicateMailError);
				}
				$(".loader").hide();
			},
			error: function(){
				$(".errorBalloon").fadeIn("slow");
				$(".errorBalloon").animate({opacity: 1.0}, 3000);
				$(".errorBalloon").fadeOut(1500);
				$(".resultText").html(systemError);
				$(".loader").hide();
			}
		});
	});

	
	//GALERIA DE FOTOS
	var gallery = $('#gallery').galleriffic('#navigation', {
		delay:                3000,
		numThumbs:            6,
		imageContainerSel:    '#slideshow',
		controlsContainerSel: '#controls',
		titleContainerSel:    '#image-title',
		descContainerSel:     '#image-desc',
		downloadLinkSel:      '#download-link'
	});

	gallery.onFadeOut = function() {
		$('#details').fadeOut('fast');
	};

	gallery.onFadeIn = function() {
		$('#details').fadeIn('fast');
	};
	
	$("span.play").hover(function () {
		$(this).css({'background-color' : '#333', 'font-weight' : 'bold'});
	}, function () {
		var cssObj = {
		'font-size:' : '11px',
		'background' : '#5EB9F9',
		'color' : '#fff'
		}
		$(this).css(cssObj);
	});

});
