$(document).ready(function() {
	
	$('input[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));	
		}
		
		$(this).focus(function() {
			if($(this).val() == $(this).attr('title')) {
				$(this).val('').removeClass('unfocused');	
			}
		});
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).addClass('unfocused');	
			}
		});
	});
	
	
	
	
	$('#subscribeButton').click(function() {
		
		$('#errors').hide();
		$('#success').hide();
		
		$.ajax({
			url: "/main/subscribe",
			type: "POST",
			dataType: "html",
			data: { email : $('#inputEmail').val() },
			
			success: function(html) {
				
				if(parseFloat(html)) {
					
					$('#success').fadeIn('slow');
					$('#inputEmail').val('');
					$('#inputEmail').val($('#inputEmail').attr('title')).addClass('unfocused');
					window.setTimeout(function(){
						$('#success').fadeOut('slow');
					}, 4000);
					
				} else {
					
					$('#errors').html(html).fadeIn('slow');
					window.setTimeout(function(){
						$('#errors').fadeOut('slow');
					}, 5000);
				}
			}
		});
		
	});
	
	$('input[name="send"]').click(function() {
		
		$('#msgerrors').hide();
	
		$.ajax({
			url: "/team/send",
			type: "POST",
			dataType: "html",
			data: $('#contact_form').serialize(),
	
			success: function(html) {
		    	if(parseFloat(html)){
		    		$('input[name="name"]').val('');
		    		$('input[name="email"]').val('');
		    		$('textarea[name="message"]').val('');
		    		$('#msgsuccess').fadeIn('slow');
					window.setTimeout(function(){
						$('#msgsuccess').fadeOut('slow');
					}, 5000);		    		
		    	} else {
		    		$('#msgerrors').html(html).fadeIn('slow');
		    	}
			}
		});
	
	});
	
});
