$(document).ready(function() {
  
  // checks to see if the input has text or not
  function currentInputState() {
    return ($('#email').val() != '');
  }
  
  // if on load, it does have text, hide the label
  if (currentInputState()) { $('#emailLabel').hide(); }
  
  // on click of the label or input force IE6 to focus on the input
  $('#email, #emailLabel').click(function() {
    $('#email').focus();
  });
  
  // on focus, if there is no text in the input, fade out
  $('#email').focus(function() {
    $('#emailLabel').fadeOut('fast');
  });
  
  // when leaving the input, fade in if theres no text
  $('#email').blur(function() {
    currentInputState() ? '' : $('#emailLabel').fadeIn('fast');
  });
  
});


$(document).ready(function(){

	$(document).pngFix();
	
	$(".success").hide();
	$(".error").hide();
	$(".loader").hide();
	
    $('form#newsletterForm').bind('submit', function(e){
		$(".successBalloon").hide();
		$(".errorBalloon").hide();
		$(".loader").show();
		var email  = $('input#email').val();
        e.preventDefault();
		
		$.ajax({
			type: 'POST',
			url: 'newsletter.php?email='+email,
			data: '',
			success: function(theResponse){
				if (theResponse == 1) {
					$(".success").fadeIn("slow");
					$(".success").animate({opacity: 1.0}, 3000);
				}
				if (theResponse == 2) {
					$(".error").fadeIn("slow");
					$(".error").animate({opacity: 1.0}, 3000);
					$(".error").fadeOut(1500);
				}
				if (theResponse == 3) {
					$(".error").fadeIn("slow");
					$(".error").animate({opacity: 1.0}, 3000);
					$(".error").fadeOut(1500);
				}
				$(".loader").hide();
			},
			error: function(){
				$(".error").fadeIn("slow");
				$(".error").animate({opacity: 1.0}, 3000);
				$(".error").fadeOut(1500);
				$(".loader").hide();
			}		
		});
	});
			
});

