/*
 favorite.js
 
 Script for handling asynchronous changes to user favorites.
*/

// function for adding or removing a favorite
function favorite(string, category, type, classToken, fadeId)
{
	// we'll determine an action later
	action = '';
	
	// if a favorite is being added
	if ($('a.' + classToken).hasClass('normal'))
	{
		// reflect that the favorite has been added
		$('a.' + classToken).removeClass('normal');
		$('a.' + classToken).addClass('added');
		
		// update the link title as well
		$('a.' + classToken).attr('title', 'Remove from Favorites');
		
		// set the action accordingly
		action = 'add';
	}
	
	// else it is being removed
	else
	{
		// reflect that the favorite has been removed
		$('a.' + classToken).removeClass('added');
		$('a.' + classToken).addClass('normal');
		
		// update the link title as well
		$('a.' + classToken).attr('title', 'Add to Favorites');
		
		// if a request has been made to fade an element
		if (null != fadeId)
		{
			// fade the element
			$('#' + fadeId).fadeOut('slow');
			$('#' + fadeId).remove();
		}
		
		// set the action accordingly
		action = 'remove';
	}
	
	// now actually perform the action
	$.post('/switch.php', { favorite: string, category: category, type: type, action: action } );
}
