$(document).ready(function() {

	$('#continue').hover(
		function () { $('#continue').addClass('join-club-mouseover'); },
		function () { $('#continue').removeClass('join-club-mouseover'); }
	);
	
	$('#continue').click(
		function(e) {
			e.preventDefault();
	
			$('#continue').addClass('join-club-clicked');
			$('#continue-message').html("<span class='grey'>Working...Please wait.</span>");
			$('#continue').unbind('hover');
			if ($("span[id^='bg_']").hasClass('bg-red') == true) { 
				$("span[id^='bg_']").removeClass('bg-red');
			} else { };
		   
		  	var data = $('#form1').serialize();
			
			$.post('sharks-club-do.php?jsoncallback=?',data,function(json) {
				
				if (json.response == "1") {
					$('#sharks-club-div').load("include-sharks-club-submitted.php", function() { alert("Thank you! You have successfully subscribed to the Wine Club."); });
					
				} else if (json.response == "2") {
				
					for (i=0; i < json.labels.length; i++) {
						$('#bg_'+json.labels[i]).addClass("bg-red");
					}
					
					$('#continue-message').html("<span class='red'>"+json.details+"</span>");
					$('#continue').removeClass('join-club-clicked');
					
				} else {
					
					$('#continue-message').html("<span class='red'>"+json.details+"</span>");
					$('#continue').removeClass('join-club-clicked');
				}
				
			},'json');
		}
	);
	
});
