(function($) {

$.fn.A_Community_Rating = function(opt) {
    var opt = opt || {};
    return $.each(this, function() {
        var el = $(this);
        
        if (!opt.itemId) {
            if (!el.attr("id"))
                return;
            var m = el.attr("id").match(/_rate_(-?[\d]+)_(-?[\d]+)$/);
            if (!m)
                return;
            opt.itemId = parseInt(m[1]);
            opt.extraId = parseInt(m[2]);
        }
        if (!opt.vote) {
            opt.vote = el.data("value") || el.attr("iesucks") || el.val();
            if (!opt.vote)
                return;
        }
        
        el.unbind("click").bind("click", function() {
            $.post(location.href, {"A_Community_XhrVote": 1,
                "A_Community_ItemId": opt.itemId, "A_Community_ExtraId": opt.extraId,
                "A_Community_Vote": opt.vote}, function(res) {
                    if (res && res.count && opt.success) {
                        opt.success.apply(el, [res]);
                    }
                }, "json");
            return false;
        });
    });
};

})(jQuery);