var MenuManager = Class.create();
Object.extend(Object.extend(MenuManager.prototype, Window.prototype), {
	toggleCss : "toggleMenu",
	link : true,
	initialize : function(option) {
		this._initialize(option);
		this.request();
		this.cannotClose();
		this.content.className = "menus";
		this.tooltip = "메뉴 관리자 입니다.";
	},
	refresh : function(evt, parentId, subLength) {
		var menus = $R(1, subLength);
		menus.each(function(menu) {
			$(parentId + "" + menu).toggleClassName(this.toggleCss);
		}.bind(this));
		Event.stop(window.event || evt);
	},
	request : function() {
		this.content.innerHTML = "";
		this.buildElement(this.content, {elementName: "div", id: "currentPath"}); 
		var xsltProcessor = new JXSLTProcessor({aXSL: "/xsl/menu.xsl", aXML: "minimal.xml"});
		var menuElems = $(xsltProcessor.result);
		xsltProcessor.result.setAttribute("id", "menuContainer");
		menuElems.immediateDescendants().each(function(elem) {
			elem.className = "toggleMenu";
		});
		this.addContentElement(xsltProcessor.result);
	},
	show : function(option) {
		var optionElement = $(option.id);
		var filter = ["title", "icon", "initCallback", "link", "tooltip", "fixedPos", "fixed", "lazyLoad",
		"mustHasParent", "targetJSClass", "targetView"];
		filter.each(function(opt) {
			var value = optionElement.getAttribute(opt);
			if(value)
				option[opt] = value;
		});
		if(option.parentId) {
			option.title = optionElement.getAttribute("title") + " in " + $(option.parentId).getAttribute("title");
		}
		var found = window.taskManager.find(option.title);
		if(found) {
			found.toggle();
			return;
		}
		option.lazyLoad = (option.lazyLoad || "true" == optionElement.getAttribute("lazyLoad")) ? true : false;
		option.mustHasParent = (option.mustHasParent || "true" == optionElement.getAttribute("mustHasParent")) ? true : false;
		option.targetJSClass = (option.targetJSClass)? option.targetJSClass : "Window";
		var aWindow = eval("new " + option.targetJSClass + "(option)");
		aWindow.setVisible(true);
		return aWindow;
	}
});