package com.guru.component.sectionStructure
{
	import com.guru.call.FunctionCall;
	import com.guru.call.ICall;
	import com.guru.utils.Delegate;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Eddy Lee
	 */
	public class SectionStructureSectionBase
	{
		protected var mTimeline_mc:MovieClip;
		protected var mCurrentStep:SectionStructureStepBase;
		protected var mStepClass_array:Array = [SectionStructureStepBase, SectionStructureStepBase, SectionStructureStepBase];
		
		public function SectionStructureSectionBase(pTimeline_mc:MovieClip)
		{
			mTimeline_mc = pTimeline_mc;
			
			//this.gotoStep(0);
		}
		
		public function dispose():void
		{
			if (mCurrentStep != null)
			{
				mCurrentStep.dispose();
				mCurrentStep = null;
			}
		}
		
		public function gotoStep(pFrame_num:Number, pDoneCall:ICall = null, pData_obj:Object = null):void
		{
			if(mCurrentStep != null)
				mCurrentStep.fadeOut(new FunctionCall(this, gotoStep2, pFrame_num, pDoneCall, pData_obj));
			else
				this.gotoStep2(pFrame_num, pDoneCall, pData_obj);
		}
		
		protected function gotoStep2(pFrame_num:Number, pDoneCall:ICall = null, pData_obj:Object = null):void
		{
			if (mCurrentStep != null)
			{
				mCurrentStep.dispose();
				mCurrentStep = null;
			}
			
			mTimeline_mc.addFrameScript(pFrame_num, new Delegate(this, gotoStep3, pDoneCall, pData_obj).getFunction());
			mTimeline_mc.gotoAndStop(pFrame_num + 1);
		}
		
		protected function gotoStep3(e:*, pDoneCall:ICall = null, pData_obj:Object = null):void
		{
			mTimeline_mc.addFrameScript(mTimeline_mc.currentFrame - 1, null);
			
			mCurrentStep = new mStepClass_array[mTimeline_mc.currentFrame - 1](mTimeline_mc.step_mc, null, null, pData_obj);
			mCurrentStep.setNextStepCall(new FunctionCall(this, gotoStep, mTimeline_mc.currentFrame%mTimeline_mc.totalFrames));
			mCurrentStep.setPreviousStepCall(new FunctionCall(this, gotoStep, Math.max(0, mTimeline_mc.currentFrame - 2)));
			mCurrentStep.fadeIn(pDoneCall);
		}
	}

}