class Anime{
	constructor(namae,yoko,tate,kyan,gen){
		this.name=name;
		this.img=document.createElement('img');
		this.img.src=gen;
		this.can=kyan;
		this.yoko=yoko;
		this.tate=tate;
		this.koma=1;
	}
	tati(x,y,lin,col){
		if(lin==undefined){
			lin=0;
		}
		if(col==undefined){
			col=0;
		}						
		this.can.drawImage(this.img,col*this.yoko,lin*this.tate,this.yoko,this.tate,x-(this.yoko/2),y-this.tate,this.yoko,this.tate);
	};
	bg(x,y,lin,col){
		if(lin==undefined){
			lin=0;
		}
		if(col==undefined){
			col=0;
		}						
		this.can.drawImage(this.img,col*this.yoko,lin*this.tate,this.yoko,this.tate,x,y,this.yoko,this.tate);
	};
};
class Hita{
	constructor(x,y,x1,y1){
		this.x=x;	
		this.y=y;
		this.x1=x1;
		this.y1=y1;
	}
	c(x,y){
		if(x>=this.x&x<=this.x1&y>=this.y&y<=this.y1){
			return true
		}else{
			return false
		}
	}
};
var prop=window.innerWidth/window.innerHeight;
var propw;
if(prop<=1.666666667){
	if(Math.floor(((100*window.innerWidth)/1200)/10)*10<=60){
		propw=60
	}else{
		propw=Math.floor(((100*window.innerWidth)/1200)/10)*10;
	}
}else{
	if(Math.floor(((100*window.innerHeight)/720)/10)*10<=60){
		propw=60
	}else{
		propw=Math.floor(((100*window.innerHeight)/720)/10)*10;
	}
}

var canvas=document.createElement('canvas');
canvas.style.zIndex=0;
canvas.width=(1200*propw)/100;
canvas.height=(720*propw)/100;
canvas.style.position='absolute';
canvas.style.left=(window.innerWidth/2)-(canvas.width/2);
canvas.style.top=(window.innerHeight/2)-(canvas.height/2);
var can=canvas.getContext('2d');
document.body.appendChild(canvas);
canvas.style.userSelect='none';
can.scale(propw/100,propw/100);

can.fillStyle='#222222';
can.fillRect(0,0,1500,1800);
can.fillStyle='#ff00ff';
can.font='30px arial';
can.fillText('Loading',10,30);

var sak={idiom:'jp',mode:'menu',press:false,line:1};
var m={x:0,y:0};

var bgmenu=new Anime('menu',1200,720,can,'sakina/bg_main.png');
var buttons=new Anime('buttons',300,100,can,'sakina/button.png');

var sakitati=new Anime('sakinatatie',400,720,can,'sakina/sakina_tati.png');
var sakitatim=new Anime('sakinatatiem',400,720,can,'sakina/sakina_tatim.png');
var sakikohai=new Anime('sakikouhai',600,720,can,'sakina/sakina_kosuhai.png');
var sakiko=new Anime('sakikouhai',400,720,can,'sakina/sakina_kosu.png');
var sakipa=new Anime('sakipajama',400,720,can,'sakina/sakina_pajama.png');
var tonari=new Anime('tonari',600,720,can,'sakina/tonari_tati.png');

var bgie=new Anime('bgie',1200,720,can,'sakina/bg_ie.png');
var bgiesoto=new Anime('bgiesoto',1200,720,can,'sakina/bg_iesoto.png');
var bgsigoto=new Anime('bgie',1200,720,can,'sakina/bg_sigoto.png');
var bgmiti=new Anime('bgmiti',1200,720,can,'sakina/bg_mitibata.png');

var videov;
var video=document.createElement('video');
document.body.appendChild(video);
video.width=(1200*propw)/100;
video.height=(720*propw)/100;
video.src='sakina/tonayomi.mp4';
video.style.position='absolute';
video.style.left=canvas.style.left;
video.style.top=canvas.style.top;
video.zIndex=10;
video.preload='auto';
video.loop=true;
video.controls=false;
video.style.display='none';
video.style.userSelect='none';

var click=new Audio('sakina/click.wav');

var p1=document.createElement('p');
p1.style.position='absolute';
p1.style.width=(1120*propw)/100;

p1.style.height=(72*propw)/100;

p1.style.zIndex=2;
p1.style.left=((window.innerWidth/2)-(canvas.width/2))+((30*propw)/100);
p1.style.top=((window.innerHeight/2)-(canvas.height/2))+((615*propw)/100);
p1.style.border= "2px solid transparent";
p1.style.backgroundColor='#555555';
p1.style.opacity="0.7";
p1.style.display='none';
p1.style.userSelect='none';
document.body.appendChild(p1);

var transA=[5,9,10,11,13,17,25,28,29,35,43,49,51];

var transition;
var opa={o:0,f:0,c:0,ff:0};
var p2=document.createElement('p');
p2.style.position='absolute';
p2.style.width=(1200*propw)/100;
p2.style.height=(720*propw)/100;
p2.style.zIndex=10;
p2.style.left=canvas.style.left;
p2.style.top=((window.innerHeight/2)-(canvas.height/2))-16;
p2.style.backgroundColor='#000000';
p2.style.opacity="0";
p2.style.display='block';
p2.style.userSelect='none';
document.body.appendChild(p2);

var lines=new Array();
lines['jpin']='右側にクリックすると次のセリフへ、左側にクリックすると前のセリフへ';
lines['enin']="Click on the right side for the next line or click on the left side for the previous line";

lines['jp1']='やまだ　さきな';
lines['jp2']='20代前半、人見知り、始めての一人暮らし';
lines['jp3']='数ヶ月前に都会に引っ越し、仕事場でもプライベートでも仲のいい人がいない';
lines['jp4']='人見知りの克服も含めてネット配信をはじめた';
lines['jp5']='人こないと想像していたが少しずつリスナーが増えて、誰にも話せなかったアニメの話題も楽しく話せた';
lines['jp6']='始めては声のみ、最近はウイッグとマスクつけて顔出し配信をこっそりしてる、よく可愛いと言われるようになった';
lines['jp7']='リアルでも人と接したくなった。。。';

lines['en1']="Sakina Yamada";
lines['en2']="Early twenties, shy, first time living alone";
lines['en3']="Moved to a big city few months ago, have no friends at work or outside work";
lines['en4']="To change that she started to livestream";
lines['en5']="For her surprise people came to her stream, she talked about anime and other things she never did, it was fun";
lines['en6']="First just her voice, now with a mask and a wig she shows herself to the viewers, and they say she's cute";
lines['en7']="Now she wants to connect with people in real world...";

lines['jp8']='好きな男性はまだいないが最近性欲が強くなってきてる。。。';
lines['en8']="She does not have any 'special' person but lately her sexual desire it's getting real strong...";

lines['jp9']='仕事場の男性たちをみかけるとどんなエッチをするかなって想像してしまう';
lines['en9']="When she sees men at work she starts to wonder what kind of sex they like";

lines['jp10']='暇な時はよくエッチな動画をみてる、息が荒くなる。。。';
lines['en10']="On free days she use to watch sex videos, her breath gets heavy...";

lines['jp11']='彼女は仕事場の同僚に話をかけてみた。。。';
lines['jp12']='興奮と緊張で真っ赤な顔で何も言えなかった。';
lines['en11']="She tried to talk to a co-worker...";
lines['en12']="She's so excited and tense she couldn't say a word";

lines['jp13']='その日凹みながら好きなアニメみてたら隣の部屋からAVでよく聞いてるシコシコ音が聞こえてきた';
lines['jp14']='となり：　あぁ　きもちいい！　シコシコっ！';
lines['jp15']='となり：　んっ、いくぅいくぅ！！';
lines['jp16']='さきな：　んっ。。。';
lines['en13']="To heal she watched some anime, that's when she heard that fap sound she used to hear at sex videos";
lines['en14']="Neighbor: Oh that feels so good! fapfap";
lines['en15']="Neighbor: Yeah, I'm cuumming!!";
lines['en16']="Sakina: nmm...";

lines['jp17']='さきな：　昨日さぁ、となりの部屋から変な音がしてさぁ。。。一人であれしてた。。。';
lines['jp18']='リスナー：えっ、あれ　あれ？！';
lines['jp19']='さきな：　そう、男性がむらむらしてる時に一人でするあれ。。。';
lines['jp20']='リスナー：　やばっ！もしかして　さきなちゃんの妄想しながらシてたとか？！';
lines['jp21']='さきな：　数ヶ月ここ住んでるけどまだ見たことないよ、きっと見られたこともない';
lines['jp22']='リスナー：　さきなちゃん可愛いから隣さん皆　さきなちゃんの妄想でシてるよ、きっと！ｗ';
lines['jp23']='さきな：　えぇ　どうかな。。。リスナーには可愛いと言われるが。。。';
lines['jp24']='リスナー：　いやいや、さきなちゃんみたいな可愛いこが俺の隣に住んでたらなぁ！';

lines['en17']="Sakina: Yesterday I heard 'that' weird sound coming from next door, he's doing it by himself...";
lines['en18']="Viewer: do doing what?";
lines['en19']="Sakina: Yup, doing that thing guys do when they're horny and alone...";
lines['en20']="Viewer: Ohh! What if he was fantasizing Sakina-chan and fapping?";
lines['en21']="Sakina: I'm living here for a few months but I never saw him and I think he also didn't see me";
lines['en22']="Viewer: You're so cute I bet all the neighbors are fapping imagining you!";
lines['en23']="Sakina: I'm not sure...you guys say I'm pretty but...";
lines['en24']="Viewer: Maan if only my neighbor was cute like you!";

lines['jp25']='さきな：気になる、となりさんどんな人かな、今日休みだしこっそり出るの待ってみようかな。。。';

lines['en25']="Sakina: Nn, I wonder how he looks like, it's my free day anyway, I'll wait and sneak peak him...";

lines['jp26']='さきな：　出てる出てる！';

lines['en26']="Sakina: He is out!";

lines['jp27']='さきな：かわいい。。。';

lines['en27']="Sakina: Cute...";

lines['jp28']='さきな：　となりさん、今日も一人でシてる。。。んっ。。。';

lines['en28']="Sakina: Today he's 'doing' again...mm...";

lines['jp29']='リスナー：　さきなちゃんけっこう気になってるじゃん！アプローチしたら？';
lines['jp30']='さきな：　ん。。。したいけど。。。毎日会ってる仕事場の人にさえ声かけられなくて。。。';
lines['jp31']='リスナー：　配信じゃ普通に話してるのに！';
lines['jp32']='さきな：　そうだけど、ここはバーチャルだし、変装もしてる。。。';
lines['jp33']='リスナー：　じゃぁさー変装してアプローチしたらどう？！';
lines['jp34']='さきな：　。。。';

lines['en29']="Viewer: Oh you're really into that neighbor! Why don't you hit on him?";
lines['en30']="Sakina: Nn, I wanna but...I can't even talk to guys I meet everyday at work...";
lines['en31']="Viewer: Weird, at the stream you sound so easy going";
lines['en32']="Sakina: Yeah, but it's internet and I'm in disguise too...";
lines['en33']="Viewer: So what about talking to him in disguise?";
lines['en34']="Sakina: ...";

lines['jp35']='さきな：。。。';
lines['jp36']='さきな：　ヨー！　み　み　道に迷ってさぁー。。。';

lines['en35']="Sakina: ...";
lines['en36']="Sakina: YOh! I I I'm kind of lost...";

lines['jp37']='となり：　。。。';
lines['jp38']='さきな：　このへんで漫画喫茶探してて。。。';
lines['jp39']='となり：　（小声）可愛い。。。';
lines['jp40']='となり：　ぁ。。。ぁ。。。あそこ　曲がったら　あります。。。';
lines['jp41']='さきな：　ありがとう！　にこっ！';

lines['en37']="Neighbor: ...";
lines['en38']="Sakina: I was looking for a manga cafe...";
lines['en39']="Neighbor: (murmurs) cute...";
lines['en40']="Neighbor: nn...nn...if you turn left there's one...";
lines['en41']="Sakina: Thank you! smiles";

lines['jp42']='さきな：　（可愛い言われた！！　どっくんどっくん）';

lines['en42']="Sakina: (He said I'm cute! thump thump)";

lines['jp43']='さきな：　こないだネットで知ってすっごく読みたくなった漫画があって、おばさんでも魔法少女になれるって漫画喫茶に全然なくて';
lines['jp44']='となり：　それもってるよ！';
lines['jp45']='さきな：　すっごい！　読みたいな';
lines['jp46']='となり：　かしてあげようか！';
lines['jp47']='さきな：　いいの？！';
lines['jp48']='となり：　ぜんぜんいいすよ';

lines['en43']="Sakina: I found a manga on internet that I really want to read, it's called 'even an aunt can be a magical girl' but I can't find it anywhere";
lines['en44']="Neighbor: I have it!";
lines['en45']="Sakina: Really?! Oh I really wanna read it";
lines['en46']="Neighbor: I can lend you!";
lines['en47']="Sakina: That's so kind!";
lines['en48']="Neighbor: You're welcome";

lines['jp49']='となり：　これですよ、読んでみて！';
lines['jp50']='さきな：　（私の脚すっごく見てる、私としたいかな？　興奮しちゃう。。。）';

lines['en49']="Neighbor: Here it is, you can read it!";
lines['en50']="Sakina: (Oh he's staring at my legs, he wants me? That's so exciting...)";

lines['jp51']='さきな：　（ズボン膨らんでる。。。握りたい。。。）';
lines['jp52']='さきな：（こっちからせめる勇気ないけど少し誘いをしようかな。。。）';
lines['jp53']='さきな：　（全然せめてこない。。。どうしよう握りたくてもう我慢できないかも　んっ。。。）';

lines['en51']="Sakina: (Oh I can see that 'volume' in his pants, I wanna feel it...)";
lines['en52']="Sakina: (but it's so embarrassing, I'll try to arouse him a little more...)";
lines['en53']="Sakina: (and he's not coming to me, I can't help myself...Mmm)";

lines['jp54']='体験版はここまで、ありがとうございました！';

lines['en54']="The trial version ends here, thanx for playing!";


var bstart=new Hita(426,472,726,568);

var bjp=new Hita(200,603,500,700);
var ben=new Hita(659,603,951,700);

function refre(){
	can.fillStyle='#222222';
	can.fillRect(0,0,1500,800);
	if(sak.mode=='menu'){
		video.pause();
		video.style.display='none';
		p1.style.display='none';
		if(sak.idiom=='jp'){
			bgmenu.bg(0,0);
		}else{
			bgmenu.bg(0,0,0,1);
		}
		if(sak.idiom=='jp'){			
			buttons.bg(425,470,2);
		}else{
			buttons.bg(425,470,3);
		}
		buttons.bg(200,600);
		buttons.bg(650,600,1);		
	}else if(sak.mode=='setsu'){
		video.style.display='none';			
		video.pause();			
		bgmiti.bg(0,0);
		p1.style.display='block';		
		var pvx=(5*propw)/100;
		p1.innerHTML='<font color="#ffffff"><font size='+Math.floor(pvx)+'>'+lines[sak.idiom+'in']+'</font></font>';
	}else{ 	
		if(sak.line<5){
			video.style.display='none';			
			video.pause();
			
			bgmiti.bg(0,0);
			sakitati.tati(600,720);			
		}else if(sak.line<9){
			bgie.bg(0,0);
			if(sak.line>5){
				if(sak.line<8){
					sakikohai.tati(600,720);			
				}else{
					sakikohai.tati(600,720,0,1);
				}
			}			
		}else if(sak.line<10){
			bgsigoto.bg(0,0);
			sakitati.tati(600,720,0,1);
		}else if(sak.line<11){
			bgie.bg(0,0);
			sakipa.tati(600,720,0,1);
		}else if(sak.line<13){
			bgsigoto.bg(0,0);
			if(sak.line<12){
				sakitatim.tati(600,720);
			}else{
				sakitatim.tati(600,720,0,1);
			}
		}else if(sak.line<17){
			bgie.bg(0,0);
			if(sak.line<15){
				sakipa.tati(600,720,0,2);
			}else{
				sakipa.tati(600,720,0,1);
			}
			
		}else if(sak.line<25){
			bgie.bg(0,0);
			if(sak.line<19){
				sakikohai.tati(600,720);
			}else{
				sakikohai.tati(600,720,0,1);
			}
		}else if(sak.line<28){
			bgiesoto.bg(0,0);			
			if(sak.line==27){				
				tonari.tati(600,720);
			}			
		}else if(sak.line<29){
			bgie.bg(0,0);
			sakipa.tati(600,720,0,1);
		}else if(sak.line<35){
			bgie.bg(0,0);
			sakikohai.tati(600,720,0,1);
		}else if(sak.line<43){  
			bgmiti.bg(0,0);
			if(sak.line<37){
				sakiko.tati(600,720);
			}else if(sak.line<38){
				tonari.tati(600,720);
			}else if(sak.line<39){
				sakiko.tati(600,720);
			}else if(sak.line<41){
				tonari.tati(600,720,0,2);
			}else{
				sakiko.tati(600,720,0,1);
			}
		}else if(sak.line<49){
			videov='';
			video.style.display='none';			
			video.pause();
			bgmiti.bg(0,0);			
			if(sak.line==44|sak.line==46|sak.line==48){
				tonari.tati(600,720,0,1);
			}else if(sak.line<44){
				sakiko.tati(600,720);
			}else{
				sakiko.tati(600,720,0,1);
			}
		}else if(sak.line<51){
			if(videov!='toyomi'){
				videov='toyomi';
				video.pause();			
				video.src='sakina/tonayomi.mp4';
				video.style.display='inline';
				video.currentTime=0;
				video.play();			
			}			
		}else {
			if(videov!='toyopan'){
				videov='toyopan';
				video.pause();			
				video.src='sakina/tonayopan.mp4';
				video.style.display='inline';
				video.currentTime=0;
				video.play();			
			}			
		}
		p1.style.display='block';
		var pvx=(5*propw)/100;
		p1.innerHTML='<font color="#ffffff"><font size='+Math.floor(pvx)+'>'+lines[sak.idiom+sak.line]+'</font></font>';
	}	
}
function traCheck(line){
	var tc=false;
	for(var i=0;i<transA.length;i++){
		if(transA[i]==line){
			tc=true;
		}
	}	
	return tc
};

function trans(){		
	p2.style.opacity=opa.o;	
	if(opa.f>0){
		if(opa.f==1){
			opa.o+=0.3;
			if(opa.o>=1){
				opa.f=2;
				opa.o=1;
			}
		}else if(opa.f==3){
			opa.o-=0.3;
			if(opa.o<=0){
				opa.o=0;
				opa.f=0;				
				sak.press=false
			}
		}else{
			opa.c++;			
			opa.o=1;
			if(opa.c>=2){
				opa.f=3;
				opa.c=0;				
				if(sak.mode=='menu'){
					sak.line=1;
				}else if(opa.ff>0){
					if(opa.ff==1){
						sak.line++;
						opa.ff=0;
					}else{
						sak.line--;
						opa.ff=0;
					}
				}
				refre();				
			}
		}		
	}	
};
onmousemove=function(e){	
	if(e.clientX-((window.innerWidth/2)-(canvas.width/2))>canvas.width){
		m.x=1200;
	}else if(e.clientX>(window.innerWidth/2)-(canvas.width/2)){		
		m.x=Math.floor((Math.floor(e.clientX-((window.innerWidth/2)-(canvas.width/2))))/(propw/100));
	}else{
		m.x=0;
	}
	if(e.clientY-((window.innerHeight/2)-(canvas.height/2))>canvas.height){
		m.y=720;
	}else if(e.clientY>(window.innerHeight/2)-(canvas.height/2)){
		m.y=Math.floor((Math.floor(e.clientY-((window.innerHeight/2)-(canvas.height/2))))/(propw/100));
	}else{
		m.y=0;
	}	
}

onmousedown=function(e){	
	if(!sak.press){
		click.currentTime=0;
		click.play();
		if(sak.mode=='menu'){			
			if(bstart.c(m.x,m.y)){								
				sak.mode='setsu';
				sak.press=true;
				opa.f=1;				
			}else if(bjp.c(m.x,m.y)){				
				sak.idiom='jp';
				document.title='人見知りでもやる時はやる！（体験版）';				
				refre();				
			}else if(ben.c(m.x,m.y)){			
				sak.idiom='en';				
				document.title='Even a shy girl do it!(Trial Version)';
				refre();
			}				
		}else if(sak.mode=='setsu'){			
			sak.mode='novel';
			sak.press=true;
			opa.f=1;				
		}else{						
			if(m.x>canvas.width/2){
				if(traCheck(sak.line+1)){						
					sak.press=true;
					opa.f=1;
					opa.ff=1;
				}else{
					if(lines[sak.idiom+(sak.line+1)]!=undefined){
						sak.line++;
					}else{							
						sak.mode='menu';							
						videov='';
						sak.line=1;
					}
				}
			}else{
				if(traCheck(sak.line)){
					sak.press=true;
					opa.f=1;
					opa.ff=2;
				}else{
					if(sak.line>1){
						sak.line--;
					}
				}
			}
			refre();			
		}		
	}	
};

window.onload=function(){
	can.fillStyle='#222222';
	can.fillRect(0,0,1500,800);	
	transition=setInterval(trans,100);
	refre();	
};
