// jQuery script to handle band fans page
jQuery(document).ready(function($){
	
	// get values that we need for the AJAX below
	var band_id 	= $('#band_id').val();
	
	// bind addFavorite onclicks
	var bindAddFavorite = function() {
	  
		// Bind the onclick event 
		$('.addFavorite').bind (
			'click',
			function(){
					
				$('.favoriteBandControl').load('/ajax/addFavoriteBand.php?band_id=' + band_id, function() {
					$('.removeFavorite').unbind(); // unbind prior events first or else it will trigger twice
					bindRemoveFavorite();
					if (typeof(pageTracker) !== 'undefined') {
						pageTracker._trackPageview('/ajax/addFavoriteBand.php'); // track this AJAX call in google analytics
					}
				});
				return false; // return false so the link doesn't actually click anywhere					
			}
		);
	};
	
	
	// bind removeFavorite onclicks
	var bindRemoveFavorite = function() {
	  
		// Bind the onclick event 
		$('.removeFavorite').bind (
			'click',
			function(){
							
				if (confirmSubmit('Are you sure you want to remove this band as a favorite?')) {
							
					$('.favoriteBandControl').load('/ajax/removeFavoriteBand.php?band_id=' + band_id, function() {
						$('.addFavorite').unbind(); // unbind prior events first or else it will trigger twice
						bindAddFavorite();
						if (typeof(pageTracker) !== 'undefined') {
							pageTracker._trackPageview('/ajax/removeFavoriteBand.php'); // track this AJAX call in google analytics
						}
					});
					return false; // return false so the link doesn't actually click anywhere
				} else {
					return false;
				}
			}
		);		
	}
	
	bindAddFavorite();
	bindRemoveFavorite();

});