Permission=function(id, param) {
	var self=this;
	this.actions=new Array();
	if (param.actions) {
		for (var key in param.actions) this.addAction(param.actions[key].values, param.actions[key].id, param.actions[key].type);
	}
	this.id=id;
	this.menu=$('#'+id);
	this.menu.find(".item").click(function() {self.onClickHandler($(this))});
	this.val=this.menu.find("input[name=r["+id+"]]");
	this.menu.find(".item").find("input[value="+Math.round(this.val.attr("value"))+"]").parent().addClass("selected");
	this.checkActions(Math.round(this.val.attr("value")));
}

Permission.prototype.onClickHandler=function(obj) {
	this.val.attr("value", obj.find("input").attr("value"));
	this.menu.find(".item").removeClass("selected");
	obj.addClass("selected");
	this.checkActions(this.val.attr("value"));
}

Permission.prototype.addAction=function(values, id, type) {
	if (!$.isArray(values)) values=[values];
	for (var key in values) {
		if (!this.actions[values[key]]) this.actions[values[key]]=new Array();
		if (!this.actions[values[key]][id]) this.actions[values[key]][id]=new Array();
		if ($.inArray(type, this.actions[values[key]][id])<0) this.actions[values[key]][id].push(type);
	}
}

Permission.prototype.checkActions=function(value) {
	if (this.actions[value]) {
		for (var id in this.actions[value]) {
			for (var key in this.actions[value][id]) {
				switch (this.actions[value][id][key]) {
					case "enable":
						$("#"+id).removeClass("disabled");
						$("#"+id).find("input").attr("disabled", "");
						break;

					case "disable":
						$("#"+id).addClass("disabled");
						$("#"+id).find("input").attr("disabled", "disabled");
						break;

					case "show":
						$("#"+id).parent().find("> div").addClass("hidden");
						$("#"+id).removeClass("hidden");
						break;
				}
			}
		}
	}
}