$(document).ready(function() {
	$('#slideshow').cycle({timeout:5000});
	//for the quick notes
	var quicknote = $('.quick-note');
	quicknote.click(function() {
		$('#quickform').show();
		return false;
	});
	$('#quickclose').click(function() {
		$('#quickform').hide();
		return false;
	});
	
	//clears inputs & textarea
	$('input:text,textarea').focus(function(){
	        if($(this).val() == $(this).attr('defaultValue')){
	            $(this).val('');
	        }
	    });

	    $('input:text,textarea').blur(function(){
	        if($(this).val() == ''){
	            $(this).val($(this).attr('defaultValue'));
	     }
	 });
	
	//this checks for valid Email & Subject for the contact form
	$("#quicksubmit").click(function() {
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var emailValue = $("#quickemail").val();
		var nameValue = $("#quickname").val();
		var textValue = $("#quicktext").val();
		if(emailValue == "your email"){
			$("#quickemail").addClass('error');
			$("#quickemail").val("Please enter a valid email address");
			hasError = true;
		}
		else if(!emailReg.test(emailValue)){
			$("#quickemail").addClass('error');
			$("#quickemail").val("Please enter a valid email address");
			hasError = true;
		}
		if(nameValue == "your name"){
			$("#quickname").addClass('error');
			$("#quickname").val("Please enter your name.");
			hasError = true;
		}
		if(textValue == "what would you like to say?"){
			$("#quicktext").addClass('error');
			$("#quicktext").val("Don't forget to tell us something.");
			hasError = true;
		}
		//alert(checkValue);
		//alert(hasError);
		if(hasError == false){
			//alert('we got this far');
			$(this).hide();
			//$("#loading").fadeIn('fast');
			$.ajax({
				url: "_include/quicknote.php",
				type: "POST",
				data:'name=' + nameValue + "&email=" + emailValue + "&text=" + textValue + "&submit=true",		
				dataType:"JSON",
				success: function(data) {
					var obj = JSON.parse(data);
					//alert(obj.checkbox);
					console.log(data);
					$("#quickform").hide('fast', function() {
						$("#success").slideDown();
					});
				},
				error: function(result) {
					alert(result);
					alert('no go');
				}
			});		
		}
		return false;
	});
});

