// all packages need to dojo.provide() _something_, and only one thing
dojo.provide("com.ba.gui.SimpleStepManager");

/*dojo.declare(
	"dijit.cbs._SimpleStepManager",
	null,
	{
		
	}
);*/

dojo.declare(
	"com.ba.gui.SimpleStepManager", 
	null,
	{
		_simpleSteps: 5,
		_expandedSimpleStep: 0,
		
		constructor: function(){
			this._simpleSteps = [];
			this._expandedSimpleStep = null;
			dojo.connect(document, "click", this, this.closeCurrentStep)
		},
		
		closeCurrentStep: function(){
			if(this._expandedSimpleStep)
			    this._expandedSimpleStep.CollapseNow();
				
			this._expandedSimpleStep = null;
		},
		
		/**
		* Add a simple step to the array of simplesteps...
		* Note that the id of the simplestep is used to identify the simpleste (and destroy connections with a previous version of the simplestep if needed)
		**/
		AddSimpleStep: function(stepInstance)
		{
			//~ console.debug("Adding a simplestep: " + stepInstance.GetSimpleStepName());
			if(this._simpleSteps[stepInstance.GetSimpleStepName()])
			{
				//~ console.debug("Duplicate simplestep found");
				this._simpleSteps[stepInstance.GetSimpleStepName()].DestroyConnections();
				this._simpleSteps[stepInstance.GetSimpleStepName()] = null;
			}
			
			this._simpleSteps[stepInstance.GetSimpleStepName()] = stepInstance;
		},
		
		DestroySimpleSteps: function()
		{
			this._expandedSimpleStep = null;
			
			for(var prop in this._simpleSteps)
			{
				this._simpleSteps[prop].DestroyConnections();
				delete(this._simpleSteps[prop]);
			}
		},
		
		SetCurrentExpandedStep: function(simpleStepInstance){
		
			if(this._expandedSimpleStep !== null)
			{
				this._expandedSimpleStep.CollapseNow();
				this._expandedSimpleStep = null;
			}
			
			this._expandedSimpleStep = simpleStepInstance;   
		}
	}
);

dojo.mixin(
	com.ba.gui.SimpleStepManager,
	null,
	{
		statics: {_managerInstance: null},
		
		GetInstance: function() {
			if(this.statics._managerInstance === null){
				this.statics._managerInstance = new com.ba.gui.SimpleStepManager();
			}
			
			return this.statics._managerInstance;
			//~ return 12;
		}
	
	}
);

