//各種処理設定
class MyProcessing{
	constructor(){
		//話す機能用
		this.talkStandby = false;
		this.talkLock = false;
		this.talkIndex = 1;
		//移動機能
		this.moveStandby = false;
		this.moveIndex = 0;
		this.movedata = [];
		this.getmoveData;
		//見る機能
		this.lockStandby = false;
		//音楽機能
		this.musData = [];
		this.musIndex = 0;
		this.musSEData = [];
		this.musSEIndex = 0;
		this.musSEBackIndex = false;
		this.musVoiceData = [];
		this.musVoiceIndex = 0;
		//保存データ
		this.saveFlg = false;
		this.ImageIndex = null;
		this.TalkNo = null;
		this.LoadFlg = false;
		this.LoadMusic = false;//RPGではmoveBefore音楽を鳴らしているためロード時に音楽再生しない
		this.musStatus = false;
		this.musSEStatus = false;
		this.musVoiceStatus = false;
		this.LoadIndex = 0;
		this.LoadIndexMax = 4;
		this.moveName = "";
		//経過日数
		this.Day = 1;
		//1日行動回数
		this.DayActCount = 5;
		//衣服状態
		this.backupWear = {};
		//野球拳用：絶対勝利フラグ
		this.victoryFlg = false;
		//脱衣チェック初期処理無効
		this.noneFlgInit = true;
		//タッチ・絶頂モード
		this.OrgasmModeFlg = false;
		this.TouchCount = 0;
		this.TouchCount2 = 0;
		//ステータス（RPG以外）
		this.StatusParam = {
			//ステータス名,最大値,初期値
			status1:["抵抗力",100,100],
			status2:["淫乱度",100,0],
			status3:["空腹度",100,0],
			status4:["性感度",100,0],
			//proc 0:加算,1:減算
			Proc:function(stsname,val,proc){
				if(proc==0){
					var Data = myProc.GetStatusData(stsname);
					Data[2] = Data[2]+val;
					if(Data[2]>=Data[1])Data[2] = Data[1];
				}else{
					var Data = myProc.GetStatusData(stsname);
					Data[2] = Data[2]-val;
					if(Data[2]<=0)Data[2] = 0;
				}
				return Data[2];
			},
			Initialize:function(Param){
				Param.Proc("抵抗力",100,0);
				Param.Proc("淫乱度",100,1);
				Param.Proc("空腹度",100,1);
				Param.Proc("性感度",100,1);
			},
			GetStatusData:function(stsname){
				for(var Param in myProc.StatusParam){
					var Data = myProc.StatusParam[Param];
					if(Data && typeof Data === 'function')continue;
					if(stsname == Data[0])return Data;
				}
			},
		}
		this.GetStatusData = this.StatusParam.GetStatusData;
		this.timer_id = 0;
	}
	
	//データ読み込み
	loadData(loadOnly=false){
		myDataCtrl.SetDataName(title_str);
		myDataCtrl.Load();		
		var sData = myDataCtrl.AppSaveData;
		if(sData==null){
			for(var loop=0;loop<myProc.LoadIndexMax;loop++){
				myDataCtrl.SetSaveData("moveIndex"+loop,myProc.moveIndex);
				myDataCtrl.SetSaveData("moveName"+loop,myProc.moveName);
				myDataCtrl.SetSaveData("EventFlg"+loop,myBE.Flg);
				myDataCtrl.SetSaveData("EventEndFlg"+loop,myBE.EndFlg);
				myDataCtrl.SetSaveData("ImageIndex"+loop,myImg.imgIndex);
				myDataCtrl.SetSaveData("TalkNo"+loop,myProc.TalkNo);
				myDataCtrl.SetSaveData("talkIndex"+loop,myProc.talkIndex);
				myDataCtrl.SetSaveData("LastEventNo"+loop,myBE.LastEventNo);
				myDataCtrl.SetSaveData("musIndex"+loop,myProc.musIndex);
				myDataCtrl.SetSaveData("musStatus"+loop,myProc.musStatus);
				myDataCtrl.SetSaveData("backCorrect"+loop,myImg.backCorrect);
				myDataCtrl.SetSaveData("RpgData"+loop,myRpg.Charctor);
				myDataCtrl.SetSaveData("Status"+loop,myProc.StatusParam);
				myDataCtrl.SetSaveData("backupWear"+loop,myProc.backupWear);
				myDataCtrl.SetSaveData("Moral"+loop,myST.Moral);
				myDataCtrl.SetSaveData("Day"+loop,myProc.Day);
				myDataCtrl.SetSaveData("DayActCount"+loop,myProc.DayActCount);
				myDataCtrl.SetSaveData("saveFlg"+loop,myProc.saveFlg);
			}
			myDataCtrl.Save();
			sData = myDataCtrl.AppSaveData;
		}else{
			if(loadOnly)return sData;
			//読込前初期化
			myBE.EndFlg.length = 0;
			myBE.eventList.length = 0;
			myProc.event(myST.GetEvent);			
			var idx = myProc.LoadIndex;
			if(sData["moveIndex"+idx]!=null){
				myProc.moveIndex = sData["moveIndex"+idx];
			}
			if((sData["moveName"+idx]!=null)&&(sData["moveName"+idx]!="")){
				myProc.moveName = sData["moveName"+idx];
			}			
			if(sData["EventFlg"+idx]!=null)myBE.Flg = sData["EventFlg"+idx];
			if(sData["EventEndFlg"+idx]!=null){
				myBE.EndFlg = sData["EventEndFlg"+idx];
				for(var loop in myBE.EndFlg){
					var event = myBE.getBaseEvent(loop);
					try{
						event[myBE.End] = myBE.EndFlg[loop];
					}catch(e){
						console.log(e);
					}
				}
			}
			if(sData["LastEventNo"+idx]!=null)myBE.LastEventNo = sData["LastEventNo"+idx];
			if(sData["TalkNo"+idx]!=null){
				myProc.TalkNo = sData["TalkNo"+idx];
				event = myBE.getBaseEvent(myBE.LastEventNo);
				event[myBE.Message] = myST.Talk[myProc.TalkNo];
				myProc.TalkNo = null;
			}
			if(sData["talkIndex"+idx]!=null){
				myProc.talkIndex = sData["talkIndex"+idx];
				myProc.talk();
			}
			if(sData["musIndex"+idx]!=null)myProc.musIndex = sData["musIndex"+idx];
			if(sData["musStatus"+idx]!=null){
				myProc.musStatus = sData["musStatus"+idx];
				if(myProc.LoadMusic)myProc.music(myProc.musIndex,!myProc.musStatus);
			}
			if(sData["backCorrect"+idx]!=null)myImg.backCorrect = sData["backCorrect"+idx];
			if(sData["RpgData"+idx]!=null)myRpg.Charctor = sData["RpgData"+idx];
			if(sData["Status"+idx]!=null){
				var data = sData["Status"+idx];
				for(var loop in data){
					myProc.StatusParam[loop] = data[loop];
				}
			}else{
				myProc.StatusParam.Initialize(myProc.StatusParam);			
			}
			if((myRpg.Charctor.INRAN===undefined)||(myRpg.Charctor.INRAN==null))myRpg.Charctor.INRAN = 0;
			if(sData["backupWear"+idx]!=null){
				myProc.backupWear = sData["backupWear"+idx];
				var flg = false;
				for(var loop in myProc.backupWear){
					if(loop=="kutu"){
						myProc.backupWear["inner"] = myProc.backupWear["kutu"];
						delete myProc.backupWear.kutu;
						flg = true;
					}
				}
				if(!flg){
					myProc.backupWear["inner"] = 1;
				}
				
			}
			//モラルデータ
			if(sData["Moral"+idx]!=null)myST.Moral = sData["Moral"+idx];
			if(sData["Day"+idx]!=null)myProc.Day = sData["Day"+idx];
			if(sData["DayActCount"+idx]!=null)myProc.DayActCount = sData["DayActCount"+idx];
			//画像表示は最後
			if(sData["ImageIndex"+idx]!=null){
				myImg.imgIndex = sData["ImageIndex"+idx];
				if(myImg.imgIndex.Other==1)myImg.imgIndex.Other = 0;
				var data = myProc.getmoveData(myProc.moveIndex);
				myImg.SetImgPos("back",[data[2].x,data[2].y]);
				myImg.AllImageView(true,false,false);
			}			
			_self.HiddenBox("anmaku");
			this.LoadFlg = true;
		}
		return sData;
	}
	deleteData(){
		myDataCtrl.Load();
		var sData = myDataCtrl.AppSaveData;
		var idx = myProc.LoadIndex;
		//初期化
		myDataCtrl.SetSaveData("moveIndex"+idx,myProc.moveIndex);
		myDataCtrl.SetSaveData("moveName"+idx,myProc.moveName);
		myDataCtrl.SetSaveData("EventFlg"+idx,myBE.Flg);
		myDataCtrl.SetSaveData("EventEndFlg"+idx,myBE.EndFlg);
		myDataCtrl.SetSaveData("ImageIndex"+idx,myImg.imgIndex);
		myDataCtrl.SetSaveData("TalkNo"+idx,myProc.TalkNo);
		myDataCtrl.SetSaveData("talkIndex"+idx,myProc.talkIndex);
		myDataCtrl.SetSaveData("LastEventNo"+idx,myBE.LastEventNo);
		myDataCtrl.SetSaveData("musIndex"+idx,myProc.musIndex);
		myDataCtrl.SetSaveData("musStatus"+idx,myProc.musStatus);
		myDataCtrl.SetSaveData("RpgData"+idx,myRpg.Charctor);
		myDataCtrl.SetSaveData("Status"+idx,myProc.StatusParam);		
		myDataCtrl.SetSaveData("backupWear"+idx,myProc.backupWear);
		myDataCtrl.SetSaveData("Moral"+idx,myST.Moral);
		myDataCtrl.SetSaveData("Day"+idx,myProc.Day);
		myDataCtrl.SetSaveData("DayActCount"+idx,myProc.DayActCount);
		myDataCtrl.SetSaveData("backCorrect"+idx,myImg.backCorrect);		
		sData["saveFlg"+idx] = false;
		myDataCtrl.Save();
	}
	//データ保存
	saveData(){
		var idx = myProc.LoadIndex;
		myDataCtrl.SetSaveData("moveIndex"+idx,myProc.moveIndex);
		myDataCtrl.SetSaveData("moveName"+idx,myProc.moveName);
		myDataCtrl.SetSaveData("EventFlg"+idx,myBE.Flg);
		myDataCtrl.SetSaveData("EventEndFlg"+idx,myBE.EndFlg);
		myDataCtrl.SetSaveData("ImageIndex"+idx,myImg.imgIndex);
		myDataCtrl.SetSaveData("TalkNo"+idx,myBE.TalkNo);
		myDataCtrl.SetSaveData("talkIndex"+idx,myProc.talkIndex);
		myDataCtrl.SetSaveData("LastEventNo"+idx,myBE.LastEventNo);
		myDataCtrl.SetSaveData("musIndex"+idx,myProc.musIndex);
		myDataCtrl.SetSaveData("musStatus"+idx,myProc.musStatus);
		myDataCtrl.SetSaveData("backCorrect"+idx,myImg.backCorrect);
		myDataCtrl.SetSaveData("RpgData"+idx,myRpg.Charctor);
		myDataCtrl.SetSaveData("Status"+idx,myProc.StatusParam);		
		myDataCtrl.SetSaveData("backupWear"+idx,myProc.backupWear);
		myDataCtrl.SetSaveData("Moral"+idx,myST.Moral);
		myDataCtrl.SetSaveData("Day"+idx,myProc.Day);
		myDataCtrl.SetSaveData("DayActCount"+idx,myProc.DayActCount);
		myDataCtrl.SetSaveData("saveFlg"+idx,true);
		myDataCtrl.Save();
	}
	
	//初期立ち絵設定
	SetCharctorWear(index){
		var Img = myST.Img[index];
		for(var loop in Img){
			//画像が衣服かチェック
			var WearJuge = ["seihuku","shatu","sukart","inner","burager","panty"];				
			for(var loop2 in WearJuge){
				//対象の画像が衣服なら
				if(WearJuge[loop2]==loop){
					//設定
					myImg.SetIndexPos(loop,Img[loop]);
				}
			}
		}
	}
	//初期処理用
	Initialize(){
		myProc.move();
		myProc.Status();
		myProc.NextDay();
		myProc.lock();
		myProc.sex();
		myProc.talk();
		myProc.OrgasmModeChange();
		myProc.Onani();
		myProc.Eat();
		myProc.makuru();
		myProc.waer();
		myProc.under();
		myProc.Kigaeru();		
		myProc.nugasu();
		myProc.Nugu();
		myProc.sounyuu();
		myProc.shasei();
		myProc.boxnone();
		myProc.Test();
		myProc.Option();
		myProc.janken();
		myProc.Lock2();
	}
	
	//話す
	talk(func = null){
		//会話機能の準備が終わっているか？
		if(!myProc.talkStandby){//終わっていないなら初期動作
			//各種機能
			this.talkData = null;
			this.talkList = null;
			this.talkFunc = null;
			this.talkExcute = null;
			this.talkDefaultFunc = null;
			this.talkStandbyFunc = null;			
			//話す処理準備
			myProc.talkStandbyFunc = function(){
				//会話内容
				this.talkData = function(){
					this.talkList = function(Index = -1){
						var data = myST.Talk;
						return Index!=-1?data[Index]:data.length;
					}
					return this.talkList();
				}
				//会話実行
				this.talkExcute = function(msg){
					var nMsg = [];
					for(var loop in msg){
						nMsg.push(msg[loop]);
					}
					myBT.setMessage(nMsg);
					return;
				}
				//初期処理
				this.talkDefaultFunc = function(){
					var index = 0;
					//人がいるなら
					if(myImg.GetIndexPos("body")!=0){
						//処理ごとにインデックスは別のところで設定する。
						index = myProc.talkIndex;
					}
					myProc.talkExcute(myProc.talkList(index));
				}		
				myProc.talkStandby = this.talkData();			
			}
			myProc.talkStandbyFunc();
			_self.setTimer(this.talk,100,func);
			return;
		}
		//特別な処理がないならデフォルト処理
		if(func == null)func = myProc.talkDefaultFunc;
		myBT.setCommandProcessing(myBT.CommandTalk,function(){
			myBT.messageCount = 0;
			var msgIndex = Math.floor(Math.random()*3);
			var shatuval = myImg.GetIndexPos("shatu");
			//抵抗力
			var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
			if(JudgeValue>85){
				msgIndex+=0;
			}else if(JudgeValue>70){
				msgIndex = Math.floor(Math.random()*2);
				msgIndex+=3;
				if((msgIndex==4)&&(shatuval==1))msgIndex = 3;
			}else if(JudgeValue>55){
				msgIndex = Math.floor(Math.random()*2);
				msgIndex+=5;
				if((msgIndex==6)&&(shatuval==2))msgIndex = 5;
			}else if(JudgeValue<=55){
				msgIndex = Math.floor(Math.random()*2);
				msgIndex+=7;
				var JudgeValue2 = (myProc.GetStatusData("淫乱度"))[2];
				if(JudgeValue2>=30){
					msgIndex+=2;
				}else if(JudgeValue2>=60){
					msgIndex+=4;
				}else if(JudgeValue2>=80){
					msgIndex+=6;
				}
			}			
			myProc.talkExcute(myProc.talkList(msgIndex));
		});
	}
	
	//イベント設定
	event(func=null){
		if(func==null)return;
		var setEv = null;
		setEv = func();
		for(var loop in setEv){
			myBE.addBaseEvent(setEv[loop]());
		}
	}
	
	//シナリオ抽出
	OutPutFlg = false;
	MsgData = "";
	OutPutSinario(){
		//シナリオ抽出フラグがOFFなら抜ける
		if(!myProc.OutPutFlg)return;
		//シナリオデータ連結
		var talkData = myST.Story;
		talkData = talkData.concat(myST.Talk);
		talkData = talkData.concat(myST.EventData);
		talkData = talkData.concat(myST.TouchMsgData[0]);
		talkData = talkData.concat(myST.TouchMsgData[1]);
		//抽出
		for(var idx in talkData){
			if(isNaN(parseInt(idx)))continue;
			var length = talkData[idx].length;
			for(var idx2=0;idx2<length;idx2++){
				if(talkData[idx][idx2][0]=="FUNC"){
					talkData[idx][idx2][1]();
				}else if(Array.isArray(talkData[idx][idx2])){
					myBT.showMessage(talkData[idx][idx2][0]);
				}else{
					myBT.showMessage(talkData[idx][idx2]);
				}
			}
			myProc.MsgData+="\n";
		}
		//体タッチメッセージ抽出
		talkData = myST.TouchData[myST.TouchData.length-2]();
		for(var loop = 0;loop<4;loop++){
			var length = talkData.length;
			for(var idx=0;idx<length;idx++){
				myST.JudgValue = 0;
				if(loop==1)myST.JudgValue = 20;
				if(loop==2)myST.JudgValue = 40;
				if(loop==3)myST.JudgValue = 80;
				if(talkData[idx][0]=="FUNC"){
					talkData[idx][1]();
				}else if(Array.isArray(talkData[idx])){
					myBT.showMessage(talkData[idx][0]);
				}else{
					myBT.showMessage(talkData[idx]);
				}
			}
			myProc.MsgData+="\n";
		}
		//挿入メッセージ抽出
		talkData = myST.SounyuuMag;
		for(var loop = 0;loop<4;loop++){
			var length = talkData.length;
			for(var idx=0;idx<length;idx++){
				myST.JudgValue = 0;
				if(loop==1)myST.JudgValue = 20;
				if(loop==2)myST.JudgValue = 40;
				if(loop==3)myST.JudgValue = 80;
				if(talkData[idx][0]=="FUNC"){
					talkData[idx][1]();
				}else if(Array.isArray(talkData[idx])){
					myBT.showMessage(talkData[idx][0]);
				}else{
					myBT.showMessage(talkData[idx]);
				}
			}
			myProc.MsgData+="\n";
		}		
		myProc.MsgData+="\n";
		console.log(myProc.MsgData);
		myProc.OutPutFlg = false;
		myBT.showMessage("");
	}
	
	//衣服状態チェック
	WearBreakcheck(parts){
		if(!myRpg.FunctionFlg)return true;
		var Chr = myRpg.Charctor;
		var BrackIdx = 0;
		
		//破損なし
		if(Chr.WP>=95){
			BrackIdx = 0;
		}
		//破損なし
		else if(Chr.WP>=90){
			BrackIdx = 1;		
		}
		//破損なし
		else if(Chr.WP>=80){
			BrackIdx = 2;
		}
		//破損なし
		else if(Chr.WP>=70){
			BrackIdx = 3;
		}
		//破損なし
		else if(Chr.WP>=60){
			BrackIdx = 4;
		}
		//破損なし
		else if(Chr.WP>=50){
			BrackIdx = 5;
		}
		//破損なし
		else if(Chr.WP>=40){
			BrackIdx = 6;
		}
		//破損なし
		else if(Chr.WP>=30){
			BrackIdx = 7;
		}
		else if(Chr.WP>=20){
			BrackIdx = 8;
		}
		//破損なし
		else if(Chr.WP>=10){
			BrackIdx = 9;
		}
		//破損なし
		else if(Chr.WP>=5){
			BrackIdx = 10;
		}
		//破損なし
		else if(Chr.WP>=0){
			BrackIdx = 11;
		}
		
		if(myST.Img[BrackIdx][parts]!=0){
			myProc.backupWear[parts] = myST.Img[0][parts];
			return true;
		}else{
			return false;
		}
		
	}
	//画像Noからイメージ取得
	searchImageNo(index){
		for(var loop in myST.Img){
			if(myST.Img[loop].No==index)return myST.Img[loop];
		}
	}
	//画像変更
	changeImage(index,move=false,anten=true,bgImage=true){
		var Img = myProc.searchImageNo(index);
		console.log(Img);
		if(move)Img['back'] = move;
		var key = "";
		myProc.talkLock = true;
		myProc.ImageIndex = index;
		if(anten)_self.ViewBox("anmaku");
		//暗転待ち
		_self.setTimer(function(){
			for(var loop in Img){
				key = loop;
				if((!bgImage)&&(key=="back")||(key=="No"))continue;
				//脱衣状態チェック
				var noneFlg = myImg.GetIndexPos(key);
				if(myProc.noneFlgInit){
					noneFlg = true;
				}
				var noneJuge = ["seihuku","shatu","sukart","inner","burager","panty"];				
				//画像設定
				myImg.SetIndexPos(key,Img[loop]);
				if(key=="back"){
					var data = myProc.getmoveData(Img[loop]);
					var setTemp = [data[2].x,data[2].y];
					myImg.SetImgPos(key,setTemp);
				}
				//脱衣状態チェック処理
				for(var loop2 in noneJuge){
					//対象の画像が衣服なら
					if(noneJuge[loop2]==key){
						//来ている状態かチェックして設定する。
						if(!noneFlg)myImg.SetIndexPos(key,0);
					}
				}
				if(anten)myImg.ClearImage(key);
			}
			myProc.noneFlgInit = false;
			//着衣状態で表情と体を変更する。
			if(!myRpg.BindStatus){
				var inner = myImg.GetIndexPos("inner");
				var seihuku = myImg.GetIndexPos("seihuku");
				var shatu = myImg.GetIndexPos("shatu");
				var sukart = myImg.GetIndexPos("sukart");
				var panty = myImg.GetIndexPos("panty");
				var burager = myImg.GetIndexPos("burager");
				//下着脱いでいる場合は赤らめる
				if(!(panty&&burager)||(!sukart)||(!shatu)){
					myImg.SetIndexPos("body_face_bk",1);
					myImg.SetIndexPos("body_face_fk",9);
				}
				//上半身裸で胸隠す
				if(!(burager||shatu||sukart||seihuku)){
					myImg.SetIndexPos("body",2);				
				}
				//全裸なら体を隠す
				if(!(burager||shatu||sukart||seihuku||panty||inner)){
					myImg.SetIndexPos("body",3);				
				}
			}
			//画像描画
			myImg.AllImageView(true,false,false);
			//描画200msec待ち後暗転解除
			_self.setTimer(function(){				
				if(anten)_self.HiddenBox("anmaku")
				myProc.talkLock = false;
			},200);
		},510);
	}
	
	//衣服状態取得(村、街用)
	getInranWear(){
		var inner = myImg.GetIndexPos("inner");
		var seihuku = myImg.GetIndexPos("seihuku");
		var shatu = myImg.GetIndexPos("shatu");
		var sukart = myImg.GetIndexPos("sukart");
		var panty = myImg.GetIndexPos("panty");
		var burager = myImg.GetIndexPos("burager");
		var res = false;
		
		//スカート脱いでいる
		if(!sukart)res = true;
		if(!(seihuku||shatu||burager))res = true;
		
		return res;
	}
	
	//移動
	move(startFlg=false){
		if(!myProc.moveStandby){
			//
			myProc.movedata = [
				[//インデックス:場所の名前
					[0,"地下室"],
					function(index,get=false){
						var tmp = myProc.movedata[0];
						for(var loop in tmp){
							if(tmp[loop] && typeof tmp[loop] === 'function')return;
							if(tmp[loop][0] == index){
								if(get)return tmp[loop];
								return tmp[loop][1]; 
							}
						}
					}
				],
				//現在の場所,[行先],{背景の表示位置}
				[0,[0,0],{x:0,y:0}],//背景なし
				[1,[0,0],{x:-50,y:0}],//カラオケ
			];
			//移動データ取得関数
			myProc.GetmoveDataFunc = function(){
				return myProc.movedata[0][myProc.movedata[0].length-1];
			}
			//移動先強制設定
			myProc.moveSet = function(posKey){
				var idx = 0;
				var IndexPos = myProc.movedata[0];
				for(var loop in IndexPos){
					var posStr = IndexPos[loop][1];
					if(posStr == posKey){
						idx = IndexPos[loop][0];
						break;
					}
				}
				myProc.moveIndex = idx;
			}
			//移動先データ取得
			myProc.getmoveData = function(idx){
				var data = myProc.movedata;
				if(typeof idx==='object')idx = idx.back;
				for(var loop in data){
					if(loop==0)continue;
					if(data[loop][0]==idx){
						return data[loop];
					}
				}
			}
			if(myProc.moveName!=""){
				var func = myProc.GetmoveDataFunc();
				var Data = func(myProc.moveIndex,true);
				Data[1] = myProc.moveName;
			}
			if(startFlg)return;
			myProc.moveStandby = true;
		}
		//移動前処理
		myProc.moveBefore = function(value){
			return false;
		}
		//移動メニュー
		myBT.setCommandProcessing(myBT.CommandMove,function(){
			var index = 0;
			var movedata = [];
			var temp = myProc.movedata;
			for(var loop in temp){
				if(myProc.moveIndex == temp[loop][0]){
					var temp2 = temp[loop][1];
					for(var loop2 in temp2){
						var index2 = temp2[loop2];
						var f_idx = myProc.movedata[0].length-1;
						var func = myProc.movedata[0][f_idx];
						movedata[index] = [];
						movedata[index][0] = index2;
						movedata[index][1] = func(index2);
						movedata[index][2] = function(idx){
							var moveData = {back:idx}
							if(!myProc.moveBefore(idx))return;
							myProc.moveIndex = idx;
							//背景の表示位置
							var data = myProc.getmoveData(idx);
							var setTemp = [data[2].x,data[2].y];
							myImg.SetImgPos("back",setTemp);							
							//背景表示
							myST.CheageImage("back",moveData);
							var funcIdx = myBE.serchExecuteEvent();
							if(funcIdx)myBE.excuteEvent(funcIdx);
							MySetting.LockCount = 0;
							//移動先名保存
							var func = myProc.GetmoveDataFunc();
							var Data = func(myProc.moveIndex,true);							
							myProc.moveName = Data[1];
						}
						index++;
					}
				}
			}
			var parent = _self.Elm("operation",_self.TypeID);
			myBT.moveMenu(parent,movedata);
		});
	}
	
	//ステータス
	Status(){
		if(myRpg.FunctionFlg)return;
		myProc.StatusMenu = "statusMenu";		
		myBT.setCommandProcessing(myBT.CommandStatus,function(){
			//通常メニュー非表示
			myBT.MenuHidden();
			var MenuItemMax = 5;
			var MenuItemIndex = 0;
			var MenuStatusPage = 0;
			var ClickFlg = true;
			//初回メニュー生成
			var StatusMenu = _self.Elm(myProc.StatusMenu,_self.TypeID);
			if((StatusMenu == undefined)||(StatusMenu == null)){
				//メニュー枠生成
				var parent = _self.Elm("operation",_self.TypeID);
				myBT.setCommonBox(parent,myProc.StatusMenu,"10px");
				_self.Elm(myProc.StatusMenu,_self.TypeID).style.width = "200px";
			}else{
				_self.ViewBox(myProc.StatusMenu);
			}
			_self.Elm(myProc.StatusMenu,_self.TypeID).innerText = "";
			for(var Param in myProc.StatusParam){
				var Data = myProc.StatusParam[Param];
				if (Data && typeof Data === 'function')continue;
				_self.Elm(myProc.StatusMenu,_self.TypeID).innerText += Data[0]+":"+Data[2]+"/"+Data[1]+"\n";
			}
			_self.Elm(myProc.StatusMenu,_self.TypeID).innerText += "※画面タッチで終了\n";			
			_self.doc.onmousedown = function(){
				if(ClickFlg){
					ClickFlg = false;
					return;
				}
				_self.HiddenBox(myProc.StatusMenu);
			}			
		});
	}
	
	//時間経過（翌日）
	NextDay(){
		myBT.setCommandProcessing(myBT.CommandNextDay,function(){
			myST.AntenImageView(function(){
				myProc.Day++;
				myProc.DayActCount = 5;
				myST.PantyWeatCount = 0;
				var Hunger = myProc.StatusParam.Proc("空腹度",20,0);
				var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
				var Msg = "女子校生はこちらを睨みつけている。";
				var MsgAddFlg = false;
				var evenIdx = 0;
				if(Hunger>=1 && Hunger<=30){
					Msg = "多少の空腹はあるのか、お腹の音が可愛く泣いている。";
				}else if(Hunger<=60){
					Msg = "さすが空腹が堪えるのか、元気がないようだ。";
				}else　if(Hunger<100){
					Msg = "空腹が限界なのか何かを懇願するようにこちらを見ている。";
				}else if(Hunger==100){
					MsgAddFlg = true;
					if(JudgeValue>85){
						evenIdx = 14;
					}else if(JudgeValue>70){
						evenIdx = 15;
					}else if(JudgeValue<70){
						evenIdx = 16;
					}
				}
				var msgList = [
					["FUNC",function(){
						_self.HiddenBox("menu1");
						myBT.showMessage("時間経過。<br>行動回数5回に回復。<br>");
					}],
					myProc.Day+"日目―<br>空腹度:"+Hunger+"%<br>"+Msg,
				];				
				if(MsgAddFlg){
					msgList = msgList.concat(myST.EventData[evenIdx]);
				}else{
					msgList[msgList.length] = [
						"FUNC",function(){
							myBT.showMessage("");
							_self.ViewBox("menu1");
						}
					];
				}
				//パンティ
				var pantyIdx = myImg.GetIndexPos("panty");
				if(pantyIdx!=0)myImg.SetIndexPos("panty",1);
				//汁
				myImg.SetIndexPos("siru",0);
				myImg.AllImageView();
				myBT.setMessage(msgList);
				//自動セーブ
				var backIndex = myProc.LoadIndex;
				myProc.LoadIndex = 3;
				myProc.saveData();
				myProc.LoadIndex = 	backIndex;			
				myBT.chgDayTime();
			});
		});
	}
	
	//見る
	lock(){
		myBT.setCommandProcessing(myBT.CommandLock,function(){
			//見る機能準備
			var fcLock = myST.Lock;
			for(var loop in fcLock){
				fcLock[loop]();
			}
		});
	}
	
	//押し倒す
	sex(){
		myBT.setCommandProcessing(myBT.CommandSex,function(){
			if(myST.SexFunc!=0x11)return;
			//立ち絵変更
			myST.Sex();
		});
		myST.SexFunc = false;
		if(myST.SexFunc==false)return;
		if(_self.product_flg)myST.SexFunc |= 0x10;
		if(_self.sample2_flg)myST.SexFunc |= 0x10;
		if(myBE.EndFlg[22]||myBE.EndFlg[23])myST.SexFunc |= 0x01;
		if(myST.SexFunc==0x11)_self.ViewBox(myBT.CommandSex);
	}
	
	//オナニー
	Onani(){
		myBT.setCommandProcessing(myBT.CommandOnani,function(){
			if(myRpg.Charctor.INRAN>=40){
				myRpg.OnaniFlg = true;
				myBE.excuteEvent(22);
			}else{
				myBT.setMessage(["淫乱度が40以上でオナニーが出来るようになります。"]);
			}
		});		
	}
	
	//タッチ・絶頂モード切替
	OrgasmModeChange(){
		myBT.setCommandProcessing(myBT.CommandOrgasm,function(){
			var elm = _self.Elm("OrgasmMode",_self.TypeID);
			if(!myProc.OrgasmModeFlg){
				elm.innerText = "絶頂モード";
				myProc.OrgasmModeFlg = true;
				myProc.TouchCount = 0;
				myProc.TouchCount2 = 0;
				myST.TouchData[myST.TouchData.length-1]();
				myProc.Voice(0,myST.BGM_ALLOFF);
				myBT.messageCount = 99;//現在のイベント終了
				myBT.showMessage("");
			}else{
				elm.innerText = "タッチモード";
				myProc.OrgasmModeFlg = false;
				myProc.Voice(0,myST.BGM_ALLOFF);
				_self.ViewBox("menu1");
			}
		});
	}
	
	//食事
	Eat(){
		myBT.setCommandProcessing(myBT.CommandEat,function(){
			var Hunger = (myProc.GetStatusData("空腹度"))[2];
			var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
			var evenIdx = 0;
			if(JudgeValue>85){
				evenIdx = 10;
			}else if(JudgeValue>70){
				evenIdx = 11;
			}else if(JudgeValue>55){
				evenIdx = 12;
			}else if(JudgeValue<=55){
				evenIdx = 13;
			}
			if(Hunger==0)evenIdx = 17;
			myBT.setMessage(myST.EventData[evenIdx]);
		});
	}
	
	//捲る
	makuru(){
		//捲るコマンド文字列変更
		myProc.ChangeMakuruName = function(){
			//シャツ
			var idx = myImg.GetIndexPos("shatu");
			if((idx == 3)||(idx == 4)){
				_self.Elm(myBT.CommandMakuruW,_self.TypeID).innerText = "シャツを捲る";
			}else if(idx != 0){
				var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
				if(JudgeValue>70){
					_self.Elm(myBT.CommandMakuruW,_self.TypeID).innerText = "シャツを捲る";
				}else{
					_self.Elm(myBT.CommandMakuruW,_self.TypeID).innerText = "シャツを戻す";
				}
			}
			//スカート			
			var idx = myImg.GetIndexPos("sukart");
			if(idx == 1){
				_self.Elm(myBT.CommandMakuruU,_self.TypeID).innerText = "スカートを捲る";
			}else if(idx != 0){
				_self.Elm(myBT.CommandMakuruU,_self.TypeID).innerText = "スカートを戻す";
			}
		}
		//捲るーコマンド
		myBT.setCommandProcessing(myBT.CommandMakuru,function(){
			myBT.MenuMakuru();
			myProc.ChangeMakuruName();
		});
		//シャツを捲るーコマンド
		myBT.setCommandProcessing(myBT.CommandMakuruW,function(){
			var idx = myImg.GetIndexPos("shatu");
			if((idx == 3)||(idx == 4)){
				myST.CheageImage("shatu",idx+5);
				var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
				var evenIdx = -1;
				if(JudgeValue>55){
					evenIdx = 8;
				}else if(JudgeValue<=55){
					evenIdx = 9;
				}
				//シャツのボタンを外してなければメッセージなし
				myBT.setMessage(myST.EventData[evenIdx]);
			}else if((idx == 8)||(idx == 9)){
				myST.CheageImage("shatu",idx-5);
				myBT.showMessage("女子校生<br>「...」");
			}else if(idx!=0){
				myBT.showMessage("せめてシャツのボタンを外さないとな。");
			}else{
				myBT.showMessage("シャツは脱がしてるな。");
			}
			myProc.ChangeMakuruName();			
		});
		//スカートを捲るーコマンド
		myBT.setCommandProcessing(myBT.CommandMakuruU,function(){
			var idx = myImg.GetIndexPos("sukart");
			if(idx == 1){
				myST.CheageImage("sukart",idx+1);
				var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
				var evenIdx = 0;
				if(JudgeValue>85){
					evenIdx = 4;
				}else if(JudgeValue>70){
					evenIdx = 5;
				}else if(JudgeValue>55){
					evenIdx = 6;
				}else if(JudgeValue<=55){
					evenIdx = 7;
				}
				myBT.setMessage(myST.EventData[evenIdx]);
			}else if(idx!=0){
				myST.CheageImage("sukart",idx-1);
				myBT.showMessage("女子校生<br>「...」");
			}else{
				myBT.showMessage("スカートは脱がしてるな。");
			}
			myProc.ChangeMakuruName();
		});
		//捲るコマンドから戻る
		myBT.setCommandProcessing(myBT.CommandMakuruR,function(){
			myBT.MenuHidden();
			myBT.MenuView();
			_self.ViewBox(myBT.Menu);
		});
	}
	
	//上着を脱がす
	waer(){
		myBT.setCommandProcessing(myBT.CommandWaer,function(){
			myST.WearUnder("wear");
		});
	}	
	
	//スカート/下着を脱がす
	under(){
		myBT.setCommandProcessing(myBT.CommandUnder,function(){
			myST.WearUnder("under");
		});
	}
	//着替える
	Kigaeru(){
		//脱衣メニュー表示
		myBT.setCommandProcessing(myBT.CommandKigaeru,function(){
			myBT.MenuKigae();
			//着替え1・ネグリジェ
			myBT.setCommandProcessing(myBT.CommandKigae1,function(){
				//衣服変更
				if(myImg.GetIndexPos("shatu")!=imgNegurije){
					//ネグリジェに着替える/ブラとパンティは消す。
					myProc.WearBackUp();//衣服状態のバックアップ		
					myST.AntenImageView(function(){
						myProc.changeImage(12,myProc.moveIndex,false);
					},510,1000)
					this.innerText = "魔導士の服";
				}else{
					//制服に着替える/ブラとパンティは戻す。
					/*myST.AntenImageView(function(){
						myST.CheageImage("seihuku",myProc.backupWear["seihuku"]);
						myST.CheageImage("shatu",myProc.backupWear["shatu"]);
						myST.CheageImage("sukart",myProc.backupWear["sukart"]);
						myST.CheageImage("kutu",myProc.backupWear["kutu"]);
						myST.CheageImage("inner",myProc.backupWear["inner"]);
						myST.CheageImage("burager",myProc.backupWear["burager"]);
						myST.CheageImage("panty",myProc.backupWear["panty"]);
						myRpg.WearBreak(myRpg.Charctor);
					},510,1000);*/
					myBE.excuteEvent(13);
					this.innerText = "ネグリジェ";
				}
			});
			//戻る
			myBT.setCommandProcessing(myBT.CommandMenuReturn,function(){
				myBT.MenuHidden();
				_self.ViewBox(myBT.Menu);		
				myBT.MenuView();
			});
		});
	}
	
	//脱衣機能ー自分で脱ぐ方
	Nugu(){
		//衣服状態のバックアップ
		myProc.WearBackUp = function(){
			var WUValue = 0;
			//下記すべて身に着けている状態を保持
			WUValue = myImg.GetIndexPos("seihuku");
			if(WUValue)myProc.backupWear["seihuku"] = myImg.GetIndexPos("seihuku");
			WUValue = myImg.GetIndexPos("shatu");
			if(WUValue)myProc.backupWear["shatu"] = myImg.GetIndexPos("shatu");
			WUValue = myImg.GetIndexPos("sukart");
			if(WUValue)myProc.backupWear["sukart"] = myImg.GetIndexPos("sukart");
			WUValue = myImg.GetIndexPos("inner");
			if(WUValue)myProc.backupWear["inner"] = myImg.GetIndexPos("inner");
			WUValue = myImg.GetIndexPos("burager");
			if(WUValue)myProc.backupWear["burager"] = myImg.GetIndexPos("burager");
			WUValue = myImg.GetIndexPos("panty");
			if(WUValue)myProc.backupWear["panty"] = myImg.GetIndexPos("panty");			
		}
		//脱衣メニュー表示
		myBT.setCommandProcessing(myBT.CommandNugu,function(){
			myBT.MenuNugu();
			myProc.WearBackUp();//衣服状態のバックアップ
			//ローブ/カーディガン
			myBT.setCommandProcessing(myBT.CommandWaer,function(){
				var tmp = myImg.GetIndexPos("seihuku");
				if(!tmp){
					if(myProc.WearBreakcheck("seihuku")){
						if(myProc.backupWear.seihuku===undefined)myProc.backupWear["seihuku"] = 1;
						myST.CheageImage("seihuku",myProc.backupWear["seihuku"]);
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					myST.CheageImage("seihuku",0);
				}
				myProc.WearUnderMsg(tmp);
			});
			//ブラウス
			myBT.setCommandProcessing(myBT.CommandWaer2,function(){
				var tmp = myImg.GetIndexPos("shatu");
				if(!tmp){
					if(myProc.WearBreakcheck("shatu")){
						//myST.CheageImage("shatu",myProc.backupWear["shatu"]);
						var shatuIndex = 3;
						if(myImg.GetIndexPos("burager")==0){
							shatuIndex = 4;
						}
						myST.CheageImage("shatu",shatuIndex);
						myBT.showMessage("女子校生<br>「...何がしたいの？」");
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("shatu",0);
					var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
					if(JudgeValue>85){
						myBT.setMessage(myST.EventData[0]);
					}else if(JudgeValue>70){
						myST.CheageImage("shatu",2);
						myBT.setMessage(myST.EventData[1]);
					}else if(JudgeValue>55){
						myST.CheageImage("shatu",3);
						myBT.setMessage(myST.EventData[2]);
					}else if(JudgeValue<=55){
						myST.CheageImage("shatu",0);
						myBT.setMessage(myST.EventData[3]);
					}
				}
				//myProc.WearUnderMsg(tmp);
			});
			//スカート
			myBT.setCommandProcessing(myBT.CommandWaer3,function(){
				var tmp = myImg.GetIndexPos("sukart");
				if(!tmp){
					if(myProc.WearBreakcheck("sukart")){
						myST.CheageImage("sukart",myProc.backupWear["sukart"]);
						myBT.showMessage("女子校生<br>「...何がしたいの？」");
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("sukart",0);
					var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
					if(JudgeValue>55){
						myBT.setMessage(myST.EventData[0]);
					}else if(JudgeValue<=55){
						myST.CheageImage("sukart",0);
						myBT.setMessage(myST.EventData[3]);
					}
				}
				//myProc.WearUnderMsg(tmp);
			});
			//タイツ
			myBT.setCommandProcessing(myBT.CommandWaer4,function(){
				var tmp = myImg.GetIndexPos("inner");
				if(!tmp){
					if(myProc.WearBreakcheck("inner")){
						myST.CheageImage("inner",myProc.backupWear["inner"]);
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("inner",0);
					myBT.setMessage(myST.EventData[0]);
				}
				//myProc.WearUnderMsg(tmp);
			});
			//ブラ
			myBT.setCommandProcessing(myBT.CommandUnder,function(){
				//体験版
				if((!_self.product_flg)&&(!_self.sample2_flg)){
					myBT.showMessage("体験版では脱がせません。");
					return;
				}
				var tmp = myImg.GetIndexPos("burager");
				if(!tmp){
					if(myProc.WearBreakcheck("burager")){
						myST.CheageImage("burager",myProc.backupWear["burager"]);
						myST.CheageImage("body",1);
						if(myImg.GetIndexPos("shatu")!=0){
							myST.CheageImage("shatu",3);						
						}
						myBT.showMessage("女子校生<br>「...何がしたいの？」");						
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("burager",0);
					var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
					if(JudgeValue>40){
						myBT.setMessage(myST.EventData[0]);
					}else if(JudgeValue<=40){
						myST.CheageImage("burager",0);
						myST.CheageImage("body",2);
						if(myImg.GetIndexPos("shatu")!=0){
							myST.CheageImage("shatu",4);						
						}						
						myBT.setMessage(myST.EventData[3]);
					}
				}
				//myProc.WearUnderMsg(tmp);
			});
			//パンティ
			myBT.setCommandProcessing(myBT.CommandUnder2,function(){
				//体験版
				var tmp = myImg.GetIndexPos("panty");
				if((!_self.product_flg)||(_self.sample2_flg)){
					if(!_self.sample2_flg)myBT.showMessage("体験版では脱がせません。");
					if(_self.sample2_flg)myBT.showMessage("限定体験版でも脱がせません。");
					return;
				}				
				if(!tmp){
					if(myProc.WearBreakcheck("panty")){
						myST.CheageImage("panty",myProc.backupWear["panty"]);
						myBT.showMessage("女子校生<br>「...何がしたいの？」");
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("panty",0);
					var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
					if(JudgeValue>40){
						myBT.setMessage(myST.EventData[0]);
					}else if(JudgeValue<=40){
						myST.CheageImage("panty",0);
						myBT.setMessage(myST.EventData[3]);
					}
				}
				//myProc.WearUnderMsg(tmp);
			});
			//戻る
			myBT.setCommandProcessing(myBT.CommandMenuReturn,function(){
				myBT.MenuHidden();
				_self.ViewBox(myBT.Menu);		
				myBT.MenuView();
			});
			/*//脱いだ時のメッセージ
			myProc.WearUnderMsg = function(flg){
				if(flg){
					myBT.showMessage("女子校生<br>「くっ...」");
				}else{
					myBT.showMessage("女子校生<br>「...」");
				}
				myRpg.WearBreak(myRpg.Charctor);
			}*/
		});
	}
	
	//脱衣機能
	nugasu(){
		myBT.setCommandProcessing(myBT.CommandNugasu,function(){
			if(!_self.GetBoxStatus(myBT.CommandWaer)){
				_self.Elm(myBT.CommandNugasu,_self.TypeID).innerText = "やめる";
				myBT.MenuNugasu();
			}else if(_self.GetBoxStatus(myBT.CommandWaer)){
				_self.Elm(myBT.CommandNugasu,_self.TypeID).innerText = "脱がす";
				myBT.MenuHidden();				
				myBT.MenuView();				
			}
		});
	}
	
	//挿入
	sounyuu(){
		myBT.setCommandProcessing(myBT.CommandSounyuu,function(){
			if(myProc.sounyuuFlg==undefined)return;
			if((!_self.product_flg)||(_self.sample2_flg)){
				myBT.setMessage(["俺<br>「体験版だから挿入は無理か」<br>※体験版での挿入は出来ません。"]);
				return;
			}
			var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
			if(JudgeValue>70){
				myBT.setMessage(["俺<br>「さすがにまだ早いな...」"]);
				return;
			}
			//挿入判定
			if(!myST.SexSounyuu){
				myST.SexSounyuu = true;
				myST.SexFlg = true;
				_self.Elm(myBT.CommandSounyuu,_self.TypeID).innerText = "抜く";
				myBT.MenuSounyuu2();
				myImg.SetIndexPos("seieki",0);
				myST.TouchData[myST.TouchData.length-1]();				
				if(_self.CheckTouchEvent()) {
					//タッチ対応
					_self.doc.ontouchdown = myST.Sounyuu;
				} else {
					//タッチ非対応
					_self.doc.onmousedown = myST.Sounyuu;
				}
			}else{
				myST.SexSounyuu = false;				
				myST.SexFlg = false;
				myST.ShaseiFlg = false;
				_self.Elm(myBT.CommandSounyuu,_self.TypeID).innerText = "挿入";
				_self.ViewBox(myBT.Menu);
				myST.Sounyuu();
				myBT.MenuView();
				_self.HiddenBox(myBT.CommandShasei);				
			}
		});
		myProc.sounyuuFlg = true;
	}
	
	//射精
	shasei(){
		myBT.setCommandProcessing(myBT.CommandShasei,function(){
			if(!myST.ShaseiFlg)return;
			myST.Shasei();
			_self.HiddenBox(myBT.CommandShasei);
			myST.ShaseiCount = 0;
		});
		myProc.sounyuuFlg = true;
	}
	
	//ジャンケン
	janken(){
		myBT.setCommandProcessing(myBT.Commandjanken,function(){
			myBT.setMessage(myST.EventData[0]);
		});
	}
	
	//視姦
	Lock2(){
		myBT.setCommandProcessing(myBT.CommandLock2,function(){
			var index = Math.floor(Math.random()*3)+18;
			myBT.setMessage(myST.Story[index]);
		});
	}
	
	//枠消す
	boxnone(){
		myBT.setCommandProcessing(myBT.CommandBoxnone,function(){
			if(_self.GetBoxStatus("msgBox")){
				_self.HiddenBox("msgBox");
				return;
			}
			if(!_self.GetBoxStatus("msgBox")){
				_self.ViewBox("msgBox");
				return;
			}
		});
		myProc.sounyuuFlg = true;
	}

	//枠消す
	Test(){
		myBT.setCommandProcessing(myBT.CommandBattle,function(){
			myRpg.EventBattleCount = false;
			myRpg.BattleProcessing();
		});
	}
	
	Option(){
		myBT.setCommandProcessing(myBT.CommandOption,function(){
			var parent = _self.Elm("operation",_self.TypeID);
			//var Xpos = parseInt(_self.width_hi*0.05)+"px";
			var Xpos = parseInt(_self.width_hi*0.05)+"px";
			var Ypos = "10px";
			var res = _self.Elm("Option1",_self.TypeID);
			if((res==undefined)||(res==null)){
				//オプション画面本体生成
				myBT.setCommonBox(parent,"Option1",Xpos,Ypos);
				var data = _self.GetBoxData("Option1");
				//data.width = parseInt(_self.width_hi*0.9)+"px";
				data.width = parseInt(_self.width_hi*0.9)+"px";
				data.height = parseInt(window.innerHeight*0.9)+"px";
				_self.ChangeBox("Option1");
				//オプションメニュー領域生成
				var elm = _self.Elm("Option1",_self.TypeID);
				elm.innerHTML = "";
				myBT.setCommonBox(elm,"OptionMenu","-1px","-1px");
				var data2 = _self.GetBoxData("OptionMenu");
				data2.height = parseInt(_self.width_hi*0.9)+"px";
				_self.ChangeBox("OptionMenu");
				//オプションメニューを閉じる
				myProc.OptionMenuBoxClose = function(){
					var flg = _self.Elm("Setting",_self.TypeID);
					if(flg!=undefined)_self.HiddenBox("Setting");
					flg = _self.Elm("DataSave",_self.TypeID);
					if(flg!=undefined)_self.HiddenBox("DataSave");
					flg = _self.Elm("DataLoad",_self.TypeID);
					if(flg!=undefined)_self.HiddenBox("DataLoad");
				}				
				//オプションメニュー生成/閉じる
				_self.AddCommand("OptionMenu","opClose","閉じる");
				myBT.setCommandProcessing("opClose",function(){
					myProc.OptionMenuBoxClose();
					_self.HiddenBox("Option1");
					_self.HiddenBox("OptionMenu");
					myBT.MenuView();
					_self.ViewBox(myBT.Menu);					
				});
				//設定メニュー
				_self.AddCommand("OptionMenu","opSet","設定");
				myBT.setCommandProcessing("opSet",function(){
					myProc.OptionMenuBoxClose();
					Xpos = (parseInt(_self.width_hi*0.05)+99)+"px";
					//音楽ON/OFF設定
					var setElm = _self.Elm("Setting",_self.TypeID);
					if((setElm==undefined)||(setElm==null)){
						//音楽設定画面生成
						myBT.setCommonBox(parent,"Setting",Xpos,Ypos);
						var data = _self.GetBoxData("Setting");
						data.width = (parseInt(_self.width_hi*0.9)-100)+"px";
						data.height = parseInt(window.innerHeight*0.9)+"px";
						_self.ChangeBox("Setting");	
						//音楽On設定＆処理
						_self.AddCommand("Setting","musicOn","音楽ON");
						myBT.setCommandProcessing("musicOn",function(){
							var mustsElm = _self.Elm("musicStatus",_self.TypeID);
							myProc.music(myProc.musIndex,0);
							mustsElm.innerText = "現在の状態：再生";
						});
						//音楽Off設定＆処理
						_self.AddCommand("Setting","musicOff","音楽OFF");
						myBT.setCommandProcessing("musicOff",function(){
							var mustsElm = _self.Elm("musicStatus",_self.TypeID);
							myProc.music(myProc.musIndex,1);
							mustsElm.innerText = "現在の状態：停止";
						});
						var sts = myProc.music_flg?"再生":"停止";						
						_self.AddCommand("Setting","musicStatus","現在の状態："+sts);
						/*if(!_self.sample_flg){
							//絶対勝利フラグ
							_self.AddCommand("Setting","victory","絶対勝利フラグ");
							myBT.setCommandProcessing("victory",function(){
								var mustsElm = _self.Elm("VictoryStatus",_self.TypeID);
								myProc.victoryFlg = !myProc.victoryFlg;
								mustsElm.innerText = "現在の状態："+(myProc.victoryFlg?"オン":"オフ");
							});
							var sts = myProc.victoryFlg?"オン":"オフ";	
							_self.AddCommand("Setting","VictoryStatus","現在の状態："+sts);
						}*/
						//応援プラン用機能解放コード
						_self.AddCommand("Setting","special_code","");
						_self.Elm("special_code",_self.TypeID).innerHTML = '機能解放コード入力<br><input type="text" id="sp_code" /><br><button id="sp_func_on">機能解放</button><br><p id="sp_code_msg"></p>';
						myProc.SpFunction = function(){
							mySpCode.SetDataName(title_str+"_SpCode");
							mySpCode.SetSaveData("SpCodeValue",_self.Elm("sp_code",_self.TypeID).value);
							mySpCode.Save();
							var res = mySpCode.CheckCode();
							var msg = "機能コードが間違っています。";
							if(res)msg = "機能解放します。<br>※一度再起動してください。";
							myBT.optionMessage(parent,"機能コードが入力されました。<br>"+msg);
						}					
						myBT.setCommandProcessing("sp_func_on",myProc.SpFunction);
						//コード入力フォーカスイベント-IN
						_self.Elm("sp_code",_self.TypeID).addEventListener("focus",function(){
							//制御解除
							document.oncontextmenu = function () {
								var userAgent = window.navigator.userAgent.toLowerCase();
								var res = userAgent.indexOf("windows");
								if(res==-1){
									return true;
								}else{
									return false;
								}
							}
						});
						//コード入力フォーカスイベント=OUT
						_self.Elm("sp_code",_self.TypeID).addEventListener("blur",function(){
							document.oncontextmenu = function(){return false;}
						});
					}else{
						_self.ViewBox("Setting");	
					}				
				});
				/*セーブ/ロードなし*/
				//return;
				//保存生成
				_self.AddCommand("OptionMenu","opSave","セーブ");
				myBT.setCommandProcessing("opSave",function(){
					myProc.OptionMenuBoxClose();					
					Xpos = (parseInt(_self.width_hi*0.05)+99)+"px";
					//保存設定
					var setElm = _self.Elm("DataSave",_self.TypeID);
					if((setElm==undefined)||(setElm==null)){
						//保存設定画面生成
						myBT.setCommonBox(parent,"DataSave",Xpos,Ypos);
						var data = _self.GetBoxData("DataSave");
						data.width = (parseInt(_self.width_hi*0.9)-100)+"px";
						data.height = parseInt(window.innerHeight*0.9)+"px";
						_self.ChangeBox("DataSave");
						_self.AddCommand("DataSave","SaveMenu","セーブ");
						_self.Elm("SaveMenu",_self.TypeID).innerHTML += "<hr>";
						//データ設定ループ
						for(var loop=0;loop<myProc.LoadIndexMax;loop++){
							//保存設定＆処理
							var ld_data = myProc.loadData(true);
							var mvPosData = myProc.movedata[0];
							//保存データチェック
							var msg = "";
							//保存データメッセージ
							myProc.SaveMsg = function(index){
								var msg = "\nデータはありません。\n\n";
								if(ld_data["saveFlg"+index]){
									var mvIdx = ld_data["moveIndex"+index];
									msg = 'データ'+parseInt(index+1)+'\n';
									var funcIdx = mvPosData.length-1;
									msg += "場所："+mvPosData[funcIdx](mvIdx)+"\n";
									//msg += "イベントNo："+ld_data["LastEventNo"+index]+"\n";
									//msg += "LV："+ld_data["RpgData"+index].LV+",EXE："+ld_data["RpgData"+index].EXE+"\n";
									msg += "監禁"+myProc.Day+"目\n";

								}
								return msg;
							}
							//保存処理
							msg = myProc.SaveMsg(loop);
							_self.AddCommand("DataSave","saveNo"+loop,msg);
							_self.Elm("saveNo"+loop,_self.TypeID).innerHTML += "<hr>";
							myBT.setCommandProcessing("saveNo"+loop,function(){
								var stratPos = String("saveNo").length;
								var endPos = this.id.length - stratPos;
								var idx = parseInt(this.id.substr(stratPos,endPos));
								myProc.LoadIndex = idx;
								myProc.saveData();
								msg = myProc.SaveMsg(idx);
								_self.Elm(this.id,_self.TypeID).innerText = msg;
								_self.Elm(this.id,_self.TypeID).innerHTML += "<hr>";
								myBT.optionMessage(parent,"保存しました。");
							});
						}
					}else{
						_self.ViewBox("DataSave");	
					}
				});
				//読込生成				
				_self.AddCommand("OptionMenu","opLoad","ロード");
				myBT.setCommandProcessing("opLoad",function(){
					myProc.OptionMenuBoxClose();
					Xpos = (parseInt(_self.width_hi*0.05)+99)+"px";
					//読込設定
					var setElm = _self.Elm("DataLoad",_self.TypeID);
					if((setElm==undefined)||(setElm==null)){
						//読込設定画面生成
						myBT.setCommonBox(parent,"DataLoad",Xpos,Ypos);
						var data = _self.GetBoxData("DataLoad");
						data.width = (parseInt(_self.width_hi*0.9)-100)+"px";
						data.height = parseInt(window.innerHeight*0.9)+"px";
						_self.ChangeBox("DataLoad");
						_self.AddCommand("DataLoad","LoadMenu","ロード");
						_self.Elm("LoadMenu",_self.TypeID).innerHTML += "<hr>";
						//データ設定ループ
						for(var loop=0;loop<myProc.LoadIndexMax;loop++){
							//読込設定＆処理
							var ld_data = myProc.loadData(true);
							var mvPosData = myProc.movedata[0];
							//読込データチェック
							var msg = "";
							//読込データメッセージ
							myProc.SaveMsg = function(index){
								var msg = "\nデータはありません。\n\n";
								if(ld_data["saveFlg"+index]){
									var mvIdx = ld_data["moveIndex"+index];
									msg = 'データ'+parseInt(index+1)+'\n';
									var funcIdx = mvPosData.length-1;
									msg += "場所："+mvPosData[funcIdx](mvIdx)+"\n";
									//msg += "イベントNo："+ld_data["LastEventNo"+index]+"\n";
									//msg += "LV："+ld_data["RpgData"+index].LV+",EXE："+ld_data["RpgData"+index].EXE+"\n";
									msg += "監禁"+myProc.Day+"目\n";
								}
								return msg;
							}
							//読込処理
							msg = myProc.SaveMsg(loop);
							_self.AddCommand("DataLoad","LoadNo"+loop,msg);
							_self.Elm("LoadNo"+loop,_self.TypeID).innerHTML += "<hr>";
							myBT.setCommandProcessing("LoadNo"+loop,function(){
								var stratPos = String("LoadNo").length;
								var endPos = this.id.length - stratPos;
								var idx = parseInt(this.id.substr(stratPos,endPos));
								myProc.LoadIndex = idx;
								myProc.OptionMenuBoxClose();
								_self.HiddenBox("Option1");
								_self.HiddenBox("OptionMenu");
								_self.ViewBox(myBT.Menu);
								_self.Processing(false);
								myBT.optionMessage(parent,"読み込みました。");
							});
						}
					}else{
						_self.ViewBox("DataLoad");	
					}
				});
			}else{
				_self.ViewBox("Option1");
				_self.ViewBox("OptionMenu");
			}
			myBT.MenuHidden();
			_self.HiddenBox(myBT.Menu);
		});
	}	
	//音楽
	musicData(){
		var data = [
			/*"./music/失楽_A93.mp3",//0*/
			"./music/Strings02.mp3",//0
		];
		return data;
	}

	//効果音
	SEArray(){
		var data = [
			/*"./se/04.攻撃・打撃.wav",//0*/
		];
		return data;
	}
	
	//効果音
	VoiceArray(){
		var data = [
			"./voice/プロローグ.mp3",//0
			"./voice/シーン1.mp3",//1
			"./voice/シーン2.mp3",//2
			"./voice/シーン3.mp3",//3
			"./voice/シーン4.mp3",//4
			"./voice/シーン5.mp3",//5
			"./voice/シーン6.mp3",//6
			"./voice/シーン7.mp3",//7
			"./voice/シーン8.mp3",//8
			"./voice/シーン9.mp3",//9
			"./voice/シーン10.mp3",//10
			"./voice/シーン11.mp3",//11
			"./voice/シーン12.mp3",//12
			"./voice/シーン13.mp3",//13
			"./voice/シーン14.mp3",//14
			"./voice/シーン15.mp3",//15
			"./voice/シーン16.mp3",//16
			"./voice/シーン17.mp3",//17
			"./voice/シーン18.mp3",//18
			"./voice/シーン19.mp3",//19
			"./voice/シーン20.mp3",//20
			"./voice/シーン21.mp3",//21
			"./voice/シーン22.mp3",//22
			"./voice/シーン23.mp3",//23
			"./voice/シーン24.mp3",//24
			"./voice/シーン25.mp3",//25
			"./voice/シーン26.mp3",//26
			"./voice/シーン27.mp3",//27
			"./voice/シーン28.mp3",//28
			"./voice/シーン29.mp3",//29
			"./voice/シーン30.mp3",//30
			"./voice/シーン31.mp3",//31
			"./voice/シーン32.mp3",//32
			"./voice/シーン33.mp3",//33
			"./voice/シーン34.mp3",//34
			"./voice/シーン35.mp3",//35
			"./voice/シーン36.mp3",//36
			"./voice/シーン37.mp3",//37
			"./voice/シーン38.mp3",//38
			"./voice/シーン39.mp3",//39
			"./voice/シーン40.mp3",//40
			"./voice/シーン41.mp3",//41
			"./voice/シーン42.mp3",//42
			"./voice/シーン43.mp3",//43
			"./voice/シーン44.mp3",//44
			"./voice/シーン45.mp3",//45
			"./voice/シーン46.mp3",//46
			"./voice/シーン47.mp3",//47
			"./voice/シーン48.mp3",//48
			"./voice/シーン49.mp3",//49
			"./voice/シーン50.mp3",//50
			"./voice/シーン51.mp3",//51
			"./voice/シーン52.mp3",//52
			"./voice/シーン53.mp3",//53
			"./voice/シーン54.mp3",//54
			//"./voice/01_ねえねえ.mp3",//0
		];
		return data;
	}	
	
	//音楽
	music(trakNo=-1,cmd=0){
		//初期化
		if(trakNo==-1){
			var OptionData = [];
			var musData = this.musicData();
			for(var loop in musData){
				myProc.musData[loop] = new Audio;
				myProc.musData[loop].musNo = loop;
				myProc.musData[loop].src = musData[loop];
				myProc.musData[loop].music_flg = false;
				//ロード開始
				myProc.musData[loop].load();
				//ロード完了イベント
				myProc.musData[loop].addEventListener("loadedmetadata",function(){
					//音量設定/次音声ロード
					this.volume = 0.10;
				},
				false);
				//音楽再生
				myProc.musData[loop].musStart = function(){
					if(!this.music_flg){
						this.music_flg = true;
						myProc.musIndex = this.musNo;
						myProc.musStatus = true;
						this.play();
						this.addEventListener("ended", function() {
							this.currentTime = 0;
							this.play();
						}, false);		
					}
				}
				//停止
				myProc.musData[loop].musStop = function(){
					if(this.music_flg){
						this.pause();
						this.currentTime = 0;
						this.music_flg = false;
						myProc.musStatus = false;
					}
				}				
			}
			return;
		}
		//再生
		if(cmd==0)myProc.musData[trakNo].musStart();
		//停止
		if(cmd==1)myProc.musData[trakNo].musStop();
		//全停止
		if(cmd==2){
			for(var loop in myProc.musData){
				myProc.music(loop,myST.BGM_OFF);					
			}
		}
		//再生中かチェック
		if(cmd==3)return myProc.musData[trakNo].music_flg;
	}
	//効果音
	SESound(trakNo=-1,cmd=0){
		//初期化
		if(trakNo==-1){
			var musSEData = this.SEArray();
			for(var loop in musSEData){
				myProc.musSEData[loop] = new Audio;
				myProc.musSEData[loop].musNo = loop;
				myProc.musSEData[loop].src = musSEData[loop];
				myProc.musSEData[loop].music_flg = false;
				//ロード開始
				myProc.musSEData[loop].load();
				//ロード完了イベント
				myProc.musSEData[loop].addEventListener("loadedmetadata",function(){
					//音量設定/次音声ロード
					this.volume = 0.35;
				},
				false);
				//音楽再生
				myProc.musSEData[loop].musStart = function(){
					var debugView = _self.Elm(".debug");
					if(!this.music_flg){
						this.music_flg = true;
						this.musSEIndex = loop;
						myProc.musSEStatus = true;
						myBT.debugMessage("SE発生:"+this.musNo+"\n");
						this.play();
						if(!_self.Windows_flg){
							this.addEventListener("ended", function() {
								this.currentTime = 0;
								this.music_flg = false;
							}, false);
						}
					}
				}
				//停止
				myProc.musSEData[loop].musStop = function(){
					if(this.music_flg){
						this.pause();
						this.currentTime = 0;
						this.music_flg = false;
						myProc.musSEStatus = false;
						var debugView = _self.Elm(".debug");
						myBT.debugMessage("SE消音:"+this.musNo+"\n");
					}
				}				
			}
			return;
		}
		//再生
		if(cmd==0)myProc.musSEData[trakNo].musStart();
		//停止
		if(cmd==1)myProc.musSEData[trakNo].musStop();
	}
	
	//効果音
	Voice(trakNo=-1,cmd=0,option=[],repeat=false){
		//初期化
		if(trakNo==-1){
			var musVoiceData = this.VoiceArray();
			for(var loop in musVoiceData){
				myProc.musVoiceData[loop] = new Audio;
				myProc.musVoiceData[loop].musNo = loop;
				myProc.musVoiceData[loop].src = musVoiceData[loop];
				myProc.musVoiceData[loop].music_flg = false;
				//ロード開始
				myProc.musVoiceData[loop].load();
				//ロード完了イベント
				myProc.musVoiceData[loop].addEventListener("loadedmetadata",function(){
					//音量設定/次音声ロード
					this.volume = 1;
					this.loop = false;
				},
				false);
				//音楽再生
				myProc.musVoiceData[loop].musStart = function(){
					var debugView = _self.Elm(".debug");
					if(!this.music_flg){
						this.music_flg = true;
						this.musVoiceIndex = loop;
						myProc.musVoiceStatus = true;
						myBT.debugMessage("Voice発生:"+this.musNo+"\n");
						this.play();
						if(!_self.Windows_flg){
							this.addEventListener("ended", function() {
								this.pause();
								this.currentTime = 0;
								this.music_flg = false;
							}, false);
						}
					}
				}
				//停止
				myProc.musVoiceData[loop].musStop = function(){
					if(!this.paused){
						this.pause();
						this.currentTime = 0;
						this.music_flg = false;
						myProc.musVoiceStatus = false;
						var debugView = _self.Elm(".debug");
						myBT.debugMessage("Voice消音:"+this.musNo+"\n");
					}
				}				
			}
			return;
		}
		//再生
		if(cmd==0){
			//同じ音声なら再生しない
			if(myProc.musVoiceData[trakNo].music_flg&&repeat)return;
			//時間指定での再生時
			if(option.length!=0){
				//音声開始位置設定
				myProc.musVoiceData[trakNo].currentTime = option[0];
				//再生時間終了
				_self.setTimer(function(trakNo){
					if(myProc.timer_id>1){
						myProc.timer_id--;
						myBT.debugMessage("Voiceタイマーキャンセル:"+trakNo+"\n");
						return;
					}
					myProc.timer_id--;
					myProc.musVoiceData[trakNo].musStop();
				},option[1]*1000,trakNo);
				console.log("TimerID:"+myProc.timer_id);
				//タイマーIDカウント/2以上なら次再生音声がある場合はタイマーを無視する。
				myProc.timer_id++;
			}
			myProc.musVoiceData[trakNo].musStart();
		}else
		//停止
		if(cmd==1){
			myProc.musVoiceData[trakNo].musStop();
		}
		//全停止
		if(cmd==2){
			for(var loop in myProc.musVoiceData){
				myProc.Voice(loop,myST.BGM_OFF);					
			}
		}		
	}
	
}
myProc = new MyProcessing();