$(document).ready(function(){

	var timestamp=0;
	$('#submitButton').click(function(e){

		var photoID = $('#photoID').val();
		var message = $('#message').val();
		var name = $('#name').val();
		var email = $('#email').val();
		var url = $('#url').val();
		// Only one todo per 5 seconds is allowed:
		if((new Date()).getTime() - timestamp<5000) return false;

		if (name.length == 0 || email.length == 0) {

			alert("You must enter your name and email address to post a comment.");

		} else {

			$.get("/comment.ajax.php",{'action':'new','photoID':photoID,'message':message,'name':name,'email':email,'url':url},function(msg){
	
				var originalColor = "#6f6f6f";
	
				if($("#descriptionExtended").length != 0) {
					// Appending the new todo and fading it into view:
					$(msg).hide().appendTo('#descriptionExtended').fadeIn().animate({ backgroundColor:'#a5a5a5' },'normal','linear', function(){ $(this).animate({ backgroundColor:originalColor }); });
				} else {
					$(msg).hide().appendTo('#description').fadeIn().animate({ backgroundColor:'#a5a5a5' },'normal','linear', function(){ $(this).animate({ backgroundColor:originalColor }); });
				}
			});

		}

		// Updating the timestamp:
		timestamp = (new Date()).getTime();

		e.preventDefault();
	});

});
