var script = {
	init:function() {
		script.align();
		script.clearField();
		script.send();
		script.close();
	},
	
	align:function() {
		var content = $('#content');
		
		var height = content.height();
		var top = parseInt(content.css('top'));
		var position = height / 2;
		
		content.css('top', position);
	},
	
	send:function() {
		var form = $('form');
		
		form.submit(function(e) {
			var error = 0;
			
			$('.message').hide();
			
			var email = form.find('input[name="email"]');
			
			if(email.val() == '' || checkEmail(email.val()) == false) { error++; }
			
			if(error != 0) {
				$('#fail').slideDown();
			}
			else {
				$.post($(this).attr('action'), { email: email.val() }, function(respond) {
					$('.message').hide(); 
					if(respond == 'ko') {
						$('#fail').slideDown();
					}
					else {
						$('#success').slideDown();
					}
				});
			}
			
			e.preventDefault();
			return false;
		});
	},
	
	clearField:function() {
		var email = $('input[name="email"]');
		
		email.focus(function() {
			if($(this).val() == 'email') $(this).val('');
		});
		
		email.blur(function() {
			if($(this).val() == '') { $(this).val('email'); }
		});
	},
	
	close:function() {
		$('a.close').click(function(e) {
			$(this).parent('div').slideUp();
			
			e.preventDefault();
			return false;
		});
	}
};
