package com.guru.conn
{
	import com.guru.facebook.FacebookIFrameCenter;
	import flash.display.LoaderInfo;
	/**
	 * ...
	 * @author Eddy Lee
	 */
	public class ConnPath
	{
		private static var sLocalMode_bol:Boolean = true;
		private static var sForceLocalMode_bol:Boolean = false;
		private static var sLogXML_bol:Boolean = false;
		
		private static var sAppPrefix_str:String = "http://apps.facebook.com/sewingmachine/";
		private static var sHostingPrefix_str:String = "http://www.brofbapp.com/app/";
		
		private static var sServerPrefix_str:String = "";
		private static var sServerApiFolder_str:String = "api/";
		private static var sServerSwfFolder_str:String = "swf/";
		private static var sServerImageFolder_str:String = "swf/image/";
		
		private static var sLocalPrefix_str:String = "";
		private static var sLocalApiFolder_str:String = "api/";
		private static var sLocalSwfFolder_str:String = "";
		private static var sLocalImageFolder_str:String = "image/";
		
		
		public function ConnPath()
		{
			
		}
		
		public static function init(pLoaderInfo:LoaderInfo):void
		{
			if (!sForceLocalMode_bol)
			{
				sLocalMode_bol = new RegExp("file://").test(pLoaderInfo.url);
			}
			Logger.eddy("Local Mode: " + sLocalMode_bol);
		}
		
		public static function get logXML():Boolean
		{
			return sLogXML_bol;
		}
		
		public static function set logXML(pLogXML_bol:Boolean):void
		{
			sLogXML_bol = pLogXML_bol;
			Logger.eddy("Log XML: " + sLogXML_bol);
		}
		
		public static function set forceLocalMode(pForceLocal_bol:Boolean):void
		{
			sForceLocalMode_bol = pForceLocal_bol;
			Logger.eddy("Force localModel: " + sForceLocalMode_bol);
			if (sForceLocalMode_bol)
			{
				sLocalMode_bol = sForceLocalMode_bol;
			}
		}
		
		public static function isLocalMode():Boolean
		{
			return sLocalMode_bol;
		}
		
		//**************** PREFIX ****************//
		public static function getAppPrefix():String
		{
			var prefix_str:String;
			
			if (sLocalMode_bol)
				prefix_str = sLocalPrefix_str;
			else
				prefix_str = sAppPrefix_str;
			
			return prefix_str;
		}
		
		public static function getHostingPrefix():String
		{
			var prefix_str:String;
			
			if (sLocalMode_bol)
				prefix_str = sLocalPrefix_str;
			else
				prefix_str = sHostingPrefix_str;
			
			return prefix_str;
		}
		
		public static function getSwfPrefix():String
		{
			var prefix_str:String;
			
			if (sLocalMode_bol)
				prefix_str = sLocalPrefix_str + sLocalSwfFolder_str;
			else
				prefix_str = sServerPrefix_str + sServerSwfFolder_str;
			
			return prefix_str;
		}
		
		public static function getServerPrefix():String
		{
			var prefix_str:String;
			
			if (sLocalMode_bol)
				prefix_str = sLocalPrefix_str;
			else
				prefix_str = sServerPrefix_str;
			
			return prefix_str;
		}
		
		public static function getImagePrefix():String
		{
			var prefix_str:String;
			
			if (sLocalMode_bol)
				prefix_str = sLocalPrefix_str + sLocalImageFolder_str;
			else
				prefix_str = sServerPrefix_str + sServerImageFolder_str;
			
			return prefix_str;
		}
		
		public static function getAPIPrefix():String
		{
			var prefix_str:String;
			
			if (sLocalMode_bol)
				prefix_str = sLocalPrefix_str + sLocalApiFolder_str;
			else
				prefix_str = sServerPrefix_str + sServerApiFolder_str;
			
			return prefix_str;
		}
		//**************** END ****************//
		
		//**************** PHP CENTER ****************//
		public static function getProfilePath():String
		{
			return getAPIPrefix() + "getProfile.php" + getSessionParam();
		}
		public static function getFriendsPath():String
		{
			return getAPIPrefix() + "getFriends.php" + getSessionParam();
		}
		
		private static function getSessionParam():String
		{
			var param_str:String = "";
			if (FacebookIFrameCenter.getSessionForBrowserBug().length > 0)
				param_str = "?session=" + FacebookIFrameCenter.getSessionForBrowserBug();
			
			return param_str;
		}
		//**************** END ****************//
		
		//**************** RANKING ****************//
		public static function getGlobalRankPath():String
		{
			return getAPIPrefix() + "rank/getGlobalRank.php";
		}
		
		public static function getFriendRankPath():String
		{
			return getAPIPrefix() + "rank/getFriendRank.php";
		}
		
		public static function getWeekRankPath():String
		{
			return getAPIPrefix() + "rank/getWeekRank.php";
		}
		//**************** END ****************//
		
		//**************** TRACKING ****************//
		public static function getTracking():String
		{
			return getAPIPrefix() + "tracking.php";
		}
		//**************** END ****************//
		
		//**************** PUBLISH ****************//
		public static function getPublishPath():String
		{
			return getAPIPrefix() + "publish.php" + getSessionParam();
		}
		
		public static function getPublishAttachmentPath():String
		{
			return getAPIPrefix() + "publishAttachment.php" + getSessionParam();
		}
		//**************** END ****************//
		
		public static function getSubmitGameResultPath():String
		{
			return getAPIPrefix() + "game/submitGameResult.php";
		}
		
		public static function getGetGameRecordPath():String
		{
			return getAPIPrefix() + "game/getGameRecord.php";
		}
		
		public static function getCollectionPath():String
		{
			return getAPIPrefix() + "collection/getCollection.php";
		}
		
		public static function getInboxPath():String
		{
			return getAPIPrefix() + "inbox/getInbox.php";
		}
		
		public static function getSendCollectionToFriendPath():String
		{
			return getAPIPrefix() + "collection/sendCollectionToFriend.php";
		}
	}

}