// jQuery script to handle user show activity: attend/unattend show
jQuery(document).ready(function($){
	
	var bindAttendShow = function() {
		$('.addAttendShow').each(
  			
			// For each attend link, bind AJAX
			function() {
  
				// Bind the onclick event 
				$(this).bind (
					'click',
					function(){
						
						var theId = $(this).attr('id'); // get ID of clicked element, eg: add3537
						var tourdate_id = theId.substr(3); // strip off the user ID from the element ID, eg: 3537

						$(this).parent().parent().hide().load('/ajax/addAttendingShow.php?tourdate_id=' + tourdate_id, function() {
							$(this).fadeIn();
							if (typeof(pageTracker) !== 'undefined') {
								pageTracker._trackPageview('/ajax/addAttendingShow.php'); // track this AJAX call in google analytics
							}
						});
						
						return false; // return false so the link doesn't actually click anywhere					
					}
				);
			}
		);
	};
	
	var bindUnattentShow = function() {
		$('.removeAttendShow').each(
  			
			// For each attend link, bind AJAX
			function() {
  
				// Bind the onclick event 
				$(this).bind (
					'click',
					function(){
						
						var theId = $(this).attr('id'); // get ID of clicked element, eg: remove3537
						var tourdate_id = theId.substr(6); // strip off the user ID from the element ID, eg: 3537

						$(this).parent().parent().hide().load('/ajax/removeAttendingShow.php?tourdate_id=' + tourdate_id, function() {
							$(this).fadeIn();
							if (typeof(pageTracker) !== 'undefined') {
								pageTracker._trackPageview('/ajax/removeAttendingShow.php'); // track this AJAX call in google analytics
							}
						});
						
						return false; // return false so the link doesn't actually click anywhere					
					}
				);
			}
		);
	};
	
	bindAttendShow();
	bindUnattentShow();
});