
function CLeaf()
{
	CLeaf_Constructor(this);
}

function CLeaf_Constructor(_this)
{
	CCommonTree_Constructor(_this);

	_this.m_objParent = null;

	_this.SetParent = CLeaf_SetParent;
	_this.GetParent = CLeaf_GetParent;
	_this.GetTree = CLeaf_GetTree;
	_this.Remove = CLeaf_Remove;
	_this.ResetIds = CLeaf_ResetIds;
	_this.ResetLevels = CLeaf_ResetLevels;
}

function CLeaf_SetParent(obj, bAdded)
{
	this.m_objParent = obj;
	if(!bAdded) obj.SetLeaf(this, true);
	this.ResetIds();
	this.ResetLevels();
}

function CLeaf_GetParent()
{
	return this.m_objParent;
}

function CLeaf_Remove()
{
	for(c in this.m_arLeafs) this.m_arLeafs[c].Remove();
	var ar = new Array();
	var n = 0;
	for(c in this.m_objParent.m_arLeafs)
		if(this.m_objParent.m_arLeafs[c] != this)
			ar[n++] = this.m_objParent.m_arLeafs[c];
	this.m_objParent.m_arLeafs = ar;
}

function CLeaf_GetTree()
{
	pTree = this;
	while(pTree.m_objParent) pTree = pTree.m_objParent;
	return pTree;
}

function CLeaf_ResetIds()
{
	this.m_nId = this.GetTree().m_nMaxId++;
	for(c in this.m_arLeafs)
		this.m_arLeafs[c].ResetIds();
}

function CLeaf_ResetLevels()
{
	this.m_nLevel = this.m_objParent.m_nLevel+1;
	for(c in this.m_arLeafs)
		this.m_arLeafs[c].ResetLevels();
}
