CMS.Explorer.Tree = CMS.Widget.extend({
	multiple: true,

	_objects: null,

	_children: [],
	_selected: [],
	
	_callbacks: [],
	
	construct: function() {
		arguments.callee.$.call(this);
	
		this._objects = document.createElement('ul');
		addClass(this._objects, 'Objects');
		this.get().appendChild(this._objects);	
		this.expand();	
	},
		
	expand: function() {
		var child;
		var obj;
		
		callCMS(
			1,
			this,
			function(r) {
				for ( var i = 0; i < r.length; i++ )
				{
					child = r[i];
					obj = new CMS.Explorer.Object(this,child.id,child.name,child.icon,child.childrenCount>0);
					this._children[this._children.length] = obj;
					this._objects.appendChild(obj.getElement());
				}
			},
			'getChildren' );
	},
	
	collapse: function() {
	},
	
	toggleSelect: function(obj) {
		if ( this._selected.inArray(obj) ) {
			this.unselect(obj);
		} else {
			this.select(obj);
		}
	},
	
	selectOnly: function(obj) {
		this.unselectAll();
		this.select(obj);
	},
	
	select: function(obj) {
		if (!this.multiple) {
			this.unselectAll();
		}
		
		obj.select();
		this._selected.push(obj);
	},
	
	unselect: function(obj) {
		obj.unselect();
		this._selected.remove(obj);
	},
	
	unselectAll: function() {
		while ( obj = this._selected.shift() ) {
			this.unselect(obj);
		}
	},
	
	getSelected: function() {
		selected = [];
		
		for ( var i = 0; i < this._selected.length; i++ ) {
			selected.push(this._selected[i]);
		}
		
		return selected;
	}
});



