$(document).ready(function(e) {
	
	//
	// Mailing List
	//
	
	// Init
	
	var scriptlocation = $('#mailingList form').attr('action');
	
	$('#mailingList form button')
	.addClass('disabled')
	.attr({
		disabled : true
	});
	
	// Placeholder
	
	var init = $('#mailingList form input').val();
	var initColour = $('#mailingList form input').css('color');
	
	$('#mailingList form input')
	.focus(function() {
		
		var x = $(this).val();
		
		if ( x == init ) {
		
			$(this).val('');
			
			$(this).css({
				'color' : '#666666'
			});
		
		};
		
	})
	.blur(function() {
		
		var x = $(this).val();
	
		if ( x == init || x == '' ) {
		
			$(this).val(init);
			
			$(this).css({
				'color' : initColour
			});
		
		};

	})
	.bind('keyup change', function() {
		
		var element = $(this);
		var x = $(this).val();
		
		$.ajax({
			url: scriptlocation,
			type: 'POST',
			data: 'ml-email=' + x,
			success: function(data) {
				
				if ( data == 1 ) {
					
					$(element).next('button')
					.removeClass('disabled')
					.removeAttr('disabled');
					
				}
				else {
					
					$(element).next('button')
					.addClass('disabled')
					.attr({
						disabled : true
					});
					
				};
				
  			}
		});

	});
	
	$('#mailingList form button').hover(
	function() {
	
		$(this).addClass('hover');
	
	},
	function() {
	
		$(this).removeClass('hover');
	
	});
	
	//
	// Question
	//
	
	$('#question form .radio-question input').hide();
	$('#question form .radio-question label').before('<div class="radio-button">');
	
	var originalColour = $('#question form .radio-question .radio-button').css('background-color');
	
	$('#question form .radio-question').hover(
	function() {
	
		$(this).find('.radio-button, label').addClass('hover');
	
	},
	function() {
		
		$(this).find('.radio-button, label').removeClass('hover');
		
	})
	.click(function() {
		
		$(this).parent().find('.radio-button, label').removeClass('checked');
		$(this).find('.radio-button, label').addClass('checked');
		
		$(this).parent().find('button')
		.removeClass('disabled')
		.removeAttr('disabled');
		
	});
	
	$('#question form button').hover(
	function() {
	
		$(this).addClass('hover');
	
	},
	function() {
	
		$(this).removeClass('hover');
	
	});
	
	// Equalise Height
	
	var x = $('#mailingList').height();
	var y = $('#question').height();
	
	if ( x > y ) {
		
		$('#question').height(x);
	
	}
	else if ( x < y ) {
		
		$('#mailingList').height(y);
	
	};
	
});
