(function($) {
    $.fn.participated = function(options) {
        var defaults = {
            text: "Request sent"
        };

        var opts = $.extend(defaults, options);
        
        $(this).unbind('click', sendRequest);
        $(this).click(sendRequest);
        
        function sendRequest(url) {
            link = $(this);
            href = link.attr("href");

            $.ajax({
                type: "POST",
                url: href,
                dataType: "json",
                beforeSend: function() {
                    $("#participation-request").removeClass("addlonger").addClass("sent");
                },
                success: function(json) {
                    //$.handleJSON();

                    $("#participation-request > span").text(opts.text);
                }
            });
            
            return false;
        }
    };
})(jQuery);

