/*----------------------------------------------------------
	Behaviors for the nav tabs bar found in the show spaces
----------------------------------------------------------*/

jQuery(document).ready(function() {
	var showName = jQuery('h1.show_title').text();
	if(showName==''){
		showName = jQuery('#smallhead .title').text();
	}
		
	//add to or remove from favorites
	jQuery('.add_to_favorites:not(.login_required), .remove_from_favorites:not(.login_required)').click(function(){
		var thisLink = jQuery(this);
		var thisHref = thisLink.attr('href');
		var addingShow = jQuery(this).hasClass('add_to_favorites');
		var removingShow = jQuery(this).hasClass('remove_from_favorites');

		if(addingShow){
			var callbackFunction = jQuery(thisLink).removeClass('add_to_favorites').addClass('on_state remove_from_favorites').text('Favorited');
			
			jQuery.post(thisHref,{},function(){
				jQuery('body').growl({
					notificationClass:'success',
					notificationContent:'<p><span class="show_name">'+showName+'</span> has been added to your Favorites.</p>',
					callback: callbackFunction
				});
			});
			
		}else if(removingShow){
			var callbackFunction = jQuery(thisLink).removeClass('on_state remove_from_favorites').addClass('add_to_favorites').text('Favorite');
			
			jQuery.post(thisHref,{},function(){
				jQuery('body').growl({
					notificationClass:'error',
					notificationContent:'<p><span class="show_name">'+showName+'</span> has been removed from your Favorites.</p>',
					callback: callbackFunction
				});
			});
		}
		
		return false;
	});
});//closes document ready---------------------------------------------------------------------

