$(function() {  
	$('.yourfilmssubmit').click(function(e) {  

		// Disable the form to prevent further submissions
		$('.yourfilmssubmit').attr('disabled', 'disabled');

		// Hide the options and show the saving div
		$('#yourfilmoptionarea').hide();
		$('#yourfilmsaving').show();
		//Work out which element has been clicked
		var clickedOption = $(this).attr('name');
		
		// Initialise variables
		var action ='';
		var rating = -1;
		var filmId = $('input#film_id').val(); 
		var inCollection = $('input#in_collection').val();

		// Set up params for ajax post call
		var params = {};
		params['ajax'] = 1;
		params['film_id'] = filmId;
		params['in_collection'] = inCollection;
	
		switch (clickedOption) {

			case 'rating[1]' : 
							params['rating'] = 1;
							break;

			case 'rating[2]' : 
							params['rating'] = 2;
							break;

			case 'rating[3]' : 
							params['rating'] = 3;
							break;

			case 'rating[4]' : 
							params['rating'] = 4;
							break;

			case 'rating[5]' : 
							params['rating'] = 5;
							break;

			case 'remove' 	: 
							params['remove'] = 1;
							break;
			case 'want'		:
							params['want'] = 1;
							break;
			case 'later' 	:
							params['later'] =1;
							break;
							
		}

		$.post('../keswick_shared/action/edityourfilm.php', params,
				  function(data){
			
					if (data!=0) {
						// Animate 'nothing' to ensure message is seen
						$('#yourfilmsaving').animate({opacity: 1.0}, 1000,function(){
							$('#yourfilmholder').html(data);  
							// Hide the message area over 5 seconds (but not currently setting a message) 
							$('#yourfilmsupdatemessage p').hide(5000);
						 }); 
						
					
					} else {
						// Clear any message currently on the page to prevent it being repeated on sucessive calls
						$('#yourfilmsupdatemessage').html();  
						
						//Enable buttons again
						$('.yourfilmssubmit').removeAttr('disabled');
						$('#yourfilmsupdatemessage').html('Sorry, there was a problem updating your film collection');  
						// Show options hide saving
						$('#yourfilmoptionarea').show();
						$('#yourfilmsaving').hide();
					}
		});

		return false;
 	});  
});  
