var gamehall_GameUI = gamehall_GameUI ||{};

gamehall_GameUI.Mem = {};
gamehall_GameUI.Mem.categoryObj = null;
gamehall_GameUI.Mem.gameList = [];
gamehall_GameUI.utlani_doend = function(id,sx,count,allend){
	
}

gamehall_GameUI.onloadurl = function(recid,rectype,url,error,count,len){
	
}

gamehall_GameUI.utlgamebegindraw = function(gameid, spid, times, timelong){
	
}

gamehall_GameUI.utlmousedown = function(gameid, spid, downx, downy, no1, no2, no3, no4, no5, no6){
	for(var i=0;i<gamehall_Const.clickBtn.length;i++){
		
		if(spid == gamehall_Const.clickBtn[i]){
			set_self(gamehall_Const.clickBtn[i],35,200,0,0);
			set_self(gamehall_Const.clickBtn[i],33,105,0,0);
		}
	}
	switch(spid){
		case gamehall_Const.GameList.f_spid:	
			gamehall_Data.downX = downx;	
			gamehall_Data.isSliderGameList = false;
			break;
		case gamehall_Const.categoryTwo.f_spid:
			gamehall_Data.downX = downx;
			gamehall_Data.categoryTwo.isSlide = false;
			break;
		case gamehall_Const.Location.f_spid:
			gamehall_Data.selectAgentSlide = false;
			break;
	}
}

gamehall_GameUI.utlmousedown_nomove = function(gameid, spid, downx, downy, timelong, no1, no2, no3, no4, no5){
	
}

gamehall_GameUI.utlmouseup = function(gameid,  spid_down,  downx,  downy,  spid_up,  upx,  upy,  timelong,  no1,  no2){
	for(var i=0;i<gamehall_Const.clickBtn.length;i++){
		if(spid_down == gamehall_Const.clickBtn[i]){
			set_self(gamehall_Const.clickBtn[i],35,255,0,0);
			set_self(gamehall_Const.clickBtn[i],33,100,0,0);
		}
	}
	//if(spid_down == gamehall_Const.GameList.f_spid){
		//var pos = get_self(spid_down,18,0,0,0);
		//if(pos > gamehall_Const.GameList.place_x1){//
			//var t = pos - gamehall_Const.GameList.place_x1;
			//play_ani(1,spid_down,18,pos,gamehall_Const.GameList.place_x1,0,t,0,0,0,1,0,0,0);

		//}else{
			//if(gamehall_Const.GameList.pageCount>=gamehall_Data.GameList.length){
				//if(pos < gamehall_Const.GameList.place_x1){
					//var t = gamehall_Const.GameList.place_x1 - pos;
					//play_ani(1,spid_down,18,pos,gamehall_Const.GameList.place_x1,0,t,0,0,0,1,0,0,0);

				//}
			//}else{
				//var dis = get_self(spid_down,20,0,0,0);;
				//if(pos + dis < gamehall_Const.GameList.place_x2){
					//var t = gamehall_Const.GameList.place_x2 - dis - pos;
					//play_ani(1,spid_down,18,pos,gamehall_Const.GameList.place_x2 - dis,0,t,0,0,0,1,0,0,0);

				//}
			//}
		//}
	//}
	if(spid_down == gamehall_Const.GameList.f_spid){
		gamehall_Data.deltaX = upx - gamehall_Data.downX;
		var pos = get_self(spid_down,18,0,0,0);
		var x = gamehall_GameUI.getSlideLocation(pos);
		var t = ifast_abs(x-pos)/2;
		//t=100;
		//console.log("x="+x);
		play_ani(1,spid_down,18,pos,x,0,t,0,0,0,1,0,0,0);

	}
	if(spid_down == gamehall_Const.categoryTwo.f_spid){
		gamehall_Data.deltaX =  upx - gamehall_Data.downX;
		var pos = get_self(spid_down,18,0,0,0);
		var x = gamehall_GameUI.getSlideLocation2(pos);
		var t = ifast_abs(x-pos)/2;
		//console.log("x="+x);
		//t=100;
		play_ani(1,spid_down,18,pos,x,0,t,0,0,0,1,0,0,0);

	}
	if(spid_down==gamehall_Const.Location.f_spid){
		var pos=get_self(spid_down,19,0,0,0);
		var h=get_self(spid_down,21,0,0,0);
		if(pos>gamehall_Const.Location.clip_y){
			var t = pos - gamehall_Const.Location.clip_y;
			play_ani(1,spid_down,19,pos,gamehall_Const.Location.clip_y,0,t,0,0,0,1,0,0,0);

		}else{

			if(gamehall_Const.Location.clip_h < h){
				var t = gamehall_Const.Location.clip_y+gamehall_Const.Location.clip_h-pos-h;
				play_ani(1,spid_down,19,pos,gamehall_Const.Location.clip_y+gamehall_Const.Location.clip_h-h,0,t,0,0,0,1,0,0,0);

			}else{
				var t = gamehall_Const.Location.clip_y - pos;
				play_ani(1,spid_down,19,pos,gamehall_Const.Location.clip_y,0,t,0,0,0,1,0,0,0);

			}
		}
	}
	if(spid_up == spid_down){
		switch(spid_up){
		/*
			case gamehall_Const.GameList.f_spid://点击游戏列表
				var up_id = ifast_check_add(spid_up,upx,upy);
				
				if(!gamehall_Data.isSliderGameList){
					//console.log(up_id);
					if(up_id>=gamehall_Const.GameList.bg_tag&&up_id<gamehall_Const.GameList.pack_tag){
						
						gamehall_Data.gameIdx = up_id - 1;
						if(gamehall_Data.GameList[gamehall_Data.gameIdx].isDownload == 0){
							if(gamehall_Data.GameList[gamehall_Data.gameIdx].gameid){
								gamehall_GameUI.openCheckDownload(gamehall_Data.gameIdx);
							}else{
								//GameUI.OpenTips("游戏正在拼命内测，敬请期待~~",ConstVal.Tips.time);
							}
						}else{
							if(!gamehall_Data.GameList[gamehall_Data.gameIdx].othergameurlurl){
								var data={};
								var webtype = 3;
								if(gamehall_Data.GameList[up_id - 1].webtype){
									webtype = gamehall_Data.GameList[up_id - 1].webtype;
								}
								data.webtype = webtype;
								data.gamedir = gamehall_Data.GameList[up_id - 1].gamedir;
								data.gameid = gamehall_Data.GameList[up_id - 1].gameid;
								gamehall_Logic.saveGameinfo(JSON.stringify(data));
								
								var data1={};
								data1.from=0;
								data1.opt = "loginPlayerid";
								data1.data = Utl.ReadData(gamehall_Logic.launchGameId);
								Func.SwitchOverGameData(webtype,gamehall_Data.GameList[up_id - 1].gamedir,gamehall_Data.GameList[up_id - 1].gameid,data1);
							}else{
								gamehall_Data.gameInfo = gamehall_Data.GameList[gamehall_Data.gameIdx];
								if(!gamehall_Data.isLogin){
									var sdata={};
									sdata.agentid = GameData.AgentId;
									sdata.openid = C_Player.openid;
									sdata.nickname = C_Player.nickname;
									sdata.avatar = C_Player.avatar;
									sdata.sex = C_Player.sex;
									sdata.province = C_Player.province;
									sdata.city = C_Player.city;
									sdata.unionid = C_Player.unionid;
									sdata.gameid=gamehall_Data.GameList[0].gameid;
									sdata.version = 99999;
									sdata.channelid = GameData.ChannelId;
									sdata.marketid = GameData.marketID;
									var msg={};
									msg.data=sdata;
									msg.app=AppList.app;
									msg.route=RouteList.agent;
									msg.rpc=RpcList.player_login;
									var url="http://"+gamehall_Data.GameList[0].game_server_http+"/index.html";
									Func.AjaxHttp2(url,msg,gamehall_Logic.httpLogin,function(){
										GameUI.OpenTips("网络出现了点小状况，请稍后再试~~",ConstVal.Tips.time);
									});
								}else{
									gamehall_Logic.jumpOtherGame(gamehall_Data.gameInfo);
								}
							}
						}
					}
				}
				break;
			*/
			case gamehall_Const.GameList.f_spid://点击游戏列表
				var up_id = ifast_check_add(spid_up,upx,upy);

				if(!gamehall_Data.isSliderGameList){
					//console.log(up_id);
					if(up_id>=gamehall_Const.GameList.bg_tag&&up_id<gamehall_Const.GameList.pack_tag){
						Utl.playSound("00052.mp3");
						gamehall_Data.gameIdx = up_id - 1;
						var gameList = gamehall_GameUI.Mem.gameList;
					//	if(gameList[gamehall_Data.gameIdx].isDownload == 0){
						//	if(gameList[gamehall_Data.gameIdx].gameid){
						//		gamehall_GameUI.openCheckDownload(gamehall_Data.gameIdx);
						//	}else{
								//GameUI.OpenTips("游戏正在拼命内测，敬请期待~~",ConstVal.Tips.time);
						//	}
						//}else{
							if(!gameList[gamehall_Data.gameIdx].othergameurlurl){
								var data={};
								var webtype = 3;
								if(gameList[up_id - 1].webtype){
									webtype = gameList[up_id - 1].webtype;
								}
								data.webtype = webtype;
								data.gamedir = gameList[up_id - 1].gamedir;
								data.gameid = gameList[up_id - 1].gameid;
								gamehall_Logic.saveGameinfo(JSON.stringify(data));

								var data1={};
								data1.from=2;
								data1.opt = "loginPlayerid";
								data1.data = Utl.ReadData(gamehall_Logic.launchGameId);
								Func.SwitchOverGameData(webtype,gameList[up_id - 1].gamedir,gameList[up_id - 1].gameid,data1);
							}else{
								gamehall_Data.gameInfo = gameList[gamehall_Data.gameIdx];
								if(!gamehall_Data.isLogin){
									var sdata={};
									sdata.agentid = GameData.AgentId;
									sdata.openid = C_Player.openid;
									sdata.nickname = C_Player.nickname;
									sdata.avatar = C_Player.avatar;
									sdata.sex = C_Player.sex;
									sdata.province = C_Player.province;
									sdata.city = C_Player.city;
									sdata.unionid = C_Player.unionid;
									sdata.gameid=gameList[0].gameid;
									sdata.version = 99999;
									sdata.channelid = GameData.ChannelId;
									sdata.marketid = GameData.marketID;
									var msg={};
									msg.data=sdata;
									msg.app=AppList.app;
									msg.route=RouteList.agent;
									msg.rpc=RpcList.player_login;
									var url="http://"+gameList[0].game_server_http+"/index.html";
									Func.AjaxHttp2(url,msg,gamehall_Logic.httpLogin,function(){
										GameUI.OpenTips("网络出现了点小状况，请稍后再试~~",ConstVal.Tips.time);
									});
								}else{
									gamehall_Logic.jumpOtherGame(gamehall_Data.gameInfo);
								}
							}
						//}
					}
				}
				break;
			case gamehall_Const.categoryTwo.f_spid://点击游戏列表
				var up_id = ifast_check_add(spid_up,upx,upy);

				if(!gamehall_Data.categoryTwo.isSlide){
					//console.log(up_id);
					if(up_id>=gamehall_Const.categoryTwo.bg_tag&&up_id<gamehall_Const.categoryTwo.pack_tag){

						if(!gamehall_Data.categoryTwo.gameList[up_id - 1].othergameurlurl){
							var data={};
							var webtype = 3;
							if(gamehall_Data.categoryTwo.gameList[up_id - 1].webtype){
								webtype = gamehall_Data.categoryTwo.gameList[up_id - 1].webtype;
							}
							data.webtype = webtype;
							data.gamedir = gamehall_Data.categoryTwo.gameList[up_id - 1].gamedir;
							data.gameid = gamehall_Data.categoryTwo.gameList[up_id - 1].gameid;
							gamehall_Logic.saveGameinfo(JSON.stringify(data));
							var data1={};
							data1.from=2;
							data1.opt = "loginPlayerid";
							data1.data = Utl.ReadData(gamehall_Logic.launchGameId);
							Func.SwitchOverGameData(webtype,gamehall_Data.categoryTwo.gameList[up_id - 1].gamedir,gamehall_Data.categoryTwo.gameList[up_id - 1].gameid,data1);
						}else{
								gamehall_Data.gameInfo = gamehall_Data.categoryTwo.gameList[up_id - 1];
								if(!gamehall_Data.isLogin){
									var sdata={};
									sdata.agentid = GameData.AgentId;
									sdata.openid = C_Player.openid;
									sdata.nickname = C_Player.nickname;
									sdata.avatar = C_Player.avatar;
									sdata.sex = C_Player.sex;
									sdata.province = C_Player.province;
									sdata.city = C_Player.city;
									sdata.unionid = C_Player.unionid;
									sdata.gameid=gamehall_Data.GameList[0].gameid;
									sdata.version = 99999;
									sdata.channelid = GameData.ChannelId;
									sdata.marketid = GameData.marketID;
									var msg={};
									msg.data=sdata;
									msg.app=AppList.app;
									msg.route=RouteList.agent;
									msg.rpc=RpcList.player_login;
									var url="http://"+gamehall_Data.GameList[0].game_server_http+"/index.html";
									Func.AjaxHttp2(url,msg,gamehall_Logic.httpLogin,function(){
										GameUI.OpenTips("网络出现了点小状况，请稍后再试~~",ConstVal.Tips.time);
									});
								}else{
									gamehall_Logic.jumpOtherGame(gamehall_Data.gameInfo);
								}
							}
					}
				}
				break;
			case gamehall_Const.Location.f_spid:
				var up_id = ifast_check_add(spid_up,upx,upy);
				if(!gamehall_Data.selectAgentSlide){
					if(up_id >= gamehall_Const.Location.selectTag && up_id < gamehall_Const.Location.nameTag){						
						gamehall_GameUI.selectAgent(up_id - gamehall_Const.Location.selectTag);
					}
				}
				break;
			//case 1002:
				//GameUI.OpenInfo_hall();
				//break;
			case 1010:
				var data={};
				var webtype = 3;
				if(gamehall_Data.GameList[gamehall_Data.gameIdx].webtype){
					webtype = gamehall_Data.GameList[gamehall_Data.gameIdx].webtype;
				}
				data.webtype = webtype;
				data.gamedir = gamehall_Data.GameList[gamehall_Data.gameIdx].gamedir;
				data.gameid = gamehall_Data.GameList[gamehall_Data.gameIdx].gameid;
				gamehall_Logic.saveGameinfo(JSON.stringify(data));
				var data1={};
				data1.from=2;
				data1.opt = "loginPlayerid";
				data1.data = Utl.ReadData(gamehall_Logic.launchGameId);
				Func.SwitchOverGameData(webtype,gamehall_Data.GameList[gamehall_Data.gameIdx].gamedir,gamehall_Data.GameList[gamehall_Data.gameIdx].gameid,data1);
				gamehall_GameUI.closeCheckDownload();
				break;
			case 1011:
			case 1008:
				gamehall_GameUI.closeCheckDownload();
				break;
			case 1029:
				gamehall_GameUI.showCategoryOne();
				break;
			case 1030:
				gamehall_GameUI.showCategoryTwo();
				break;
			case 1031:
				gamehall_GameUI.showCategoryThree();
				break;
			case 1032:
				gamehall_GameUI.showCategoryFour();
				break;
			case 1033:
				gamehall_GameUI.showCategoryFive();
				break;
				//确认切换 
			case 1036:
				gamehall_GameUI.switchLocalHall();
				break;
				//取消切换 
			case 1038:
			case 1034:
				gamehall_GameUI.closeCheckSwitch();
				break;
			case 1040:
				gamehall_GameUI.openSelectAgent();
				break;
			case 1042:
			case 1049:
				gamehall_GameUI.closeSelectAgent();
				break;
			case 1048:
				gamehall_Data.agentConfigTemp = gamehall_Data.selectedAgent;
				gamehall_GameUI.switchLocalHall();
				break;
		}	
		if(spid_up >= 1029 && spid_up <=1033){
			Utl.playSound("00052.mp3");
			gamehall_Data.categoryPage = spid_up-1029;
			gamehall_GameUI.updateSelectBar();
		}
	}
}

gamehall_GameUI.utlmousemove = function(gameid, spid, downx, downy, movex,movey ,timelong,offmovex, offmovey, no1){
	switch(spid){
		case gamehall_Const.GameList.f_spid://游戏列表
		
			if(ifast_abs(offmovex)>10){
			
				set_self(spid,18,offmovex,1,0);
				gamehall_Data.isSliderGameList = true;
			}
			break;
		case gamehall_Const.categoryTwo.f_spid://游戏列表

			if(ifast_abs(offmovex)>10){
				
				set_self(spid,18,offmovex,1,0);
				gamehall_Data.categoryTwo.isSlide = true;
			}
			break;
		case gamehall_Const.Location.f_spid://游戏列表

			if(ifast_abs(offmovey)>10){

				set_self(spid,19,offmovey,1,0);
				gamehall_Data.selectAgentSlide = true;
			}
			break;
	}
}

gamehall_GameUI.utlgamemydraw = function(gameid, spid, times, timelong, no2, no3, no4, no5, no6, no7){
	
}
gamehall_GameUI.utlgamemydrawbegin = function(gameid, spid, times, timelong, no2, no3, no4, no5, no6, no7){
	if(spid==gamehall_Const.GameList.f_spid){
		set_clip(0,0,gamehall_Const.GameList.clip_x,gamehall_Const.GameList.clip_y,gamehall_Const.GameList.clip_w,gamehall_Const.GameList.clip_h);
		set_clip(0,0,gamehall_Const.GameList.place_x1,gamehall_Const.GameList.clip_y,gamehall_Const.GameList.pageWidth,gamehall_Const.GameList.clip_h);
	}
	if(spid==gamehall_Const.Location.f_spid){
		set_clip(0,0,gamehall_Const.Location.clip_x,gamehall_Const.Location.clip_y,gamehall_Const.Location.clip_w,gamehall_Const.Location.clip_h);
	}
}
gamehall_GameUI.utlontimer = function(gameid, spid, /* 本次间隔多少次了 */ times, /* 本次间隔多久 */ timelong,/* 开启后运行多少次了 */ alltimes){
	
}
//显示游戏大厅子游戏信息按钮
gamehall_GameUI.updateHall = function(){
	for(var i=0;i<gamehall_Data.GameList.length;i++){
		if(!gamehall_Data.GameList[i].othergameurlurl){
			gamehall_Data.GameList[i].isDownload = Func.getInstallInfo(gamehall_Data.GameList[i].gamedir);
			//Func.up_imgurl(gamehall_Data.GameList[i].imgres,gamehall_Data.GameList[i].gameimage);
			//Func.up_imgurl(512+i,gamehall_Data.GameList[i].gameimage);
			if(!gamehall_Data.GameList[i].gameid){
				gamehall_Data.GameList[i].isDownload = 0;
			}
		}else{
			gamehall_Data.GameList[i].isDownload = 1;
		}
	}
	//gamehall_Data.GameList[1].isDownload = 1;
	/*
	gamehall_Data.categoryTwo.gameList=[];
	for(var i=0;i<gamehall_Data.GameList.length;i++){
		if(gamehall_Data.GameList[i].isDownload == 1){//已下载
			gamehall_Data.categoryTwo.gameList.push(gamehall_Data.GameList[i]);
		}
	}*/
	gamehall_Data.categoryTwo.gameList=[];
	for(var i=0;i<gamehall_Data.GameList.length;i++){
		if(gamehall_Data.GameList[i].category == 1){//分类一 
			gamehall_Data.categoryTwo.gameList.push(gamehall_Data.GameList[i]);
		}
	}
	gamehall_Data.categoryThree.gameList=[];
	for(var i=0;i<gamehall_Data.GameList.length;i++){
		if(gamehall_Data.GameList[i].category == 2){//分类二 
			gamehall_Data.categoryThree.gameList.push(gamehall_Data.GameList[i]);
		}
	}
	gamehall_Data.categoryFour.gameList=[];
	for(var i=0;i<gamehall_Data.GameList.length;i++){
		if(gamehall_Data.GameList[i].category == 3){//分类三 
			gamehall_Data.categoryFour.gameList.push(gamehall_Data.GameList[i]);
		}
	}
	gamehall_Data.categoryFive.gameList=[];
	for(var i=0;i<gamehall_Data.GameList.length;i++){
		if(gamehall_Data.GameList[i].category == 4){//分类四 
			gamehall_Data.categoryFive.gameList.push(gamehall_Data.GameList[i]);
		}
	}
	
	//调整已下载位置 
	gamehall_Data.GameList = gamehall_GameUI.resetDownloaded(gamehall_Data.GameList);
	gamehall_Data.categoryTwo.gameList = gamehall_GameUI.resetDownloaded(gamehall_Data.categoryTwo.gameList);
	gamehall_Data.categoryThree.gameList = gamehall_GameUI.resetDownloaded(gamehall_Data.categoryThree.gameList);
	gamehall_Data.categoryFour.gameList = gamehall_GameUI.resetDownloaded(gamehall_Data.categoryFour.gameList);
	gamehall_Data.categoryFive.gameList = gamehall_GameUI.resetDownloaded(gamehall_Data.categoryFive.gameList);
	return;
	var gameListTemp1 = [];
	var gameListTemp2 = [];
	var gameListTemp3 = [];
	for(var i=0;i<gamehall_Data.GameList.length;i++){
		if(gamehall_Data.GameList[i].isDownload == 1){//已下载
			gameListTemp1.push(gamehall_Data.GameList[i]);
		}else{
			if(gamehall_Data.GameList[i].gameid){
				gameListTemp2.push(gamehall_Data.GameList[i]);
			}else{
				gameListTemp3.push(gamehall_Data.GameList[i]);
			}

		}
	}
	gamehall_Data.GameList = gameListTemp1.concat(gameListTemp2).concat(gameListTemp3);
}
//将已下载调到前面位置
gamehall_GameUI.resetDownloaded = function(gameList){
	var gameListTemp1 = [];
	var gameListTemp2 = [];
	var gameListTemp3 = [];
	for(var i=0;i<gameList.length;i++){
		if(gameList[i].isDownload == 1){//已下载
			gameListTemp1.push(gameList[i]);
		}else{
			if(gameList[i].gameid){
				gameListTemp2.push(gameList[i]);
			}else{
				gameListTemp3.push(gameList[i]);
			}

		}
	}
	gameList = gameListTemp1.concat(gameListTemp2).concat(gameListTemp3);
	return gameList;
} 
//获取当前滑动恢复位置 
gamehall_GameUI.getSlideLocation = function(x){
	
	var pageLocation = [];
	var categoryObj = gamehall_GameUI.Mem.categoryObj;
	for(var i=0;i < categoryObj.pageCount;i++ ){
		pageLocation.push(gamehall_Const.GameList.place_x1 - i*(gamehall_Const.GameList.pageSpace + gamehall_Const.GameList.pageWidth));
	}
	var pIndex = categoryObj.pageTag;
	if(gamehall_Data.deltaX > gamehall_Const.GameList.deltaX){//向右滑动
		if(categoryObj.pageTag == 0){
			pIndex =0;
		}else{
			pIndex = (categoryObj.pageTag - 1) % categoryObj.pageCount;
		}

	}else if(gamehall_Data.deltaX < -gamehall_Const.GameList.deltaX){//向左滑动

		if(categoryObj.pageTag == categoryObj.pageCount - 1){
			pIndex = categoryObj.pageTag;
		}else{
			pIndex = (categoryObj.pageTag + 1) % categoryObj.pageCount;
		}
	}
	categoryObj.pageTag = pIndex;
	//gamehall_GameUI.updateCategoryOnePageNumber();
	gamehall_GameUI.updatePageNumber(categoryObj.pageTag);
	return pageLocation[pIndex];
} 
gamehall_GameUI.getSlideLocation2 = function(x){
	//if(x > gamehall_Const.categoryTwo.place_x1 ){
		//return gamehall_Const.categoryTwo.place_x1;
	//}
	//if(x < gamehall_Const.categoryTwo.place_x1 - get_self(gamehall_Const.categoryTwo.f_spid,20,0,0,0)-(gamehall_Const.categoryTwo.pageSpace + gamehall_Const.categoryTwo.pageWidth)){
		//return gamehall_Const.categoryTwo.place_x1 - get_self(gamehall_Const.categoryTwo.f_spid,20,0,0,0);
	//}
	var pageLocation = [];
	
	for(var i=0;i < gamehall_Data.categoryTwo.pageCount;i++ ){
		pageLocation.push(gamehall_Const.categoryTwo.place_x1 - i*(gamehall_Const.categoryTwo.pageSpace + gamehall_Const.categoryTwo.pageWidth));
	}
	
	//if(x > pageLocation[0]){
		//pIndex = 0;
	//}else{
		//if(x < pageLocation[pageLocation.length - 1]){
			//pIndex = pageLocation.length - 1;
		//}else{
			//for(var i=0;i<gamehall_Data.categoryTwo.pageCount - 1;i++){
				//if(x <= pageLocation[i] - gamehall_Const.categoryTwo.deltaX && x > pageLocation[i+1]){
					//pIndex = i+1;
					//break;
				//}
			//}
		//}
	//}
	var pIndex = gamehall_Data.categoryTwo.pageTag;
	if(gamehall_Data.deltaX > gamehall_Const.categoryTwo.deltaX){//向右滑动 
		if(gamehall_Data.categoryTwo.pageTag == 0){
			pIndex =0;
		}else{
			pIndex = (gamehall_Data.categoryTwo.pageTag - 1) % gamehall_Data.categoryTwo.pageCount;
		}
		
	}else if(gamehall_Data.deltaX < -gamehall_Const.categoryTwo.deltaX){//向左滑动 
		
		if(gamehall_Data.categoryTwo.pageTag == gamehall_Data.categoryTwo.pageCount - 1){
			pIndex = gamehall_Data.categoryTwo.pageTag;
		}else{
			pIndex = (gamehall_Data.categoryTwo.pageTag + 1) % gamehall_Data.categoryTwo.pageCount;
		}
	}
	//return gamehall_Data.categoryTwo.pageTag;
	//console.log(pIndex);
	gamehall_Data.categoryTwo.pageTag = pIndex;
	//gamehall_GameUI.updateCategoryTwoPageNumber();
	gamehall_GameUI.updatePageNumber(gamehall_Data.categoryTwo.pageTag);
	return pageLocation[pIndex];
}
//设置首页页数 
/*
gamehall_GameUI.setCategoryOnePageCount = function(){
	if(gamehall_Data.GameList.length<=6){
		gamehall_Data.categoryOne.pageCount = 1;
	}else{
		gamehall_Data.categoryOne.pageCount = Math.ceil((gamehall_Data.GameList.length-6)/8)+1;
	}
}*/
//设置首页页数
gamehall_GameUI.setCategoryOnePageCount = function(){
	gamehall_Data.categoryOne.pageCount = Math.ceil(gamehall_Data.GameList.length/6);
	/*
	if(gamehall_Data.GameList.length<=6){
		gamehall_Data.categoryOne.pageCount = 1;
	}else{
		gamehall_Data.categoryOne.pageCount = Math.ceil((gamehall_Data.GameList.length-6)/8)+1;
	}*/
}

//设置首页页数
gamehall_GameUI.setCategoryTwoPageCount = function(){
	gamehall_Data.categoryTwo.pageCount = Math.ceil(gamehall_Data.categoryTwo.gameList.length/6);
}
gamehall_GameUI.getCategoryOnePageTag = function(tag){
	return Math.floor(tag/6);
	if(tag<5){
		return 0;
	}else{
		return Math.ceil((tag-5)/8);
	}
}
gamehall_GameUI.getCategoryTwoPageTag = function(tag){
	return Math.floor(tag/6);

}
gamehall_GameUI.showCategoryTwo = function(){
	set_self(1015,37,1,0,0);
	set_self(1016,37,1,0,0);
	set_self(gamehall_Const.GameList.f_spid,37,0,0,0);
	gamehall_Data.categoryPage = 1;
	gamehall_GameUI.createDownloadedPage();
	gamehall_GameUI.updateCategoryItem();
}
gamehall_GameUI.createDownloadedPage = function(){
	gamehall_GameUI.createCategory(gamehall_Data.categoryTwo.gameList,gamehall_Data.categoryTwo,0);
	return;
	//set_self(1001,1,219,0,0);
	gamehall_Data.categoryTwo.pageTag = 0;
	gamehall_GameUI.clearCategoryTwo();
	gamehall_GameUI.clearGameHall();
	gamehall_GameUI.setCategoryTwoPageCount();
	var pages = gamehall_Data.categoryTwo.pageCount;	
	set_self(gamehall_Const.categoryTwo.f_spid,37,1,0,0);
	set_self(gamehall_Const.categoryTwo.bg_spid,37,1,0,0);
	set_self(gamehall_Const.categoryTwo.f_spid,18,gamehall_Const.categoryTwo.place_x1,0,0);
	set_self(gamehall_Const.categoryTwo.f_spid,20,gamehall_Const.categoryTwo.pageWidth*pages+(pages-1)*gamehall_Const.categoryTwo.pageSpace,0,0);
	set_self(gamehall_Const.categoryTwo.f_spid,21,gamehall_Const.categoryTwo.h,0,0);
	if(!gamehall_Data.categoryTwo.isCreate){//未创建
		for(var i=0;i<gamehall_Data.categoryTwo.gameList.length;i++){
			var pageSpace = gamehall_GameUI.getCategoryTwoPageTag(i)*(gamehall_Const.categoryTwo.pageSpace+gamehall_Const.categoryTwo.pageWidth);
			//var fSpid = gamehall_Const.GameList.bg_spid;
			var bgsp = ifast_addtospritefromspritecopy(gamehall_Const.categoryTwo.f_spid,gamehall_Const.categoryTwo.bg_spid,
				pageSpace + i%3*(gamehall_Const.GameList.sizeList[2][0]+gamehall_Const.GameList.pageOne.spaceX4),
				Math.floor((i%6)/3)*(gamehall_Const.GameList.sizeList[2][1]+gamehall_Const.GameList.pageOne.spaceY1),gamehall_Const.categoryTwo.bg_tag+i);//背景
			
			if(gamehall_Data.categoryTwo.gameList[i].res_frame){
				set_self(bgsp,1,gamehall_Const.categoryTwo.mFrameImgRes[gamehall_Data.categoryTwo.gameList[i].res_frame[0]],0,0);
				set_self(bgsp,43,gamehall_Data.categoryTwo.gameList[i].res_frame[1],0,0);
			}else{
				if(gamehall_Data.categoryTwo.gameList[i].imgres){
					set_self(bgsp,1,gamehall_Data.categoryTwo.gameList[i].imgres,0,0);
				}
			}
			if(gamehall_Data.categoryTwo.gameList[i].gamedir == gamehall_Data.GameList[0].gamedir && gamehall_Data.categoryTwo.gameList[i].downloadimg){
				set_self(bgsp,1,116,0,0,0);
			}
			if(gamehall_Data.categoryTwo.gameList[i].gamedir ==  gamehall_Data.GameList[1].gamedir && gamehall_Data.categoryTwo.gameList[i].downloadimg){
				set_self(bgsp,1,117,0,0,0);
			}

		}

		gamehall_Data.categoryTwo.isCreate = true;
		gamehall_Data.categoryTwo.createLength = gamehall_Data.categoryTwo.gameList.length;
		/*
		set_self(1025,37,1,0,0);
		set_self(1026,37,1,0,0);
		gamehall_Data.pageTwoNumberLength = gamehall_Data.categoryTwo.pageCount;
		set_self(1025,20,32*gamehall_Data.categoryTwo.pageCount - 16,0,0);
		for(var i=0;i<gamehall_Data.categoryTwo.pageCount;i++){
			var pnSp = ifast_addtospritefromspritecopy(1025,1026,
					i*32,0,i);
				gamehall_Data.pageTwoNumberList.push(pnSp);
		}
		GameUI.adaptPositionX(1025,767);
		gamehall_GameUI.updateCategoryTwoPageNumber();
		*/
		gamehall_GameUI.createPageItem(gamehall_Data.categoryTwo.pageCount);
		gamehall_GameUI.updatePageNumber(gamehall_Data.categoryTwo.pageTag);
	}else{

	}
}
gamehall_GameUI.updateCategoryTwoPageNumber = function(){
	for(var i=0;i<gamehall_Data.pageTwoNumberList.length;i++){
		if(i == gamehall_Data.categoryTwo.pageTag){
			set_self(gamehall_Data.pageTwoNumberList[i],43,2,0,0);
		}else{
			set_self(gamehall_Data.pageTwoNumberList[i],43,1,0,0);
		}
	}
}
gamehall_GameUI.clearCategoryTwo = function(){
	if(gamehall_Data.categoryTwo.isCreate){
		for(var i=0;i<gamehall_Data.categoryTwo.createLength;i++ ){
			ifast_dllpritefromspritecopy(gamehall_Const.categoryTwo.f_spid,gamehall_Const.categoryTwo.bg_tag+i);
		}
		gamehall_Data.categoryTwo.isCreate = false;	
		gamehall_Data.categoryTwo.createLength = 0;
	}
	//for(var i=0;i<gamehall_Data.pageTwoNumberLength;i++){
	//	ifast_dllpritefromspritecopy(1025,1026,i);
	//}
	gamehall_Data.pageTwoNumberLength = 0;
	gamehall_Data.pageTwoNumberList = [];
	set_group(203,37,0,0,0);
}
gamehall_GameUI.showCategoryOne = function(){
	gamehall_GameUI.createCategory(gamehall_Data.GameList,gamehall_Data.categoryOne,0);
	return;
	//set_self(1001,1,219,0,0);
	gamehall_Data.categoryOne.pageTag = 0;
	gamehall_GameUI.clearGameHall();
	gamehall_GameUI.clearCategoryTwo();
	set_self(1015,37,1,0,0);
	set_self(1016,37,1,0,0);
	gamehall_Data.categoryPage = 0;
	gamehall_Data.categoryOne.pageTag = 0;
	gamehall_GameUI.setCategoryOnePageCount();
	var pages = gamehall_Data.categoryOne.pageCount;
	
	set_self(gamehall_Const.GameList.f_spid,37,1,0,0);
	set_self(gamehall_Const.GameList.bg_spid,37,1,0,0);
	set_self(gamehall_Const.GameList.spidList[0],37,1,0,0);
	set_self(gamehall_Const.GameList.spidList[1],37,1,0,0);
	set_self(gamehall_Const.GameList.spidList[2],37,1,0,0);
	set_self(gamehall_Const.GameList.pack_spid,37,1,0,0);
	set_self(gamehall_Const.GameList.front_spid,37,1,0,0);
	set_self(1007,37,1,0,0);
	set_self(gamehall_Const.GameList.f_spid,18,gamehall_Const.GameList.place_x1,0,0);
	//set_self(gamehall_Const.GameList.f_spid,20,gamehall_Data.GameList.length*(gamehall_Const.GameList.dis_x+gamehall_Const.GameList.w),0,0);
	set_self(gamehall_Const.GameList.f_spid,20,gamehall_Const.GameList.pageWidth*pages+(pages-1)*gamehall_Const.GameList.pageSpace,0,0);
	//set_self(gamehall_Const.GameList.f_spid,20,pages*(gamehall_Const.GameList.pageSpace+gamehall_Const.GameList.pageWidth),0,0);
	set_self(gamehall_Const.GameList.f_spid,21,gamehall_Const.GameList.h,0,0);
	if(!gamehall_Data.isCreateGameList){//未创建
		for(var i=0;i<gamehall_Data.GameList.length;i++){
			var pageSpace = gamehall_GameUI.getCategoryOnePageTag(i)*(gamehall_Const.GameList.pageSpace+gamehall_Const.GameList.pageWidth);
			//var pageSpace
			var fSpid = gamehall_Const.GameList.spidList[2];
			var bgsp;
			/*
			switch(i){
				case 0:
					fSpid = gamehall_Const.GameList.spidList[0];
					bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,fSpid,
					0,0,gamehall_Const.GameList.bg_tag+i);//背景
					break;
				case 1:
					fSpid = gamehall_Const.GameList.spidList[1];
					bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,fSpid,
					gamehall_Const.GameList.sizeList[0][0]+gamehall_Const.GameList.pageOne.spaceX1,
					gamehall_Const.GameList.pageOne.spaceY+gamehall_Const.GameList.sizeList[2][1],gamehall_Const.GameList.bg_tag+i);//背景
					break;
				case 2:
					fSpid = gamehall_Const.GameList.spidList[2];
					bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,fSpid,
					gamehall_Const.GameList.sizeList[0][0]+gamehall_Const.GameList.pageOne.spaceX1,
					0,gamehall_Const.GameList.bg_tag+i);//背景
					break;
				case 3:
					fSpid = gamehall_Const.GameList.spidList[2];
					bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,fSpid,
					gamehall_Const.GameList.sizeList[0][0]+gamehall_Const.GameList.pageOne.spaceX1+gamehall_Const.GameList.sizeList[2][0]+gamehall_Const.GameList.pageOne.spaceX2,
					0,gamehall_Const.GameList.bg_tag+i);//背景
					break;
				case 4:
					fSpid = gamehall_Const.GameList.spidList[2];
					bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,fSpid,
					gamehall_Const.GameList.sizeList[0][0]+gamehall_Const.GameList.pageOne.spaceX1+gamehall_Const.GameList.sizeList[2][0]*2
					+gamehall_Const.GameList.pageOne.spaceX2+gamehall_Const.GameList.pageOne.spaceX3,
					0,gamehall_Const.GameList.bg_tag+i);//背景
					break;
				case 5:
					fSpid = gamehall_Const.GameList.spidList[2];
					bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,fSpid,
					gamehall_Const.GameList.sizeList[0][0]+gamehall_Const.GameList.pageOne.spaceX1+gamehall_Const.GameList.sizeList[2][0]*2
					+gamehall_Const.GameList.pageOne.spaceX2+gamehall_Const.GameList.pageOne.spaceX3,
					gamehall_Const.GameList.pageOne.spaceY+gamehall_Const.GameList.sizeList[2][1],gamehall_Const.GameList.bg_tag+i);//背景
					break;
				default:
					fSpid = gamehall_Const.GameList.spidList[2];
					bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,fSpid,
					pageSpace + (i-6)%4*(gamehall_Const.GameList.sizeList[2][0]+gamehall_Const.GameList.pageOne.spaceX4),
					Math.floor(((i-6)%8)/4)*(gamehall_Const.GameList.sizeList[2][1]+gamehall_Const.GameList.pageOne.spaceY1),gamehall_Const.GameList.bg_tag+i);//背景
					break;
			}
			
			var bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.bg_spid,
			gamehall_Const.GameList.bg_x + (gamehall_Const.GameList.dis_x+gamehall_Const.GameList.w) * i,gamehall_Const.GameList.bg_y,gamehall_Const.GameList.bg_tag+i);//背景
			set_self(bgsp,43,gamehall_Const.GameList.frameList[i],0,0);
			set_self(bgsp,1,116+i,0,0);
			*/
			var bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.bg_spid,
				pageSpace + i%3*(gamehall_Const.GameList.sizeList[2][0]+gamehall_Const.GameList.pageOne.spaceX4),
				Math.floor((i%6)/3)*(gamehall_Const.GameList.sizeList[2][1]+gamehall_Const.GameList.pageOne.spaceY1),gamehall_Const.GameList.bg_tag+i);//背景
			var namesp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.pack_spid,
				pageSpace + i%3*(gamehall_Const.GameList.sizeList[2][0]+gamehall_Const.GameList.pageOne.spaceX4),
				Math.floor((i%6)/3)*(gamehall_Const.GameList.sizeList[2][1]+gamehall_Const.GameList.pageOne.spaceY1)+
				get_self(bgsp,21,0,0,0)+gamehall_Const.GameList.pageOne.spaceY2,gamehall_Const.GameList.pack_tag+i);//背景
				set_self(namesp,7,gamehall_Data.GameList[i].gamename,0,0);
				set_self(namesp,20,gamehall_Data.GameList[i].gamename.gblen()*12,0,0);
				GameUI.adaptPositionSpid(namesp,bgsp);
			if(gamehall_Data.GameList[i].imgres){
				set_self(bgsp,1,gamehall_Data.GameList[i].imgres,0,0);	
			}
			//console.log("------------------------------");
			
			if(gamehall_Data.GameList[i].res_frame){
				set_self(bgsp,1,gamehall_Const.GameList.mFrameImgRes[gamehall_Data.GameList[i].res_frame[0]],0,0);
				set_self(bgsp,43,gamehall_Data.GameList[i].res_frame[1],0,0);
			}else{
				if(gamehall_Data.GameList[i].imgres){
					set_self(bgsp,1,gamehall_Data.GameList[i].imgres,0,0);
				}
			}
			
			if(gamehall_Data.GameList[i].isDownload == 0){
				var maskSpid;
				/*
				switch(i){
					case 0:
						maskSpid = gamehall_Const.GameList.downloadMaskList[0];
						if(!gamehall_Data.GameList[i].gameid){
							maskSpid = gamehall_Const.GameList.waitingList[0];
						}
						break;
					case 1:
						maskSpid = gamehall_Const.GameList.downloadMaskList[1];
						if(!gamehall_Data.GameList[i].gameid){
							maskSpid = gamehall_Const.GameList.waitingList[1];
						}
						break;
					default:
						maskSpid = gamehall_Const.GameList.downloadMaskList[2];
						if(!gamehall_Data.GameList[i].gameid){
							maskSpid = gamehall_Const.GameList.waitingList[2];
						}
						break;
				}
				*/
				maskSpid = gamehall_Const.GameList.downloadMaskList[2];
				if(!gamehall_Data.GameList[i].gameid){
					maskSpid = gamehall_Const.GameList.waitingList[2];
				}
				var downloadmask = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,maskSpid,
				get_self(bgsp,18,0,0,0),
				get_self(bgsp,19,0,0,0),gamehall_Const.GameList.front_tag+i);//未下载遮罩
				//游戏名 
				
				//set_self(namesp);
				
				//if(!gamehall_Data.GameList[i].gameid){
					//set_self(downloadmask,1,512,0,0,0);
				//}
			}else{
				if(!gamehall_Data.GameList[i].gameid){
					var maskSpid;
					/*
					switch(i){
						case 0:
							maskSpid = gamehall_Const.GameList.waitingList[0];
							break;
						case 1:
							maskSpid = gamehall_Const.GameList.waitingList[1];
							break;
						default:
							maskSpid = gamehall_Const.GameList.waitingList[2];
							break;
					}
					*/
					maskSpid = gamehall_Const.GameList.waitingList[2];
					var downloadmask = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,maskSpid,
					get_self(bgsp,18,0,0,0),
					get_self(bgsp,19,0,0,0),gamehall_Const.GameList.front_tag+i);//未下载遮罩
					}
					
			}
			
		}
		
		gamehall_Data.isCreateGameList = true;
		/*
		set_self(1017,37,1,0,0);
		set_self(1018,37,1,0,0);
		gamehall_Data.pageOneNumberLength = gamehall_Data.categoryOne.pageCount;
		set_self(1017,20,32*gamehall_Data.categoryOne.pageCount - 16,0,0);
		for(var i=0;i<gamehall_Data.categoryOne.pageCount;i++){
			var pnSp = ifast_addtospritefromspritecopy(1017,1018,
					i*32,0,i);
				gamehall_Data.pageOneNumberList.push(pnSp);
		}
		GameUI.adaptPositionX(1017,767);
		gamehall_GameUI.updateCategoryOnePageNumber();
		*/
		
		gamehall_GameUI.createPageItem(gamehall_Data.categoryOne.pageCount);
		gamehall_GameUI.updatePageNumber(gamehall_Data.categoryOne.pageTag);
	}else{

	}
	gamehall_GameUI.updateCategoryItem();
}
gamehall_GameUI.updateCategoryOnePageNumber = function(){
	for(var i=0;i<gamehall_Data.pageOneNumberList.length;i++){
		if(i == gamehall_Data.categoryOne.pageTag){
			set_self(gamehall_Data.pageOneNumberList[i],43,2,0,0);
		}else{
			set_self(gamehall_Data.pageOneNumberList[i],43,1,0,0);
		}
	}
}
gamehall_GameUI.clearGameHall = function(){
	if(gamehall_Data.isCreateGameList){//未创建
		for(var i=0;i<gamehall_Data.GameList.length;i++){
			ifast_dllpritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.bg_tag+i);
			ifast_dllpritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.front_tag+i);
			ifast_dllpritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.pack_tag+i);
		}
		gamehall_Data.isCreateGameList = false;
	
	}
	///for(var i=0;i<gamehall_Data.pageOneNumberLength;i++){
	//	ifast_dllpritefromspritecopy(1017,1018,i);
//	}
	gamehall_Data.pageOneNumberLength = 0;
	gamehall_Data.pageOneNumberList = [];
	set_group(204,37,0,0,0);
}
gamehall_GameUI.updateCategoryItem = function(){
	return;
	switch(gamehall_Data.categoryPage){
		case 0:
			set_self(1015,43,2,0,0);
			set_self(1016,43,1,0,0);	
			break;
		case 1:
			set_self(1015,43,1,0,0);
			set_self(1016,43,2,0,0);
			break;
	}
}
/*
gamehall_GameUI.openCheckDownload = function(idx){
	if(gamehall_Data.GameList[idx].zipsize){
		var text="是否下载:"+gamehall_Data.GameList[idx].gamename+"("+gamehall_Data.GameList[idx].zipsize+")?";
	}else{
		var text="是否下载:"+gamehall_Data.GameList[idx].gamename+"?";	
	}
	var t_len = text.gblen()*17; 
	set_self(1012,7,text,0,0);
	set_self(1012,20,t_len,0,0);
	set_self(1012,18,get_self(1009,18,0,0,0) + get_self(1009,20,0,0,0)/2-t_len/2,0,0);
	set_group(201,37,1,0,0);
}*/
gamehall_GameUI.openCheckDownload = function(idx){
	if(gamehall_GameUI.Mem.gameList[idx].zipsize){
		var text="是否下载:"+gamehall_GameUI.Mem.gameList[idx].gamename+"("+gamehall_GameUI.Mem.gameList[idx].zipsize+")?";
	}else{
		var text="是否下载:"+gamehall_GameUI.Mem.gameList[idx].gamename+"?";
	}
	var t_len = text.gblen()*17;
	set_self(1012,7,text,0,0);
	set_self(1012,20,t_len,0,0);
	set_self(1012,18,get_self(1009,18,0,0,0) + get_self(1009,20,0,0,0)/2-t_len/2,0,0);
	set_group(201,37,1,0,0);
}
gamehall_GameUI.closeCheckDownload = function(){
	set_group(201,37,0,0,0);
}
gamehall_GameUI.updateSelectBar = function(){
	set_group(205,37,1,0,0);
	set_self(1029,43,1,0,0,0);//全部
	set_self(1030,43,3,0,0,0);//分类一
	set_self(1031,43,5,0,0,0);//分类二
	set_self(1032,43,7,0,0,0);//分类三
	set_self(1033,43,9,0,0,0);//分类四
	switch(gamehall_Data.categoryPage){
		case 0://全部分类
			set_self(1029,43,2,0,0,0);//全部 
			break;
		case 1://分类一 
			set_self(1030,43,4,0,0,0);//分类一
			break;
		case 2://分类二 
			set_self(1031,43,6,0,0,0);//分类二
			break;
		case 3://分类三 
			set_self(1032,43,8,0,0,0);//分类三
			break;
		case 4://分类四 
			set_self(1033,43,10,0,0,0);//分类四
			break;

	}
}
gamehall_GameUI.createPageItem = function(count){
	gamehall_GameUI.removePageItem();
	set_self(1025,37,1,0,0);
	set_self(1026,37,1,0,0);
	gamehall_Data.pageNumberLength = count;
	var space = 35
	//gamehall_Data.pageTwoNumberLength = count;
	set_self(1025,20,space*count,0,0);
	for(var i=0;i<count;i++){
		var pnSp = ifast_addtospritefromspritecopy(1025,1026,
				i*space,0,i);
			gamehall_Data.pageNumberList.push(pnSp);
	}
	GameUI.adaptPositionX(1025,767);
	//return rList;
}
gamehall_GameUI.removePageItem = function(){
	for(var i=0;i<gamehall_Data.pageNumberLength;i++){
		ifast_dllpritefromspritecopy(1025,i);
	}
	set_self(1025,37,0,0,0);
	set_self(1026,37,0,0,0);
	gamehall_Data.pageNumberLength=0;
	gamehall_Data.pageNumberList = [];
}
gamehall_GameUI.updatePageNumber = function(tag){
	for(var i=0;i<gamehall_Data.pageNumberList.length;i++){
		if(i == tag){
			set_self(gamehall_Data.pageNumberList[i],43,2,0,0);
		}else{
			set_self(gamehall_Data.pageNumberList[i],43,1,0,0);
		}
	}
}
gamehall_GameUI.updateLocation = function(){	
	if(gamehall_Data.agentConfig){
		set_group(209,37,1,0,0);
		set_self(1041,7,gamehall_Data.agentConfig.name,0,0);	
		set_self(1041,20,gamehall_Data.agentConfig.name.gblen()*14,0,0);
		var w = get_self(1041,20) + 70;
		if(w > 135){
			set_self(1040,20,w,0,0);
		}else{
			set_self(1040,20,135,0,0);
		}
	}else{
		set_group(209,37,0,0,0);
	}
}
gamehall_GameUI.showGameHall = function(){
	gamehall_GameUI.updateLocation();
	gamehall_GameUI.updateSelectBar();
	gamehall_GameUI.updateHall();
	switch(gamehall_Data.categoryPage){
		case 0://全部
			gamehall_GameUI.showCategoryOne();
			break;
		case 1://分类一
			gamehall_GameUI.showCategoryTwo();
			break;
		case 2://分类二
			gamehall_GameUI.showCategoryThree();
			break;
		case 3://分类三
			gamehall_GameUI.showCategoryFour();
			break;
		case 4://分类四
			gamehall_GameUI.showCategoryFive();
			break;
	}
}
gamehall_GameUI.showCategoryThree = function(){
	gamehall_GameUI.createCategory(gamehall_Data.categoryThree.gameList,gamehall_Data.categoryThree,2);
}
gamehall_GameUI.showCategoryFour = function(){
	gamehall_GameUI.createCategory(gamehall_Data.categoryFour.gameList,gamehall_Data.categoryFour,3);
}
gamehall_GameUI.showCategoryFive = function(){
	gamehall_GameUI.createCategory(gamehall_Data.categoryFive.gameList,gamehall_Data.categoryFive,4);
}
gamehall_GameUI.createCategory = function(gameList,categoryObject,page){
	gamehall_GameUI.Mem.categoryObj = categoryObject;
	gamehall_GameUI.Mem.gameList = gameList;
	//gamehall_Data.categoryOne.pageTag = 0;
	gamehall_GameUI.clearCategory();
	categoryObject.pageTag = 0;
	set_self(1015,37,1,0,0);
	set_self(1016,37,1,0,0);
	gamehall_Data.categoryPage = page;
	gamehall_GameUI.setCategoryPageCount(categoryObject,gameList.length);
	var pages = categoryObject.pageCount;
	set_self(gamehall_Const.GameList.f_spid,19,gamehall_Const.GameList.clip_y,0,0);
	set_self(gamehall_Const.GameList.f_spid,37,1,0,0);
	set_self(gamehall_Const.GameList.bg_spid,37,1,0,0);
	set_self(gamehall_Const.GameList.spidList[0],37,1,0,0);
	set_self(gamehall_Const.GameList.spidList[1],37,1,0,0);
	set_self(gamehall_Const.GameList.spidList[2],37,1,0,0);
	set_self(gamehall_Const.GameList.pack_spid,37,1,0,0);
	set_self(gamehall_Const.GameList.front_spid,37,1,0,0);
	set_self(1007,37,1,0,0);
	set_self(gamehall_Const.GameList.f_spid,18,gamehall_Const.GameList.place_x1,0,0);
	//set_self(gamehall_Const.GameList.f_spid,20,gamehall_Data.GameList.length*(gamehall_Const.GameList.dis_x+gamehall_Const.GameList.w),0,0);
	set_self(gamehall_Const.GameList.f_spid,20,gamehall_Const.GameList.pageWidth*pages+(pages-1)*gamehall_Const.GameList.pageSpace,0,0);
	//set_self(gamehall_Const.GameList.f_spid,20,pages*(gamehall_Const.GameList.pageSpace+gamehall_Const.GameList.pageWidth),0,0);
	set_self(gamehall_Const.GameList.f_spid,21,gamehall_Const.GameList.h,0,0);
	if(!gamehall_Data.isCreateGameList){//未创建
		for(var i=0;i<gameList.length;i++){
			var pageSpace = gamehall_GameUI.getCategoryOnePageTag(i)*(gamehall_Const.GameList.pageSpace+gamehall_Const.GameList.pageWidth);
			var fSpid = gamehall_Const.GameList.spidList[2];
			var bgsp;
			var bgsp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.bg_spid,
				pageSpace + i%3*(gamehall_Const.GameList.sizeList[2][0]+gamehall_Const.GameList.pageOne.spaceX4),
				Math.floor((i%6)/3)*(gamehall_Const.GameList.sizeList[2][1]+gamehall_Const.GameList.pageOne.spaceY1),gamehall_Const.GameList.bg_tag+i);//背景
			var namesp = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.pack_spid,
				pageSpace + i%3*(gamehall_Const.GameList.sizeList[2][0]+gamehall_Const.GameList.pageOne.spaceX4),
				Math.floor((i%6)/3)*(gamehall_Const.GameList.sizeList[2][1]+gamehall_Const.GameList.pageOne.spaceY1)+
				get_self(bgsp,21,0,0,0)+gamehall_Const.GameList.pageOne.spaceY2,gamehall_Const.GameList.pack_tag+i);//背景
				set_self(namesp,7,gameList[i].gamename,0,0);
				set_self(namesp,20,gameList[i].gamename.gblen()*12,0,0);
				GameUI.adaptPositionSpid(namesp,bgsp);
			if(gameList[i].imgres){
				set_self(bgsp,1,gameList[i].imgres,0,0);
			}
			//console.log("------------------------------");

			if(gameList[i].res_frame){
				set_self(bgsp,1,gamehall_Const.GameList.mFrameImgRes[gameList[i].res_frame[0]],0,0);
				set_self(bgsp,43,gameList[i].res_frame[1],0,0);
			}else{
				if(gameList[i].imgres){
					set_self(bgsp,1,gameList[i].imgres,0,0);
				}
			}
		/*	
			if(gameList[i].isDownload == 0){
				var maskSpid;
				maskSpid = gamehall_Const.GameList.downloadMaskList[2];
				if(!gameList[i].gameid){
					maskSpid = gamehall_Const.GameList.waitingList[2];
				}
				var downloadmask = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,maskSpid,
				get_self(bgsp,18,0,0,0),
				get_self(bgsp,19,0,0,0),gamehall_Const.GameList.front_tag+i);//未下载遮罩
			}else{
				if(!gameList[i].gameid){
					var maskSpid;
					maskSpid = gamehall_Const.GameList.waitingList[2];
					var downloadmask = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,maskSpid,
					get_self(bgsp,18,0,0,0),
					get_self(bgsp,19,0,0,0),gamehall_Const.GameList.front_tag+i);//未下载遮罩
					}

			}
			*/
			if(!gameList[i].gameid){
				var maskSpid;
				maskSpid = gamehall_Const.GameList.waitingList[2];
				var downloadmask = ifast_addtospritefromspritecopy(gamehall_Const.GameList.f_spid,maskSpid,
				get_self(bgsp,18,0,0,0),
				get_self(bgsp,19,0,0,0),gamehall_Const.GameList.front_tag+i);//未下载遮罩
			}
			
		}
	
		gamehall_Data.isCreateGameList = true;

		gamehall_GameUI.createPageItem(categoryObject.pageCount);
		gamehall_GameUI.updatePageNumber(categoryObject.pageTag);
		gamehall_Data.hallCreateLength = gameList.length;
	}else{

	}
	gamehall_GameUI.updatePageNumber(categoryObject.pageTag);
}

gamehall_GameUI.clearCategory = function(){
	if(gamehall_Data.isCreateGameList){//未创建
		for(var i=0;i<gamehall_Data.hallCreateLength;i++){
			ifast_dllpritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.bg_tag+i);
			//ifast_dllpritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.front_tag+i);
			ifast_dllpritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.pack_tag+i);
			ifast_dllpritefromspritecopy(gamehall_Const.GameList.f_spid,gamehall_Const.GameList.front_tag+i);
		}
		gamehall_Data.isCreateGameList = false;

	}	
}

gamehall_GameUI.setCategoryPageCount = function(obj,len){
	//gamehall_Data.categoryOne.pageCount = Math.ceil(gamehall_Data.GameList.length/6);
	obj.pageCount = Math.ceil(len/6);
}
gamehall_GameUI.openCheckSwitch = function(bTemp){
	if(!get_self(4,37,0,0,0)){return;}
	if(gamehall_Data.agentConfigTemp){
		if(bTemp){
			gamehall_Data.isLocation = 1;
			Utl.SaveData(gamehall_Logic.isLocation,1);
			gamehall_Data.isLocation = 1;
				
		}
		GameUI.CloseBoard();
		GameUI.EndLoad();
		var text = "是否切换到当前地区("+gamehall_Data.agentConfigTemp.name+")大厅?";
		var t_len = text.gblen()*17;
		set_self(1039,7,text,0,0);
		set_self(1039,20,t_len,0,0);
		set_self(1039,18,get_self(1035,18,0,0,0) + get_self(1035,20,0,0,0)/2-t_len/2,0,0);
		set_group(208,37,1,0,0);
	}
}
gamehall_GameUI.closeCheckSwitch = function(){
	set_group(208,37,0,0,0);	
}
gamehall_GameUI.switchLocalHall = function(){
	if(gamehall_Data.agentConfigTemp){
		gamehall_Data.agentConfig = gamehall_Data.agentConfigTemp;
		gamehall_Logic.setGameListByRgn(gamehall_Data.agentConfig.agentCode);
		gamehall_GameUI.showGameHall();
		gamehall_GameUI.closeCheckSwitch();
	}else{
		gamehall_GameUI.closeCheckSwitch();
	}
	gamehall_GameUI.closeSelectAgent();
}
gamehall_GameUI.openSelectAgent =function(){
	set_group(210,37,1,0,0);
	gamehall_Data.agentList = gamehall_GameUI.getAgentList(gamehall_Data.gameHallConfig.agentConfig);
	gamehall_GameUI.createAgentList();
}
gamehall_GameUI.closeSelectAgent = function(){
	set_group(210,37,0,0,0);	
}
gamehall_GameUI.createAgentList = function(){
	gamehall_GameUI.removeAgentList();
	if(gamehall_Data.gameHallConfig.agentConfig){
		gamehall_Data.agentListLength = 0;
		set_group(210,37,1,0,0);
		set_self(gamehall_Const.Location.f_spid,18,gamehall_Const.Location.clip_x,0,0);
		set_self(gamehall_Const.Location.f_spid,19,gamehall_Const.Location.clip_y,0,0);
		var cX = 0;
		var cY = 0;
		var tag = 0;
		var cY1 = 0;
		gamehall_Data.selectItemTagList = [];//列表
		gamehall_Data.selectItemSpList = [];//精灵列表 
		for(var i=0;i<gamehall_Data.agentList.length;i++){
			var cX1 = 0;
			for(var j=0;j<gamehall_Data.agentList[i].length;j++){
				cX = cX1 + gamehall_Const.Location.spaceX * (j%4);
				cY = cY1 + gamehall_Const.Location.spaceY * Math.floor(j/4);
				var selectItem = ifast_addtospritefromspritecopy(gamehall_Const.Location.f_spid,
				gamehall_Const.Location.selectSpid,cX,cY,gamehall_Const.Location.selectTag+tag);
				
				var nameItem = ifast_addtospritefromspritecopy(gamehall_Const.Location.f_spid,
				gamehall_Const.Location.nameSpid,cX + gamehall_Const.Location.snSpace,
				cY + 10,gamehall_Const.Location.nameTag+tag);
				set_self(nameItem,7,gamehall_Data.agentList[i][j][0]);
				gamehall_Data.selectItemTagList.push([i,j]);
				gamehall_Data.selectItemSpList.push(selectItem);
				tag++;
				gamehall_Data.agentListLength++;
			}
			cY1 = cY + gamehall_Const.Location.spaceY ;
		}
		gamehall_GameUI.selectAgent(0);
		set_self(gamehall_Const.Location.f_spid,21,cY1,0,0);
	}
	
	
}
gamehall_GameUI.selectAgent = function(tag){
	gamehall_Data.selectTag = tag;	
	for(var i=0;i<gamehall_Data.selectItemSpList.length;i++){
		if(i == gamehall_Data.selectTag){
			set_self(gamehall_Data.selectItemSpList[i],43,2,0,0);
		}else{
			set_self(gamehall_Data.selectItemSpList[i],43,1,0,0);
		}
	}
	
	var tmp = gamehall_Data.agentList[gamehall_Data.selectItemTagList[gamehall_Data.selectTag][0]][gamehall_Data.selectItemTagList[gamehall_Data.selectTag][1]];	
	gamehall_Data.selectedAgent = gamehall_Logic.travelAgentConfig(gamehall_Data.gameHallConfig.agentConfig,"agentCode",tmp[1]);
}
//获取列表
/*
	[[[name,agentCode],....],....]

*/
gamehall_GameUI.getAgentList = function(config){
	var rValue = [];
	if(config){
		//第一层
		var rTemp = [];
		rTemp.push([config.name,config.agentCode]);
		rValue.push(rTemp);
		//第二层
		var rTemp1 = [];
		if(config.list){
			
			for(var i=0;i<config.list.length;i++){
				rTemp1 = [];
				//rTemp.push([config.list[i].name,config.list[i].agentCode]);
				rTemp1.push([config.list[i].name,config.list[i].agentCode]);
				//第三层
				if(config.list[i].list){
					for(var j=0;j<config.list[i].list.length;j++){
						//rTemp.push([config.list[i].list[j].name,config.list[i].list[j].agentCode]);
						rTemp1.push([config.list[i].list[j].name,config.list[i].list[j].agentCode]);
						//第四层
						if(config.list[i].list[j].list){
							for(var k=0;k<config.list[i].list[j].list.length;k++){
								//rTemp.push([config.list[i].list[j].list[k].name,config.list[i].list[j].list[k].agentCode]);
								rTemp1.push([config.list[i].list[j].list[k].name,config.list[i].list[j].list[k].agentCode]);
							}
						}
					}
				}
				rValue.push(rTemp1);
			}
		}
		//rValue.push(rTemp);	
	}
	
	return rValue;
} 
gamehall_GameUI.removeAgentList = function(){
	for(var i=0;i<gamehall_Data.agentListLength;i++){
		ifast_dllpritefromspritecopy(gamehall_Const.Location.f_spid,gamehall_Const.Location.selectTag + i);
		ifast_dllpritefromspritecopy(gamehall_Const.Location.f_spid,gamehall_Const.Location.nameTag + i);
		gamehall_Data.agentListLength = 0;
	}
}







