/**
 *  register a ready event for the document. 
 *  
 */

/*
 * TODO Do we want a way of registering which javascript files to load here so all of the following isn't included on every page
 * e.g registerJS(wanttosee) when it's needed and then check and include here?
 */
$(document).ready(function() {
	// Apply the lightbox to any a tags with lightbox class
	$('a.lightbox').lightBox(); // Select all links in the page
	
	// Apply the prettyPhoto lightbox without the slideshow option
	$("a[rel^='prettyPhoto']").prettyPhoto({
			social_tools: false,
			slideshow: false, 	
			overlay_gallery: false,
	});
	
	// Add the Want To See options to anything on the page
	
	var wanttoseehtml = "<img src='images/icons/wanttosee.png' alt='Want To See' title='Add this film to Your Films'>"
	$("a.wanttosee").html(wanttoseehtml);
		
	$(".wanttosee").click(function() {
		     
		// Sets the clicked on film to be want to see
		
		     var clickedOption = $(this).attr('id');
		     var pos = clickedOption.lastIndexOf("_"); 
		     var filmId = clickedOption.substr(pos+1);
		
		     
		 	// Set up params for ajax post call
		     var params = {};
		     params['ajax'] = 1;
		     params['film_id'] = filmId;
		     params['want'] = 1;
		     params['source']='W';
	
			$.post('../keswick_shared/action/edityourfilm.php', params,function(data){

				if (data==0){
					alert('Sorry the film could not be added to your collection at this time');
					
				} else {
					
					var updatehtml ="<a href='yourfilms.php'><img src='images/icons/yourfilms.png' alt='View Your Films' title='View Your Films'></a>";
				
					$(".filmcollectionoptions_"+filmId).html(updatehtml);
				}
			});
	});


	
});
