
					function CategoryController(cats) {

						this.cats = cats;
						if (this.cats == null) {
							this.cats = new Array();
							this.cats[0] = 0;
						}
		

						var addCategory = $("add-category");
						addCategory.controller = this;
						addCategory.onclick = function() {
							this.controller.cats.push(0);
							this.controller.redrawCategories();
						}

						this.setSelectBoxValue = function(sel, id) {
							for (var i=0; i<sel.options.length; i++) {
								if (sel.options[i].value == id) {
									sel.selectedIndex = i;
									return;
								}
							}
						}

						this.redrawCategories = function(cats) {
							var wrapper = $("category-wrapper");
							var hiddenCategory = $("category-0");

							/** erase old categories from canvas **/
							var divs = wrapper.getElements("div");
							for (var i=1; i<divs.length; i++) {
								var div = $(divs[i]);
								div.remove();
							}
					
							for (var i=1; i<=this.cats.length; i++) {
								var copy = hiddenCategory.clone();
								copy.style.display = "block";
								copy.setProperty('id','category-' + i);
								wrapper.adopt(copy);
								var catid = copy.getElement("select");
								catid.setProperty('id','catid-' + i);
								catid.setProperty('name','catid-' + i);
								this.setSelectBoxValue(catid, this.cats[i-1]);

								/** when the remove link is clicked, delete the 
									category from the array and redraw the boxes **/
								var remove = copy.getElement("a");
								remove.controller = this;
								remove.index = i-1;
								remove.onclick = function() {
									this.controller.cats.splice(this.index,1);
									this.controller.redrawCategories();
								}

								/** when the change link is clicked, change the
									value in the array and re-draw the boxes **/
								catid.controller = this;
								catid.index = i-1;
								catid.onchange = function() {
									this.controller.cats[this.index] = this.options[this.selectedIndex].value;
								}
							}
						}

						this.redrawCategories(this.cats);
					}


