﻿jQuery().ready(function(){
	jQuery('#left_3DWorld').load('3D-Subject3D.aspx');
});
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------

var GroupFolderName = new Array(3);
	GroupFolderName[0] = new Array(7);	//3D建物
	GroupFolderName[1] = new Array(0);//'特約
	GroupFolderName[2] = new Array(2);//'POI
	GroupFolderName[3] = new Array(10);//'找XX
	GroupFolderName[4] = new Array(10);//'找XX
//*************************3D建物
//LoadFlyFile('http://140.112.64.27/xpl/tp_xpl/','Tp_xplpoint','精緻建物');//台北3D精緻建物
	GroupFolderName[0][0]="精緻建物";//台北3D精緻建物
	GroupFolderName[0][1]="BuildingTCH";//台中市3D精緻建物
	GroupFolderName[0][2]="BuildingKH";//高雄市3D精緻建物
	GroupFolderName[0][3]="TP_Building";//台北市3D一般建物
	GroupFolderName[0][4]="TCH_building";//台中市3D一般建物
	GroupFolderName[0][5]="KH_building";//高雄市3D一般建物
	GroupFolderName[0][6]="Model";//台南精緻建物
	GroupFolderName[0][7]="RoadBuilder_1";//台北3D精緻建物
	//GroupFolderName[0][6]="PagePlusA";//台北市景點導覽+KeyWord
	//GroupFolderName[0][7]="PagePlusB";//台南市景點導覽
	//GroupFolderName[0][8]="PagePlusC";//高雄市景點導覽
	//GroupFolderName[0][9]="PagePlusD";//海角七號景點導覽
	//GroupFolderName[0][10]="PagePlusE";//媽祖繞境景點導覽
	//GroupFolderName[0][11]="Model";//台南市景點導覽
	//GroupFolderName[0][12]="hc_xpl";//內部導覽
	//GroupFolderName[0][13]="TPshp_A";//內部導覽
	//GroupFolderName[0][14]="TPshp_B";//內部導覽
	//GroupFolderName[0][15]="TPshp_C";//內部導覽
//*************************特約
GroupFolderName[1][0]="yellowpage";//黃頁
//*************************POI
GroupFolderName[2][0]="sinzuPOIV2notip";//紅色POIv2  
GroupFolderName[2][1]="t-bar[1]";//t-bar[1]
GroupFolderName[2][2]="ifLocationLabel";//約會地點： ifLocationLabel
//*************************找 XX
GroupFolderName[3][0]="Friend";//找朋友： Friend
GroupFolderName[3][1]="Fun";//找什麼： Fun
GroupFolderName[3][2]="LOC";//找地標： LOC
GroupFolderName[3][3]="addressBox";//找地址： addressBox
GroupFolderName[3][4]="V2secondResultView";//搜主意： V2secondResultView
GroupFolderName[3][5]="V2NewPomaResultView";//報Ma： V2NewPomaResultView
GroupFolderName[3][6]="V2MyPomaResultView";//我的報MA： V2MyPomaResultView
GroupFolderName[3][8]="sinzuPOIV2notip";//紅色POIv2 
GroupFolderName[3][9]="Spacial_Point";//特約地圖(黃頁、EZtable)
GroupFolderName[3][10]="ifLocation";//  特約地圖(黃頁、EZtable) ??
//******************************主題 - 立體 World
GroupFolderName[4][0]="PagePlusA";//台北市景點導覽+KeyWord
GroupFolderName[4][1]="PagePlusB";//台南市景點導覽
GroupFolderName[4][2]="PagePlusC";//高雄市景點導覽
GroupFolderName[4][3]="PagePlusD";//海角七號景點導覽
GroupFolderName[4][4]="PagePlusE";//媽祖繞境景點導覽
GroupFolderName[4][5]="Model";//台南市景點導覽
GroupFolderName[4][6]="hc_xpl";//內部導覽
GroupFolderName[4][7]="TPshp_A";//內部導覽
GroupFolderName[4][8]="TPshp_B";//內部導覽
GroupFolderName[4][9]="TPshp_C";//內部導覽
GroupFolderName[4][10]="MonGa";//MonGa號景點導覽
//************** selct function 
function SelectgroupcontrolFunctionIndex(Groupname,Action)
{
var _Action;
if(Action.toLowerCase()=='open')
{
	_Action=1;
}else{
	_Action=0;
}
	switch (Groupname){
		case "愛找查" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "找朋友" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('Friend',1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "找什麼" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('Fun',1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "找地標" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('LOC',1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "找地址" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('addressBox',1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "搜主意" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('V2secondResultView',1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "報Ma仔" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('V2NewPomaResultView',1);
			GroupNameSetVisibilityInfTree('V2MyPomaResultView',1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "NEW報Ma仔" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('V2NewPomaResultView',1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "My報Ma仔" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('V2MyPomaResultView',1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "特約地圖" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			break;
		case "主題地圖" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(0,1);
			CPGroupNameFun(4,1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "立體世界" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(0,1);
			CPGroupNameFun(4,1);
			GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
			break;
		case "YP" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('Spacial_Point\\yellowpage',1);
			break;
		case "EZTable" :
			//執行動作
			CPGroupNameFun(3,0);
			CPGroupNameFun(4,0);
			GroupNameSetVisibilityInfTree('Spacial_Point\\EZTable',1);
			break;
		case "MonGa" :
			//執行動作 load 3d Building & POI
			OpenAll3DBuilding("MogGa");
			setTimeout("CPGroupNameFun(3,0)",500);
			setTimeout("CPGroupNameFun(4,0)",500);
			//艋舺
			setTimeout("GroupNameSetVisibilityInfTree('MonGa',1)",750);
			setTimeout("SettimeoutMongaRun();",1000);
			//CPGroupNameFun(3,0);
			//CPGroupNameFun(4,0);
			//myDebugWin=new $TEDebug(true);//Debug windows open
			break;
		default :
			//執行動作
			alert('nothing to Run');
			break;
	} 
}
//ShowHideLayer("Spacial_Point",0);
function SettimeoutMongaRun()
{
	GroupNameSetVisibilityInfTree('MonGa\\建物',0);
	GroupNameSetVisibilityInfTree('MonGa\\道路',0);
	GroupNameSetVisibilityInfTree('MonGa\\cover',0);
}
//***************************************************
function GroupNameSetVisibilityInfTree(OPGN,AC)//  (' AA//AA , BB/BB ' ,1) 傳入 inf tree 裡的 itemname or group name 的開關控制
{
	var _OPGN=OPGN;
	var _Ac=AC;
	var GName = _OPGN.split(",");
	for(var k=0;k<=GName.length-1;k++)
	{
		var GroupName = GName[k];
		var GroupID = IInformationTree.FindItem(GroupName);
		if(GroupID !=0){
			IInformationTree.SetVisibility(GroupID,_Ac);
		}else{
		//load fly
		}
	}
}

function GroupNameSetVisibility(OPGN,AC)//  (' AA//AA , BB/BB ' ,1) 先比對 陣列裡的GroupFolderName 傳入 inf tree 裡的 itemname or group name 的開關控制
{
	var _OPGN=OPGN;
	var _Ac=AC;
	 for(var i=0;i<=GroupFolderName.length-1;i++)
	 {
		 for(var j=0;j<=GroupFolderName[i].length-1;j++)
		 {
				var GName = _OPGN.split(",");
				for(var k=0;k<=GName.length-1;k++)
				{
					if(GroupFolderName[i][j]==GName[k]){
						var GroupName = GName[k];
						var GroupID = IInformationTree.FindItem(GroupName);
						if(GroupID !=0){
							IInformationTree.SetVisibility(GroupID,_Ac);
						}else{
						//load fly
						}
					}
				}
		 }
	 }
}
function CPGroupNameFun(GNID,AC) //   (0 , 1 )   群組 id 開關 控制  
{
	var _Ac=AC;
		 for(var j=0;j<=GroupFolderName[GNID].length-1;j++)
		 {
			var GroupName = GroupFolderName[GNID][j];
			var GroupID = IInformationTree.FindItem(GroupName);
			if(GroupID !=0){
				IInformationTree.SetVisibility(GroupID,_Ac);
			}else{
			//load fly
			}
		 }
}
	//onclick="OpenAll3DBuilding();FindObjPlay('PagePlusA\\TP\\skm');"
function GroupSubjectFunction(GN,Ac)//'3D建物','true'
{
	_GN=GN;
	_Ac=Ac;
	for(var i=0;i<=GroupFolderName.length-1;i++)
	{
		if(GroupFolderName[i]==_GN)
		{
			var GName = GroupFolderNameItem[i].split(",");
			for(var i=0;i<=GName.length-1;i++)
			{
				var GroupName = GName[i];
				var GroupID = IInformationTree.FindItem(GroupName);
				if(GroupID !=0){
					IInformationTree.SetVisibility(GroupID,_Ac);
				}
			}
		}
	}
	
}
//-------------------------------------------------------------------------------------------------------
function LoadFlyFile(Url,FlyName,FolderName){
//load Fly file
//LoadFlyFile('http://140.112.64.27/xpl/tp_xpl/','Tp_xplpoint','精緻建物');
	var _Url=Url;
	var _FlyName=FlyName;
	var _FolderName=FolderName;
	var _Fly=".fly";
	var sheetid =  IInformationTree.FindItem(_FolderName);
	if (sheetid != 0){
		// IInformationTree.DeleteItem(sheetid);//移除
		//alert('groupname重複：'+_FolderName);
	}else{
		// var test=IInformationTree.CreateGroup(FolderName);
		IInformationTree.LoadFlyLayer(_Url + _FlyName + _Fly);
		var addressstate =  IInformationTree.FindItem(_Url + _FlyName);
		IInformationTree.RenameGroup(addressstate,_FolderName);
	}
}
function FindObjPlay(GroupNameID){
// fly to or  play obj
//FindObjPlay('start1')
 	GroupName = GroupNameID;
	GroupID = IInformationTree.FindItem(GroupName);
	if (GroupID != 0){
		//getsetvisibleOpen();//全開顯示建物
		var ObjID = IInformationTree.GetTerraObjectID(GroupID);
		IPlane.FlyToObject(ObjID,11);
	}else{
		alert('not Find Obj');
	} 
}
function getsetvisibleOpen(){
	//全開顯示建物
	//var DelGroupName="精緻建物,BuildingTCH,BuildingKH,TP_Building,TCH_building,KH_building,PagePlusA,PagePlusB,PagePlusC,PagePlusD,PagePlusE,Model,hc_xpl,TPshp_A,TPshp_B,TPshp_C";
	var GName = GroupFolderNameItem[0].split(",");
	for(var i=0;i<=GName.length-1;i++)
	{
		var GroupName = GName[i];
		var GroupID = IInformationTree.FindItem(GroupName);
		if(GroupID !=0){
			IInformationTree.SetVisibility(GroupID,true);
		}
	}
}
function UnderGoundOpen()
{//地底檢視模式
		globe.teCore.IMenu.Invoke(33372);
		alert("地底檢視模啟動");
		ITerrain.Opacity = 1;
}

var UnderGroundFlag=0;
function JustOpen(){
	if(UnderGroundFlag==0){
		UnderGroundFlag=1;
		UnderGoundOpen();
	}
}
var closeAll3dBuildingFlag=true;
function closeAll3dBuilding()
{	
	if(closeAll3dBuildingFlag)
	{
		closeAll3dBuildingFlag=false;
	}
	else
	{
		closeAll3dBuildingFlag=true;
	}
	CPGroupNameFun(0,closeAll3dBuildingFlag);
	CPGroupNameFun(4,closeAll3dBuildingFlag);
/* 	//關閉所有建物
	var DelGroupName="精緻建物,BuildingTCH,BuildingKH,TP_Building,TCH_building,KH_building,PagePlusA,PagePlusB,PagePlusC,PagePlusD,PagePlusE,Model,hc_xpl,TPshp_A,TPshp_B,TPshp_C";
	var GName = DelGroupName.split(",");
	for(var i=0;i<=GName.length-1;i++)
	{
		var GroupName = GName[i];
		var GroupID = IInformationTree.FindItem(GroupName);
		if(GroupID !=0){
			//var openFlag=IInformationTree.GetVisibility(GroupID);
			IInformationTree.SetVisibility(GroupID,closeAll3dBuildingFlag);
		}else{
			//OpenAll3DBuilding();
			//alert('ERROR');
			break;
			}
	} */
	if(UnderGroundFlag==1){
		UnderGroundFlag=0;
		globe.teCore.IMenu.Invoke(33372);
		alert("地底模式關閉");
	}
}
function OpenAll3DBuilding(Groupname)
{
	//LoadFlyFile('http://140.112.64.27/xpl/tp_xpl/','Tp_xplpoint','精緻建物');//台北3D精緻建物
	//LoadFlyFile('http://140.112.64.27/xpl/tch_xpl/','Default','BuildingTCH');//台中市3D精緻建物
	//LoadFlyFile('http://140.112.64.27/xpl/khc_xpl/','Default','BuildingKH');//高雄市3D精緻建物
	//LoadFlyFile('http://140.112.64.27/sfsFlyFile/Building/Shp_Only/','TP_Building','TP_Building');//台北市3D一般建物
	//LoadFlyFile('http://140.112.64.27/sfsFlyFile/Building/Shp_Only/','TCH_building','TCH_building');//台中市3D一般建物
	//LoadFlyFile('http://140.112.64.27/sfsFlyFile/Building/Shp_Only/','KH_building','KH_building');//高雄市3D一般建物
	//LoadFlyFile('http://140.112.64.27/PagePlus/','Default','PagePlusA');		//台北市景點導覽+KeyWord
	//LoadFlyFile('http://140.112.64.27/xpl/tn_xpl/','Default','Model');			//台南市景點導覽
	//LoadFlyFile('http://140.112.64.27/xpl/tn_xpl/','tn_navi','PagePlusB');		//台南市景點導覽
	//LoadFlyFile('http://140.112.64.27/xpl/khc_xpl/','kh_navi','PagePlusC');		//高雄市景點導覽
	//LoadFlyFile('http://140.112.64.27/xpl/cape_no7/','Default','PagePlusD');	//海角七號景點導覽
	//LoadFlyFile('http://140.112.64.27/xpl/matsu/','Default','PagePlusE');		//媽祖繞境景點導覽
	//LoadFlyFile('http://140.112.64.27/xpl/hc_xpl/','Default','hc_xpl');				//內部導覽
	//LoadFlyFile('http://www.mapi.net.tw/fly/','cks1','TPshp_C');					//內部導覽
	//LoadFlyFile('http://140.112.64.27/xpl/gonggungMRT/','gonggung_MRT','TPshp_A');	//內部導覽
	//LoadFlyFile('http://140.112.64.27/xpl/underground/','cksmh_under','TPshp_B');	//內部導覽
	switch (Groupname){
		case "ALL_Building" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/tp_xpl/','Tp_xplpoint','精緻建物');//台北3D精緻建物
			LoadFlyFile('http://140.112.64.27/XPL/RoadBuilder/','default','RoadBuilder_1');//台北3D精緻建物(道路+樹)-2
			LoadFlyFile('http://140.112.64.27/xpl/tch_xpl/','Default','BuildingTCH');//台中市3D精緻建物
			LoadFlyFile('http://140.112.64.27/xpl/khc_xpl/','Default','BuildingKH');//高雄市3D精緻建物
			LoadFlyFile('http://140.112.64.27/xpl/tn_xpl/','default','Model');//台南精緻建物
			//LoadFlyFile('http://140.112.64.27/sfsFlyFile/Building/Shp_Only/','TP_Building','TP_Building');//台北市3D一般建物
			LoadFlyFile('http://140.112.64.27/sfsFlyFile/Building/Shp_Only/','TCH_building','TCH_building');//台中市3D一般建物
			LoadFlyFile('http://140.112.64.27/sfsFlyFile/Building/Shp_Only/','KH_building','KH_building');//高雄市3D一般建物
			break;
		case "ALL_Subject" :
			//執行動作
			//LoadFlyFile('http://140.112.64.27/PagePlus/','Default','PagePlusA');		//台北市景點導覽+KeyWord
			//LoadFlyFile('http://140.112.64.27/xpl/tn_xpl/','Default','Model');			//台南市景點導覽
			//LoadFlyFile('http://140.112.64.27/xpl/tn_xpl/','tn_navi','PagePlusB');		//台南市景點導覽
			//LoadFlyFile('http://140.112.64.27/xpl/khc_xpl/','kh_navi','PagePlusC');		//高雄市景點導覽
			//LoadFlyFile('http://140.112.64.27/xpl/cape_no7/','Default','PagePlusD');	//海角七號景點導覽
			//LoadFlyFile('http://140.112.64.27/xpl/matsu/','Default','PagePlusE');		//媽祖繞境景點導覽
			//LoadFlyFile('http://140.112.64.27/xpl/hc_xpl/','Default','hc_xpl');				//內部導覽
			//LoadFlyFile('http://www.mapi.net.tw/fly/','cks1','TPshp_C');					//內部導覽
			//LoadFlyFile('http://140.112.64.27/xpl/gonggungMRT/','gonggung_MRT','TPshp_A');	//內部導覽
			//LoadFlyFile('http://140.112.64.27/xpl/underground/','cksmh_under','TPshp_B');	//內部導覽
			break;
		case "PagePlusA" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/PagePlus/','Default','PagePlusA');		//台北市景點導覽+KeyWord
			break;
		case "PagePlusB" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/tn_xpl/','tn_navi','PagePlusB');		//台南市景點導覽
			break;
		case "PagePlusC" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/khc_xpl/','kh_navi','PagePlusC');		//高雄市景點導覽
			break;
		case "PagePlusD" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/cape_no7/','Default','PagePlusD');	//海角七號景點導覽
			break;
		case "PagePlusE" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/matsu/','Default','PagePlusE');		//媽祖繞境景點導覽
			break;
		case "TPshp_A" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/gonggungMRT/','gonggung_MRT','TPshp_A');	//內部導覽
			break;
		case "TPshp_B" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/underground/','cksmh_under','TPshp_B');	//內部導覽
			break;
		case "TPshp_C" :
			//執行動作
			LoadFlyFile('http://www.mapi.net.tw/fly/','cks1','TPshp_C');					//內部導覽
			break;
		case "hc_xpl" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/hc_xpl/','Default','hc_xpl');				//內部導覽
			break;
		case "MogGa" :
			//執行動作
			LoadFlyFile('http://140.112.64.27/xpl/MG/','MG_mapi','MonGa');	//MonGa POI
			break;
		default :
			//執行動作
			alert('OpenAll3DBuilding'+Groupname);
			break;
	} 
}
var OpenAllRoadRoadOpenFlag=false;
function OpenAllRoad()
{	//開啟所有道路
	//myDebugWin=new $TEDebug(true);//Debug windows open
	//LoadRoadflyA('http://140.112.64.27/sfsFlyFile/Road/');
	//LoadRoadflyB('http://140.112.64.27/sfsFlyFile/Road/');
	//LoadRoadflyC('http://140.112.64.27/sfsFlyFile/Road/');
	LoadFlyFile('http://140.112.64.27/sfsflyfile/road/','road','AllRoad');//AllRoad(road_A,road_B,road_C)
	OpenAllRoadRoadOpenFlag=!OpenAllRoadRoadOpenFlag;
	GroupNameSetVisibilityInfTree('AllRoad',OpenAllRoadRoadOpenFlag);
}


//初始要load的fly files
var RunOnLoadFinished_FlagTimer=0;
function OnLoadFinished_3D(){
if(RunOnLoadFinished_FlagTimer==0){
	LoadFlyFile('http://140.112.64.27/sfsflyfile/POI/','Spacial_Point','Spacial_Point');
	OpenAll3DBuilding('ALL_Building');
	CPGroupNameFun(3,0);
	GroupNameSetVisibilityInfTree('sinzuPOIV2notip',1);
	GroupNameSetVisibilityInfTree('ifLocation',1);
	FindObjPlay('start');
	RunOnLoadFinished_FlagTimer=RunOnLoadFinished_FlagTimer+1;
}
}
