$(document).ready(
	function() {
		$('#closeBtn').click( 
				function() {
					$(this).parent().fadeOut('slow');
				}
		);
		$('#btnMailinglist').click(
			function() {
				$('.mailing-list-form').fadeIn('slow');
			}
		);
		
		$('a#mailinglist').click(
			function(){
				$('a#mailinglist').hide();
				
				mailinglist=$.ajax({
					type: "POST",
					url: "home",
					data:$('input.mailinglist'),
					dataType:"json",
					error: function(){
//						location.reload(true);
					},
					success: function(resp){
						if(resp.Errors){
							msg='Your form contained the following errors:\n\n';
							for(i in resp.Errors){
								msg+='- '+resp.Errors[i]+'\n';	
							}
							alert(msg);
						}
						else {
							$('.mailing-list-form').fadeOut('slow');
							$('.mailinglist').each(
								function(){
									if(this.type=='checkbox' || this.type=='radio'){
										this.checked=false;	
									}
									else {
										this.value='';
									}
								}
							);
							alert('Thank-you for signing up to our newsletter.');	
						}
						$('a#mailinglist').show();
					}
				});
			}
		);
	}
);
