//***********************************************************************************************
// implements a class representing a menue consisting of an array of CItem objects
//
//***********************************************************************************************

function CMenue(nMaxItems, nStat)
{
	this.m_nMaxItems = nMaxItems;
	this.m_nCurrent = -1;
	this.m_nMyIndex = 0;
	this.m_nStat = nStat;
	this.m_pParent = 0;
	
					// ------ methods ------
					
	this.Alloc = CMenue_Alloc;
	this.AddItem = CMenue_AddItem;
	this.Create = CMenue_Create;
	this.Print = CMenue_Print;
	this.RegisterCreateFunc = CMenue_RegisterCreateFunc;
	this.ToggleStat = CMenue_ToggleStat;
		
					// ------ additional initialization 
					
	this.Alloc(nMaxItems);	
};



function CMenue_Alloc(nSize)
{
	var tmp, nNewSize, i;

	if( this.m_nCurrent == -1 )
	{
		this.m_pItems = new Array(nSize);
		this.m_nCurrent = 0;
		this.m_nMaxItems = nSize;
		
		return(nSize);
	};
		
	nNewSize = this.m_nCurrent+1+nSize;
	tmp = new Array(nNewSize);
	
		// copy existing elements
		
	for( i = 0; i < this.m_nCurrent; i++ )
		tmp[i] = this.m_pItems[i];
		
	this.m_pItems = tmp;
		
	this.m_nMaxItems = nNewSize;
	
	return(nNewSize);
};


function CMenue_AddItem(Item)
{
	if( this.m_nCurrent == this.m_nMaxItems )
		this.Alloc(3);
		
	Item.m_nMyIndex = this.m_nCurrent;
	//Item.m_nParentIndex = this.m_nMyIndex;
	
	this.m_pItems[this.m_nCurrent] = Item;
	this.m_nCurrent++;
};


function CMenue_Create()
{
	var i, rc = "";
			
	rc += this.m_pItems[0].Create();
	
	if( this.m_nStat == 1 )
	{
		for(i = 1; i < this.m_nCurrent; i++ )
			rc += this.m_pItems[i].Create();		
	};
	
	rc += "<br>\n";
	
	return(rc);
};


function CMenue_Print()
{
	alert(this.Create());
	alert("m_nMaxItems: "+this.m_nMaxItems+"\n"+"m_nCurrent: "+
				this.m_nCurrent+"\n"+"m_nMyIndex: "+this.m_nMyIndex+"\n"+"m_nStat: "+this.m_nStat+"\n");
};


function CMenue_RegisterCreateFunc(pFunc)
{
	this.Create = pFunc;
};


function CMenue_ToggleStat()
{
	if( this.m_nStat == 1 )
		this.m_nStat = 0;
	else
		this.m_nStat = 1;
		
	return(this.m_nStat);
};















