package com.guru.component.footer
{
	import com.guru.component.CommonFunction;
	import com.guru.component.panel.Panel;
	import com.guru.call.FunctionCall;
	import com.guru.call.ICall;
	import com.guru.display.button.LabelButton;
	import com.guru.display.button.LabelPressButton;
	import com.guru.display.LabelMovieClip;
	import com.guru.event.EventCall;
	import com.guru.section.Section;
	import com.guru.section.SectionEvent;
	import flash.display.MovieClip;
	/**
	 * ...
	 * @author Eddy Lee
	 */
	public class Footer
	{
		private static var sInstance:Footer
		
		public static function init(pTimeline_mc:MovieClip):void
		{
			sInstance = new Footer(pTimeline_mc);
		}
		
		public static function getInstance():Footer
		{
			if (!sInstance)
				trace("WARNING: Footer not yet inited!");
			
			return sInstance;
		}
		
		private var mTimeline_mc:MovieClip;
		private var mMainBtn:LabelButton;
		private var mInviteBtn:LabelPressButton;
		private var mTncBtn:LabelButton;
		private var mControl:LabelMovieClip;
		
		public function Footer(pTimeline_mc:MovieClip)
		{
			mTimeline_mc = pTimeline_mc;
			
			mControl = new LabelMovieClip(mTimeline_mc, "hide");
			
			mMainBtn = new LabelButton(mTimeline_mc.mainBtn_mc);
			mInviteBtn = new LabelPressButton(mTimeline_mc.inviteBtn_mc);
			mTncBtn = new LabelButton(mTimeline_mc.tncBtn_mc);
			
			mMainBtn.setPressCall(new FunctionCall(this, onMainBtnPress));
			mInviteBtn.setPressingStopCall(new FunctionCall(this, onInviteBtnPress));
			mTncBtn.setPressCall(new FunctionCall(this, onTncBtnPress));
			
			Section.addEventListener(SectionEvent.DEACTIVE_START, new EventCall(this, onDeactiveStart));
			Section.addEventListener(SectionEvent.ACTIVE_START, new EventCall(this, onActiveStart));
		}
		
		public function show(pDoneCall:ICall = null):void
		{
			mControl.playTo("show", pDoneCall);
		}
		
		public function hide(pDoneCall:ICall = null):void
		{
			mControl.playTo("hide", pDoneCall);
		}
		
		private function enable(pEnable_bol:Boolean):void
		{
			mMainBtn.enabled = pEnable_bol;
			mInviteBtn.enabled = pEnable_bol;
			mTncBtn.enabled = pEnable_bol;
			
			if (pEnable_bol)
			{
				mMainBtn.reset();
				mInviteBtn.reset();
				mTncBtn.reset();
			}
				
		}
		
		private function onDeactiveStart(e:SectionEvent):void
		{
			this.enable(false);
		}
		
		private function onActiveStart(e:SectionEvent):void
		{
			this.enable(true);
			mMainBtn.enabled = Section.getCurrentSectionName() != "main";
		}
		
		private function onMainBtnPress():void
		{
			Section.changeSection("main");
		}
		
		private function onInviteBtnPress():void
		{
			CommonFunction.inviteFriends();
		}
		
		private function onTncBtnPress():void
		{
			Panel.showPanel("tnc", null, new FunctionCall(mTncBtn, mTncBtn.reset));
		}
		
		private function onBrandSiteBtnPress():void
		{
			CommonFunction.gotoURL("http://www.brother.com.hk/");
		}
		
		
		
	}

}