category = {
	categories: {},
	callback: null,
	init: function(args){
		if(!args.page){
			alert("Error: No page specified to categories.");
			return false;
		}
		category.callback = args.callback;
		$.ajax({
			type: "GET",
			url: "/categories/ribbit.cgi?page=getcategories.atj&format=xml",
			success: category.categorydone,
			error: function(req){
				alert("Error obtaining categories!");
				return false;
			}
		});
	},
	categorydone: function(req){
		$(req).find("toplevel").each(function(){
			var currcat = $(this).attr("key");
			category.categories[currcat] = new Object();
			category.categories[currcat].name = $(this).attr("name");
			category.categories[currcat].subcategories = new Object();
			if($(this).children("category").length)
				category.categories[currcat].subcategories = category.categoryexpand(this);
		});
		if(typeof category.callback == "function")
			category.callback(category.categories);
	},
	categoryexpand: function(catxml){
		var childrenObj = false;
		$(catxml).children("category").each(function(){
			if(!childrenObj)
				childrenObj = new Object();
			var currcat = $(this).attr("key");
			childrenObj[currcat] = new Object();
			childrenObj[currcat].name = $(this).attr("name");
			childrenObj[currcat].subcategories = category.categoryexpand(this);
		});
		return childrenObj;
	}
}

