function ContextMenu(name) {
	this.items = new Array();	// array of CMItems
	this.width = null;
	this.name = name;
	this.submenus = new Array();
	
	this.addItem = function (item) {
		this.items.push(new CloneObject(item));	// clone the object so that other menus don't change properties of it (since it's just a reference normally)
		if (item instanceof CMSubmenu) {
			this.submenus.push(this.items[this.items.length - 1]);
			this.submenus[this.submenus.length - 1].subId = this.submenus.length - 1;
			this.submenus[this.submenus.length - 1].linkId = "cm_" + this.name + "_" + this.submenus.length;
		}
	}

	// myArray should be an array of CMItems
	this.addItems = function (myArray) {
		// bugged. when including prototype, this loop causes some serious bug
		//for (x in myArray) {
		//	//this.addItem(myArray[x]);
		//}
		
		for(var i=0; i<myArray.length; i++) {
			if(myArray[i] != undefined) {
				this.addItem(myArray[i]);
			}
		}
	}

	this.setWidth = function (newWidth) {
		this.width = parseInt(newWidth);
	}

	this.clear = function () {
		this.items = new Array();
	}

	this.draw = function (subText) {
		var out = "";
		for (var i = 0; i < this.items.length; i++) {		
			out += this.items[i].draw(subText);
		}
		return out;
	}
}
