//メイン処理
var baseJs = null;
var _time = null;
BaseJsLoaded = false;
class StartProcess{
	//Jsセット
	constructor(){
		this.load = false;
		this.imageload = false;
		this.oneload = false;
		this.title_str = document.title;
		console.log("OK");
	}
	ClassLoad(){
		this.loaded();
		this.ScriptLoad("./baseJs/core.js?202305091246");
		this.ScriptLoad("./baseJs/timer.js?202305091246");
		this.ScriptLoad("./baseJs/setting.js?202305091246");
		this.ScriptLoad("./baseJs/image.js?202305091246");
		this.ScriptLoad("./baseJs/box.js?202305091246");
		this.ScriptLoad("./baseJs/save.js?202305091246");
		this.ScriptLoad("./baseJs/baseJs.js?202305091246");
	}
	ScriptLoad(URL){
		if(Main.oneload){
			setTimeout(this.ScriptLoad,1000,URL);
			return;
		}
		Main.oneload = false;
		var selm = document.createElement("script");
		selm.src = URL;
		document.body.appendChild(selm);
		selm.onload = function(){
			Main.oneload = true;
			if(this.src.indexOf("baseJs.js")!==-1){
				setTimeout(function(){
					BaseJsLoaded = true;
				},500);
			}
		}
		return selm;
	}
	loaded(){
		setTimeout(function(_this){
			if(BaseJsLoaded){
				_this.load = true;
			}else{
				_this.loaded();
			}
		},100,this);
	}
	Start(func){
		if(!Main.load){
			setTimeout(Main.Start,1000,func);
			return;
		}
		func();
	}
	ClassSetting(){
		var _this =null;
		try{
		_this = new BaseJs();
		_this.addProto(TimerProc,_this);
		_this.addProto(BaseSetting,_this);
		_this.addProto(ImageProcess,_this);
		_this.addProto(BoxMaker,_this);
		}catch(e){
			console.log(e);
			document.location.reload();
		}
		return _this;
	}
	Loading(_self,width="400px",height="550px"){
		//枠を生成
		var elm_div = _self.GetInitBox();
		var Optin = {
			linecolor:false,
			bgcolor:"#030303",
			txtcolor:"#F0F0F0",
			opacity:1,
		}
		elm_div = _self.SetBoxParam(elm_div,"anmaku",width,height,Optin);
		_self.AddBoxData(elm_div);
		_self.ChangeBox(elm_div.Name);
		_self.AddCommand("anmaku","br1","　");
		_self.AddCommand("anmaku","br2","　");
		_self.AddCommand("anmaku","br3","　");
		_self.AddCommand("anmaku","br4","　");
		_self.AddCommand("anmaku","br5","　");
		_self.AddCommand("anmaku","Loading","Now Loading...");
		_self.Elm(".Loading").classList.toggle("blinking");
		_self.AddCommand("anmaku","br6","　");
		_self.AddCommand("anmaku","Progress","0%");
		_self.ButtonView = function(){
			if(!Main.imageload){
				_self.setTimer(_self.ButtonView,100);
				return;
			}
			_self.Elm(".Loading").classList.toggle("blinking");
			_self.Elm(".Loading").innerText = Main.title_str;
			_self.Elm(".Progress").innerText = " ";
			_self.AddCommand("anmaku","startbutton","ここをタッチしてスタート！");
			_self.Elm(".startbutton").classList.toggle("blinking");
			_self.AddCommand("anmaku","Version","　");
			_self.Elm(".Version").innerText = ver_str;
			_self.AddEventForId("startbutton",function(e){
				 _self.HiddenBox("anmaku");
			});
		}
		_self.ButtonView();
		return _self;
	}
	DisplayWidth(value){
		var width = 0;
		if(window.innerWidth>=value){
			width = value;		
		}else{
			width = window.innerWidth;
		}
		return width;
	}
	DisplayHeight(value){
		var height = 0;
		if(window.innerHeight<=value){
			height = window.innerHeight;
		}else{
			height = value;
		}
		return height;
	}
}
var Main = new StartProcess();
Main.ClassLoad();