
TreeGroup.implement({
	insertMenu: function(className) {
		if( this.handles ) {
			var arr = new Array();
			var ul = new Element('ul').setProperty('id', className); //this.options.id+'_tabs');
	
			for(i=0; i<this.handles.length; i++) {
				if( (this.handles[i].getParent().getProperty('id')==this.options.id) && (this.handles[i].getTag()!='ul') ) {
					var li = new Element('li').setProperty('id', this.handles[i].id+'_menu');
					li.setHTML(this.handles[i].innerHTML);
					li.addEvent('click', this.hideshow.pass([this.handles[i].id], this));
					li.injectInside(ul);
					arr.push(i);
				}
			}
			/*var showall = new Element('li').setProperty('id', this.options.id+'_showall').setHTML('Show All'); //.addClass('lastMainType').setStyle('font-weight', 'bold');
			showall.addEvent('click', this.hideshow.pass([''], this));
			showall.injectInside(ul);*/
		
			var expandall = new Element('li').setProperty('id', this.options.id+'_expandall').setHTML('Expand All');
			expandall.addEvent('click', this.hideshow.pass(['expandall'], this)); //this.expandAll.pass(null, this));
			expandall.injectInside(ul);
			
			var closeall = new Element('li').setProperty('id', this.options.id+'_closeall').setHTML('Close All').addClass('lastMainType').setStyle('font-weight', 'bold');
			closeall.addEvent('click', this.hideshow.pass(['closeall'], this)); //this.closeAll.pass(null, this));
			closeall.injectInside(ul);
		
			ul.injectBefore( this.handles[0] ); //tree.getFirst() ); //$E('#'+this.options.id+' '+this.options.panelContainerClass) ); //this.panels[0] );
		}
	},
	hideshow: function(id) {
		var children = $(this.options.id).getChildren();
		children.each(function(el){
			if( (el.getParent().getProperty('id')==this.options.id) && (el.hasClass('handle') || el.hasClass('accToggler')) ) {
				if( el.getProperty('id')==id ) {
					$(el.id+'_menu').setStyle('font-weight', 'bold');
					el.setStyle('display', '');
					el.addClass('current');
					el.getNext().setStyle('display', '');
				} else {
					$(el.id+'_menu').setStyle('font-weight', '');
					el.setStyle('display', 'none');
					el.getNext().setStyle('display', 'none');
				}
			}
		}, this);
		
		if( id == 'expandall' ) {
			this.expandAll();
			$(this.options.id+'_expandall').setStyle('font-weight', 'bold');
			$(this.options.id+'_closeall').setStyle('font-weight', '');
		} else if( id == 'closeall' ) {
			this.closeAll();
			$(this.options.id+'_closeall').setStyle('font-weight', 'bold');
			$(this.options.id+'_expandall').setStyle('font-weight', '');
		} else {
			$(this.options.id+'_expandall').setStyle('font-weight', '');
			$(this.options.id+'_closeall').setStyle('font-weight', '');
		}
	}
});

Window.onDomReady( function() {
	var cname = $('tabGroup').getProperty('class');
	var tabGroup = new TabGroup({
		id: 'tabGroup',
		show: 1,
		cookieName: cname
	});
	var docTree = new TreeGroup({
		id: 'docTree',
		expandAll: false,
		expandFirst: true
	});
	docTree.insertMenu('docMainTypes');
	var diagTree = new TreeGroup({
		id: 'schematics',
		expandAll: true,
		expandFirst: true
	});
	diagTree.insertMenu('diagMainTypes');
});
