(function(){

/*
	Class: StateManager 
	The base class for a collection of navigation components 
*/
function StateManager()
{
	this.contents = new window['SB']['util']['List'];
	this.containers = new window['SB']['util']['List'];
	this.boxes = new window['SB']['util']['List'];
	this.currentBox = null;
	this.currentContainer = null;
}

StateManager.prototype.toString = function() { return "[SB.util.StateManager]"; }

StateManager.prototype.addContainer = function( inContainer )
{
	this.containers.append( inContainer );
};

StateManager.prototype.setConfig = function( inConf )
{
	this.username = inConf.username;
	this.is_public = (inConf.public)?true:false;;

	this.log_visits = (inConf.log_visits)?true:false;
};

//Group: Basic Methods 
/*
	Function: setActive
	Intiates monitoring of basic contextual information
*/
StateManager.prototype.setActive = function()
{
	SButil.EventManager.addListener("BoxItemActivated", onBoxActivated, this);
	SButil.EventManager.addListener("BoxItemDeactivated", onBoxDeactivated, this);
	SButil.EventManager.addListener("ContainerItemActivated", onContainerActivated, this);
	SButil.EventManager.addListener("ContainerDeleted", onContainerDeleted, this);
};

StateManager.prototype.lookupContainer = function( inId )
{
	for( var i = 0; i < this.containers.size(); i++ )
	{
		if( this.containers.get(i).id == inId )
			return this.containers.get(i);
	}
};

StateManager.prototype.lookupItem = function( inId )
{
	return null;
};

function onContainerDeleted( inEvent, inArgs )
{
	var container = this.lookupContainer( inArgs[0].container_id );

	if( container )
		this.containers.remove( container );
}

function onBoxActivated( inEvent, inArgs )
{
	this.currentBox = inArgs[0];
}

function onBoxDeactivated( inEvent, inArgs )
{
	this.currentBox = null;
}

function onContainerActivated( inEvent, inArgs )
{
	this.currentContainer = inArgs[0];
}

window['SB']['util']['StateManager'] = new StateManager();

})();
