$(document).ready(
	function(){			
	$('ul#portfolio').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence',
		containerheight: '220px'
	});
	
	// ++++++ Validation of registration form -- to be removed +++++++
	$("#commentForm").validate();
	/*
		$("#commentForm").validate({
			rules: {
				dancer_birthdate: {
					required: true,
					date: true
				}
			}
		});
	*/
	
	// ++++++ Adding a new dancer ++++++++
	//When the button with an id of submit is clicked (the submit button)
	$("#newdancer_submit").click(function(){
		//Retrieve the contents of the form
		var formvalue1 = $("#dancer_name").val();
		var formvalue2 = $("#bdyear").val();
		var formvalue3 = $("#bdmonth").val();
		var formvalue4 = $("#bdday").val();
		var formvalue5 = $("#studio_id").val();
		var dancer_birthdate = formvalue2 + '-' + formvalue3 + '-' + formvalue4;
			
		//Build the URL that we will send
		var url = 'newdancer_submit=1&dancer_name=' + formvalue1 + '&dancer_birthdate=' + dancer_birthdate + '&studio_id=' + formvalue5;
		
		//Use jQuery's ajax function to send it
		$.ajax({
		   type: "POST",
		   url: "registration/registration_process.php",
		   data: url,
		   success: function(){
				//If successful , notify the user that it was added
				$('ul#dancerlist').before("<p class='new'>You just added: <i>" + formvalue1 + ".</i> Refresh the page to see the updated list.</p>");
		   }
		});
		
		//We return false so when the button is clicked, it doesn't follow the action
		return false;
	});
	
	// ++++++ Removing a dancer ++++++++
	//Check to see if an anchor link was clicked (The delete link)
	$("a.dancers").click(function(){
	
		//Save the link in a variable called element
		var element = $(this);
		
		//Find the id of the link that was clicked
		var noteid = element.attr("id");
		
		//Build a url to send
		var info = 'id=' + noteid;
		
		 $.ajax({
		   type: "GET",
		   url: "registration/registration_delete.php",
		   data: info,
		   success: function(){
		   	element.parent().eq(0).fadeOut("slow");
		   }
		 });
	
		//We return false so the browser doesn't actually follow the link
		return false;
	});
	
	prettyPrint();
});
