package com.guru.facebookApplicationBase.mainBase
{
	import com.guru.call.FunctionCall;
	import com.guru.conn.ConnAbstract;
	import com.guru.conn.ConnPath;
	import com.guru.display.LabelButton;
	import com.guru.facebook.FacebookDataBridge;
	import com.guru.facebook.feed.TestJSONFeed;
	import com.guru.panel.Panel;
	import com.guru.panel.StatusBar;
	import com.guru.section.Section;
	import flash.display.MovieClip;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author Eddy Lee
	 */
	public class MainSectionBase
	{
		protected var mTimeline_mc:MovieClip;
		protected var mInstructionBtn:LabelButton;
		protected var mRankBtn:LabelButton;
		protected var mGameBtn:LabelButton;
		protected var mInviteBtn:LabelButton;
		
		//private var mConn:ConnAbstract;
		
		public function MainSectionBase(pTimeline_mc:MovieClip)
		{
			mTimeline_mc = pTimeline_mc;
			
			mInstructionBtn = new LabelButton(mTimeline_mc.instructionBtn_mc);
			mRankBtn = new LabelButton(mTimeline_mc.rankBtn_mc);
			mGameBtn = new LabelButton(mTimeline_mc.gameBtn_mc);
			mInviteBtn = new LabelButton(mTimeline_mc.inviteBtn_mc);
			
			mInstructionBtn.setPressCall(new FunctionCall(this, onInstructionBtnPress));
			mRankBtn.setPressCall(new FunctionCall(this, onRankBtnPress));
			mGameBtn.setPressCall(new FunctionCall(this, onGameBtnPress));
			mInviteBtn.setPressCall(new FunctionCall(this, onInviteBtnPress));
			//trace("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
			//mConn = new ConnAbstract(ConnPath.getPublishPath(), new FunctionCall(this, onSuccess), new FunctionCall(this, onFail));
			//var feed:TestJSONFeed = new TestJSONFeed();
			//mConn.send(feed.getSendObj());
		}
		
		private function onSuccess():void
		{
			Logger.eddy("send feed success :)");
			//Logger.eddy(mConn.getXML());
		}
		
		private function onFail():void
		{
			Logger.eddy("send feed fail :(");
			//Logger.eddy(mConn.getXML());
		}
		
		public function dispose():void
		{
			mInstructionBtn.dispose();
			mRankBtn.dispose();
			mGameBtn.dispose();
		}
		
		protected function onInviteBtnPress():void
		{
			if (FacebookDataBridge.MODE == FacebookDataBridge.FBML)
			{
				navigateToURL(new URLRequest(ConnPath.getServerPrefix() + "invite.php"), "_blank");
			}
			else if(FacebookDataBridge.MODE == FacebookDataBridge.IFRAME)
			{
				navigateToURL(new URLRequest(ConnPath.getServerPrefix() + "invite.php"), "_top");
			}
		}
		
		protected function onInstructionBtnPress():void
		{
			Panel.showPanel("instruction", new FunctionCall(mInstructionBtn, mInstructionBtn.reset));
		}
		
		protected function onRankBtnPress():void
		{
			Panel.showPanel("rank", new FunctionCall(mRankBtn, mRankBtn.reset));
		}
		
		protected function onGameBtnPress():void
		{
			Section.changeSection("game");
		}
		
	}

}