function add_favourite(unit_id, str_to_show, str_to_return){
	
	if(!str_to_show) { //If the optional argument is not there, create a new variable with that name.
		var str_to_show = "Remove Favourite";
	}
	
	if(!str_to_return) { //If the optional argument is not there, create a new variable with that name.
		var str_to_return = "Add to Favourites";
	}
	
	$("#favourite_"+unit_id).blur();
	
	api('lettings', '_model', 'add_favourite', [unit_id], function(response){								    
		$("#favourite_"+unit_id).html(str_to_show).attr('href','javascript:remove_favourite_link(' + unit_id + ', "'+ str_to_return +'");').parent().animate({'opacity': 0.5}, 1000);
	});
}

function remove_favourite_link(unit_id, str_to_show, str_to_return){
	
	if(!str_to_show) { //If the optional argument is not there, create a new variable with that name.
		var str_to_show = "Add to Favourites";
	}
	
	if(!str_to_return) { //If the optional argument is not there, create a new variable with that name.
		var str_to_return = "Remove Favourite";
	}
	
	$("#favourite_"+unit_id).blur();
	
	api('lettings', '_model', 'remove_favourite', [unit_id], function(response){
		$("#favourite_"+unit_id).html(str_to_show).attr('href','javascript:add_favourite(' + unit_id + ', "'+ str_to_return +'");').parent().animate({'opacity': 1}, 1000);
	});
}

function remove_favourite(unit_id){
	
	$("#favourite_"+unit_id).blur();
	
	api('lettings', '_model', 'remove_favourite', [unit_id], function(response){
		if($("#favourite_"+unit_id).length > 0) {
			$("#favourite_"+unit_id).slideUp("slow");
			$("#favourites_container #favourite_"+unit_id).slideUp("slow");
		}
	});
}
/*
function refresh_favourites(){
	api('lettings', '_view', 'favourites', null, function(html){
		var favourites = $(html);
		var id = favourites.attr('id');
		var current_favourites = $('#' + id);

		if(current_favourites.length > 0){
			current_favourites.after(favourites).remove();
		}
	});
}
*/
