YAHOO.namespace("equatheque");

YAHOO.equatheque.createMenuTreeView = function () {
	YAHOO.equatheque.menuTreeView = new YAHOO.widget.TreeView("menuTreeView_Div");

	// Expand and collapse happen prior to the actual expand/collapse,
	// and can be used to cancel the operation
	/*YAHOO.equatheque.menuTreeView.subscribe("expand", function(node) {
		alert(node.index + " was expanded");
	});*/

	/*YAHOO.equatheque.menuTreeView.subscribe("collapse", function(node) {
		alert(node.index + " was collapsed",);
	});*/

	// Trees with TextNodes will fire an event for when the label is clicked:
	YAHOO.equatheque.menuTreeView.subscribe("labelClick", function(node) {
		//alert(node.index + " was clicked");
		if(node.href) {
			var localisation = node.label;
			var parentNode = node.parent;
			while(parentNode) {
				if(parentNode.label) localisation =  parentNode.label + " > " + localisation;
				parentNode = parentNode.parent;
			}

			YAHOO.equatheque.loadContent(null,node.href,localisation);
		}
	});

	//The tree is not created in the DOM until this method is called:
	YAHOO.equatheque.menuTreeView.render();
}

YAHOO.equatheque.expandMenu = function(e) {
	YAHOO.util.Event.preventDefault(e);
	YAHOO.equatheque.menuTreeView.expandAll();
}

YAHOO.equatheque.collapseMenu = function(e) {
	YAHOO.util.Event.preventDefault(e);
	YAHOO.equatheque.menuTreeView.collapseAll();
}
