/**
 * $Id: rpc.js 557 2008-11-05 15:54:11Z spocke $
 *
 * @author Moxiecode
 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
 */

(function($){
	$.jsonRPC = function(m, ar, cb) {
		$.post($.jsonRPC.url, {
			json_data : $.toJSON({
				"jsonrpc" : "2.0",
				"method" : m,
				"params" : ar,
				"id" : "c" + ($.jsonRPC.count++)
			})
			}, function(res) {
				var err = res.error;

				if (err) {
					if ($.jsonRPC.errorHandler(err) === false)
						return;
				}

				cb(res);
			}, "json"
		);
	};

	$.jsonRPC.count = 0;
})(jQuery);