class Dotto{
	constructor(namae,yoko,tate,gen,canvas){
		this.namae=namae;
		this.img=document.createElement('img');
		this.img.src=gen;
		this.can=canvas;
		this.yoko=yoko;
		this.tate=tate;			
		this.koma=0;
		this.otos=new Array();
	}
	oto(se){
		for(var a=0;a<arguments.length;a++){
			if(a>0){
				if(this.otos[arguments[a]]==undefined){
					this.otos[arguments[a]]=new Array();
				}
				this.otos[arguments[a]].push(se);								
			}
		}
	};
	kyara(x,y,gyou,tater){
		if(gyou==undefined){
			gyou=0;
		}
		if(tater==undefined){
			tater=0;
		}
		this.can.drawImage(this.img,tater*this.yoko,gyou*this.tate,this.yoko,this.tate,x-(this.yoko/2),y-this.tate,this.yoko,this.tate);
	};
	ani(x,y,gyou,ripi,talk){
		if(gyou==undefined){
			gyou=0;
		}	
		if(this.otos[this.koma]!=undefined){			
			for(var s=0;s<this.otos[this.koma].length;s++){
				this.otos[this.koma][s].p();				
			};
		};
		this.can.drawImage(this.img,this.koma*this.yoko,gyou*this.tate,this.yoko,this.tate,x-(this.yoko/2),y-this.tate,this.yoko,this.tate);
		this.koma++;
		if(talk==undefined){
			if(this.koma*this.yoko>=this.img.width){
				if(ripi!=undefined){
					this.koma=ripi;
				}else{
					this.koma=0;
				}
			}
		}else{
			if(this.koma>=ripi){
				var ran=Math.floor(Math.random()*15);
				if(ran<2){
					this.koma=ripi+1;
				}else if(ran<6){
					this.koma=ripi+2;
				}else{
					this.koma=ripi;
				}
			}
		}
	};
	talk(x,y,gyou){
		if(gyou==undefined){
			gyou=0;
		}		
		var ran=Math.floor(Math.random()*15);
		if(ran<2){
			this.koma=1;
		}else if(ran<6){
			this.koma=2;
		}else{
			this.koma=0;
		}
		this.can.drawImage(this.img,this.koma*this.yoko,gyou*this.tate,this.yoko,this.tate,x-(this.yoko/2),y-this.tate,this.yoko,this.tate);		
	};
	haikei(x,y,gyou,tater){		
		if(gyou==undefined){
			gyou=0;
		}
		if(tater==undefined){
			tater=0;
		}
		this.can.drawImage(this.img,tater*this.yoko,gyou*this.tate,this.yoko,this.tate,x,y,this.yoko,this.tate);
	};
}

class Oto{
	constructor(src){
		this.mina=new Array();
		this.mina[0]=new Audio(src);
		this.mina[1]=new Audio(src);
		this.mina[1].volume=0.5;
	};
	p(){
		if(this.mina[0].currentTime==this.mina[0].duration|this.mina[0].currentTime==0){
			this.mina[0].play();
		}else{
			this.mina[1].play();
		}
	};
};
class Hitto{
	constructor(x1,y1,x2,y2){
		this.x1=x1;
		this.y1=y1;
		this.x2=x2;
		this.y2=y2;
	};
	c(x,y){
		if(x>=this.x1&x<=this.x2&y>=this.y1&y<=this.y2){
			return true;
		}else{
			return false;
		}
	};
};

class Balloon{
	constructor(fonts,width,height,canv){
		this.font=document.createElement('img');
		this.font.src=fonts;
		this.width=width;
		this.height=height;
		this.canv=canv;		
		this.prom=0;		
		this.posi=0;
		this.leposi=0;
		this.tleposi=0;
		this.dian=1;
		this.dialogs=new Array();
		this.diav=false;
		this.nx=true;
		this.ttx;		
	}	
	fukif(fukidasi){
		this.fukidasi=document.createElement('img');
		this.fukidasi.src=fukidasi;
	}
	letter(l,nex,sto){
		this.letters=l;
		this.nex=nex;
		this.sto=sto;
	}	
	dialog(d){
		this.dialogs=d;		
	}
	next(){		
		if(this.tleposi!=0&this.tleposi<this.ttx){
			this.leposi=this.tleposi;
		}else{
			this.dian++;
			this.leposi=0;	
		}		
	}
	reset(){		
		this.dian=1;
		this.leposi=0;		
		this.nx=true;
	}
	seri(txt,x,y,nagasa,takasa,alpha){			
		this.ttx=this.dialogs[txt+this.dian].length;
		if(this.dialogs[txt+(this.dian+1)]==undefined){
			this.diav=false;
		}else{
			this.diav=true;
		}		
		if(this.dialogs[txt+this.dian]!=undefined){			
			var tx=this.dialogs[txt+this.dian].toLowerCase();
			var line=0;
			var posi=0
			var mj=0;
			if(this.prom<10){
				this.prom++;
			}else{
				this.prom=0;
			}
			this.canv.save();
			if(alpha!=undefined){
				this.canv.globalAlpha=alpha;
			}else{
				this.canv.globalAlpha=0.6;
			}
			
			this.canv.drawImage(this.fukidasi,x-2,y-2);				
			
			for(var i=this.leposi;i<=tx.length;i++){			
				for(var j=0;j*this.width<this.font.width;j++){				
					if(tx.charAt(i)==this.letters[j]){
						if(posi>0){							
							posi+=4;
						}else{
							if(tx.charAt(i-1)=='。'||tx.charAt(i-1)=='！'||tx.charAt(i-1)=='、'||tx.charAt(i-1)=='ょ'||tx.charAt(i-1)=='1'||tx.charAt(i-1)=='（'||tx.charAt(i-1)=='）'||tx.charAt(i-1)=='：'||tx.charAt(i-1)=="「"||tx.charAt(i-1)=="」"){
								if(mj!=0){
									posi+=4;
								}
							}
						}						
						this.canv.drawImage(this.font,j*this.width,0,this.width,this.height,x+posi,y+(line*this.height),this.width,this.height);
						if(tx.charAt(i)=='ま'||tx.charAt(i)=='し'||tx.charAt(i)=='よ'||tx.charAt(i)=='し'||tx.charAt(i)=='ち'||tx.charAt(i)=='り'||tx.charAt(i)=='さ'||tx.charAt(i)=='そ'||tx.charAt(i)=='ら'||tx.charAt(i)=='き'||tx.charAt(i)=='こ'||tx.charAt(i)=='ゅ'||tx.charAt(i)=='よ'||tx.charAt(i)=='っ'||tx.charAt(i)=='ぇ'||tx.charAt(i)=='た'||tx.charAt(i)=='ー'){
							posi-=1;
						}else if(tx.charAt(i)=='き'||tx.charAt(i)=='ひ'){							
							if(tx.charAt(i+1)=='ゃ'||tx.charAt(i+1)=='ゅ'||tx.charAt(i+1)=='ょ'){							
								posi-=1;							
							}
						}else　if(j>=46&j<=70){
							if(tx.charAt(i)=='ぐ'){
								posi+=1;
							}else if(tx.charAt(i)=='じ'){
								posi-=1;
							}else{
								if(tx.charAt(i)=='び'||tx.charAt(i)=='ぴ'||tx.charAt(i)=='ぎ'){							
									if(tx.charAt(i+1)=='ゃ'||tx.charAt(i+1)=='ゅ'||tx.charAt(i+1)=='ょ'){							
										posi+=1;							
									}else{
										posi+=2;
									}
								}else{
									posi+=2;
								}
							}							
						}else if(tx.charAt(i)=="？"){							
								posi-=2;							
						}else if(tx.charAt(i)=='ゃ'||tx.charAt(i)=='く'||tx.charAt(i)=='ぉ'||tx.charAt(i)=='ぃ'||tx.charAt(i)=='ぅ'||tx.charAt(i)=='ぁ'){
							posi-=2;
						}else if(tx.charAt(i)=='ょ'||tx.charAt(i)=="。"||tx.charAt(i)=="（"||tx.charAt(i)=="）"||tx.charAt(i)=="「"||tx.charAt(i)=="」"){							
							posi-=3;
						}else if(tx.charAt(i)=="、"||tx.charAt(i)=="！"){														
							posi-=4;																						
						}else if(tx.charAt(i)=='：'){
							posi-=5;
						}else if(j>=78&j<=87){
							posi-=2;
							if(j==79){
								posi-=1;
							}
						}else if(tx.charAt(i)=='ぬ'||tx.charAt(i)=='ね'||tx.charAt(i)=='の'||tx.charAt(i)=='め'||tx.charAt(i)=='ゆ'||tx.charAt(i)=='や'||tx.charAt(i)=='わ'||tx.charAt(i)=='ん'||tx.charAt(i)=='か'||tx.charAt(i)=='れ'||tx.charAt(i)=='み'){
							posi+=1;
						}else if(tx.charAt(i)=="な"||tx.charAt(i)=="ふ"){
							posi+=2;
						}
					}											
				}
				
				mj++;				
				if(i>=tx.length-1){				
					this.tleposi=0;					
					if(this.dialogs[txt+(this.dian+1)]==undefined){
						this.nx=false;
					}else{
						this.nx=true;						
					}
					if(posi+(this.width+6)>=nagasa){
						line++;
						mj=0;							
						posi=0;						
					}else{
						posi+=2;					
					}					
				}else{	
					this.nx=true;
					if(posi+(this.width*3)>=nagasa&line*(this.height*2)>=takasa){								
						this.tleposi=i+1;
						i=tx.length;				
						posi+=4;								
					}else if(posi+(this.width+6)>=nagasa){
						line++;
						mj=0;
						if(line*this.height>=takasa){										
							i=tx.length;												
						}
						posi=0;						
					}else{
						posi+=3;					
					}					
				}				
			}		
			if(this.prom>5){
				if(this.tleposi==0&this.dialogs[txt+(this.dian+1)]==undefined){			
					this.canv.drawImage(this.font,this.sto*this.width,0,this.width,this.height,x+(posi+4),y+(line*this.height),this.width,this.height);
				}else{
					this.canv.drawImage(this.font,this.nex*this.width,0,this.width,this.height,x+posi+4,y+(line*this.height),this.width,this.height);
				}
			}	
			this.canv.restore();
			line=0;					
		}
	}
	koto(txt,x,y,nagasa,takasa,arufa){			
		this.ttx=txt.length;		
		var tx=txt.toLowerCase();
		var line=0;
		var posi=0
		var mj=0;
		if(arufa==undefined){
			arufa=0.9;
		}
		this.canv.save();		
		this.canv.globalAlpha=arufa;
		
		for(var i=this.leposi;i<=tx.length;i++){			
			for(var j=0;j*this.width<this.font.width;j++){				
				if(tx.charAt(i)==this.letters[j]){
					if(posi>0){							
						posi+=4;
					}else{
						if(tx.charAt(i-1)=='。'||tx.charAt(i-1)=='！'||tx.charAt(i-1)=='、'||tx.charAt(i-1)=='ょ'||tx.charAt(i-1)=='1'||tx.charAt(i-1)=='（'||tx.charAt(i-1)=='）'||tx.charAt(i-1)=='：'||tx.charAt(i-1)=="「"||tx.charAt(i-1)=="」"){
							if(mj!=0){
								posi+=4;
							}
						}
					}						
					this.canv.drawImage(this.font,j*this.width,0,this.width,this.height,x+posi,y+(line*this.height),this.width,this.height);
					if(tx.charAt(i)=='ま'||tx.charAt(i)=='し'||tx.charAt(i)=='よ'||tx.charAt(i)=='し'||tx.charAt(i)=='ち'||tx.charAt(i)=='り'||tx.charAt(i)=='さ'||tx.charAt(i)=='そ'||tx.charAt(i)=='ら'||tx.charAt(i)=='き'||tx.charAt(i)=='こ'||tx.charAt(i)=='ゅ'||tx.charAt(i)=='よ'||tx.charAt(i)=='っ'||tx.charAt(i)=='ぇ'||tx.charAt(i)=='た'||tx.charAt(i)=='ー'){
						posi-=1;
					}else if(tx.charAt(i)=='き'||tx.charAt(i)=='ひ'){							
						if(tx.charAt(i+1)=='ゃ'||tx.charAt(i+1)=='ゅ'||tx.charAt(i+1)=='ょ'){							
							posi-=1;							
						}
					}else　if(j>=46&j<=70){
						if(tx.charAt(i)=='ぐ'){
							posi+=1;
						}else if(tx.charAt(i)=='じ'){
							posi-=1;
						}else{
							if(tx.charAt(i)=='び'||tx.charAt(i)=='ぴ'||tx.charAt(i)=='ぎ'){							
								if(tx.charAt(i+1)=='ゃ'||tx.charAt(i+1)=='ゅ'||tx.charAt(i+1)=='ょ'){							
									posi+=1;							
								}else{
									posi+=2;
								}
							}else{
								posi+=2;
							}
						}							
					}else if(tx.charAt(i)=="？"){							
							posi-=2;							
					}else if(tx.charAt(i)=='ゃ'||tx.charAt(i)=='く'||tx.charAt(i)=='ぉ'||tx.charAt(i)=='ぃ'||tx.charAt(i)=='ぅ'||tx.charAt(i)=='ぁ'){
						posi-=2;
					}else if(tx.charAt(i)=='ょ'||tx.charAt(i)=="。"||tx.charAt(i)=="（"||tx.charAt(i)=="）"||tx.charAt(i)=="「"||tx.charAt(i)=="」"){							
						posi-=3;
					}else if(tx.charAt(i)=="、"||tx.charAt(i)=="！"){														
						posi-=4;																						
					}else if(tx.charAt(i)=='：'){
						posi-=5;
					}else if(j>=78&j<=87){
						posi-=2;
						if(j==79){
							posi-=1;
						}
					}else if(tx.charAt(i)=='ぬ'||tx.charAt(i)=='ね'||tx.charAt(i)=='の'||tx.charAt(i)=='め'||tx.charAt(i)=='ゆ'||tx.charAt(i)=='や'||tx.charAt(i)=='わ'||tx.charAt(i)=='ん'||tx.charAt(i)=='か'||tx.charAt(i)=='れ'||tx.charAt(i)=='み'){
						posi+=1;
					}else if(tx.charAt(i)=="な"||tx.charAt(i)=="ふ"){
						posi+=2;
					}
				}											
			}
			
			mj++;				
			if(i>=tx.length){				
				this.tleposi=0;									
			}else{					
				if(posi+(this.width*3)>=nagasa&line*(this.height*2)>=takasa){								
					this.tleposi=i+1;
					i=tx.length;				
					posi+=4;								
				}else if(posi+(this.width+6)>=nagasa){
					line++;
					mj=0;
					if(line*this.height>=takasa){										
						i=tx.length;												
					}
					posi=0;						
				}else{
					posi+=3;					
				}					
			}				
		}				
		this.canv.restore();
		line=0;					
		
	}
}

class BalloonEn{
	constructor(fonts,width,height,canv){
		this.font=document.createElement('img');
		this.font.src=fonts;
		this.width=width;
		this.height=height;
		this.canv=canv;		
		this.prom=0;		
		this.posi=0;
		this.leposi=0;
		this.tleposi=0;
		this.dian=1;
		this.dialogs=new Array();
		this.diav=false;
		this.nx=true;
		this.ttx;		
	}	
	fukif(fukidasi){
		this.fukidasi=document.createElement('img');
		this.fukidasi.src=fukidasi;
	}
	letter(l,nex,sto){
		this.letters=l;
		this.nex=nex;
		this.sto=sto;
	}	
	dialog(d){
		this.dialogs=d;		
	}
	next(){		
		if(this.tleposi!=0&this.tleposi<this.ttx){
			this.leposi=this.tleposi;
		}else{
			this.dian++;
			this.leposi=0;	
		}		
	}
	reset(){		
		this.dian=1;
		this.leposi=0;		
		this.nx=true;
	}
	seri(txt,x,y,nagasa,takasa,alpha){		
		this.ttx=this.dialogs[txt+this.dian].length;
		if(this.dialogs[txt+(this.dian+1)]==undefined){
			this.diav=false;
		}else{
			this.diav=true;
		}		
		if(this.dialogs[txt+this.dian]!=undefined){			
			var tx=this.dialogs[txt+this.dian].toLowerCase();
			var line=0;
			var posi=0;
			var mj=0;
			if(this.prom<10	){
				this.prom++;
			}else{
				this.prom=0;
			}
			this.canv.save();
			if(alpha!=undefined){
				this.canv.globalAlpha=alpha;
			}else{
				this.canv.globalAlpha=0.6;			
			};
			this.canv.drawImage(this.fukidasi,x-2,y-2);	
			
			for(var i=this.leposi;i<=tx.length;i++){			
				for(var j=0;j*this.width<this.font.width;j++){				
					if(tx.charAt(i)==this.letters[j]){											
						if(posi>0){
							posi+=2;			
						}else{
							if(tx.charAt(i-1)=='!'||tx.charAt(i-1)==','||tx.charAt(i-1)=='.'||tx.charAt(i-1)=="'"||tx.charAt(i-1)==':'||tx.charAt(i-1)=='-'){
							 if(mj!=0){
								posi+=2;								
							 }
							}
						}
						
						if(tx.charAt(i)=='m'||tx.charAt(i)=='w'){
							posi+=1;
						}else if(tx.charAt(i)=='!'||tx.charAt(i)==','||tx.charAt(i)=="'"||tx.charAt(i)=="."){
							posi-=1;
						}
						this.canv.drawImage(this.font,j*this.width,0,this.width,this.height,x+posi,y+(line*this.height),this.width,this.height);
						if(tx.charAt(i)=='m'||tx.charAt(i)=='n'||tx.charAt(i)=='w'){
							posi+=1;
						}else if(tx.charAt(i)=='!'||tx.charAt(i)==','||tx.charAt(i)=='1'||tx.charAt(i)=="'"||tx.charAt(i)=="."||tx.charAt(i)=='-'){
							posi-=1;
						}else if(tx.charAt(i)==':'){
							posi-=2;
						}
					}						
				}
				mj++;
				if(i>=tx.length-1){						
					this.tleposi=0;
					if(this.dialogs[txt+(this.dian+1)]==undefined){
						this.nx=false;
					}else{
						this.nx=true;
					}
					if(posi+(this.width+(this.width/2))>=nagasa){
						line++;
						mj=0;						
						posi=0;					
					}else{
						posi+=2;			
					}
				}else{
					this.nx=true;					
					if(posi+(this.width*3)>=nagasa&line*(this.height*2)>=takasa){								
							this.tleposi=i+1;
							i=tx.length;				
							posi+=4;		
							
					}else if(posi+(this.width+(this.width/2))>=nagasa){
						line++;
						mj=0;
						if(line*this.height>=takasa){										
							i=tx.length;											
						}
						posi=0;					
					}else{
						posi+=2;			
					}
				}				
			}		
			if(this.prom>5){
				if(this.tleposi==0&this.dialogs[txt+(this.dian+1)]==undefined){			
					this.canv.drawImage(this.font,this.sto*this.width,0,this.width,this.height,x+(posi-1),y+(line*this.height),this.width,this.height);
				}else{
					this.canv.drawImage(this.font,this.nex*this.width,0,this.width,this.height,x+posi,y+(line*this.height),this.width,this.height);				
				}
			}		
			this.canv.restore();
			line=0;		
		}		
	}	
	koto(txt,x,y,nagasa,takasa,arufa){		
		this.ttx=txt.length;		
		var tx=txt.toLowerCase();
		var line=0;
		var posi=0;
		var mj=0;		
		this.canv.save();
		if(arufa==undefined){
			arufa=0.9
		}
		this.canv.save();	
		this.canv.globalAlpha=arufa;				
		for(var i=this.leposi;i<=tx.length;i++){			
			for(var j=0;j*this.width<this.font.width;j++){				
				if(tx.charAt(i)==this.letters[j]){											
					if(posi>0){
						posi+=2;			
					}else{
						if(tx.charAt(i-1)=='!'||tx.charAt(i-1)==','||tx.charAt(i-1)=='.'||tx.charAt(i-1)=="'"||tx.charAt(i-1)==':'||tx.charAt(i-1)=='-'){
						 if(mj!=0){
							posi+=2;								
						 }
						}
					}					
					if(tx.charAt(i)=='m'||tx.charAt(i)=='w'){
						posi+=1;
					}else if(tx.charAt(i)=='!'||tx.charAt(i)==','||tx.charAt(i)=="'"||tx.charAt(i)=="."){
						posi-=1;
					}
					this.canv.drawImage(this.font,j*this.width,0,this.width,this.height,x+posi,y+(line*this.height),this.width,this.height);
					if(tx.charAt(i)=='m'||tx.charAt(i)=='n'||tx.charAt(i)=='w'){
						posi+=1;
					}else if(tx.charAt(i)=='!'||tx.charAt(i)==','||tx.charAt(i)=='1'||tx.charAt(i)=="'"||tx.charAt(i)=="."||tx.charAt(i)=='-'){
						posi-=1;
					}else if(tx.charAt(i)==':'){
						posi-=2;
					}
				}						
			}
			mj++;
			if(i>=tx.length){						
				this.tleposi=0;				
			}
			if(posi+(this.width*3)>=nagasa&line*(this.height*2)>=takasa){								
					this.tleposi=i+1;
					i=tx.length;				
					posi+=4;		
					
				}else if(posi+(this.width+(this.width/2))>=nagasa){
					line++;
					mj=0;
					if(line*this.height>=takasa){										
						i=tx.length;											
					}
					posi=0;					
				}else{
					posi+=2;			
				}
			
		}				
		this.canv.restore();
		line=0;						
	}		
}

var waku=new Object();
waku.gen='jp';
waku.jou='menu';
waku.size=3;
waku.yoko=window.innerWidth;
waku.tate=window.innerHeight;
waku.cayo=130;
waku.cata=110;
waku.bgm=true;
waku.scn=1;
waku.scnt=2;

var nez={x:0,y:0,osu:false,osuc:0};

var canvas=document.createElement('canvas');
document.body.appendChild(canvas);
canvas.style.borderRadius='10px';
canvas.style.position='absolute';
canvas.width=waku.cayo*waku.size;
canvas.height=waku.cata*waku.size;
canvas.style.left=(waku.yoko/2)-(canvas.width/2);
canvas.style.top=(waku.tate/2)-(canvas.height/2);
var can=canvas.getContext('2d')
can.imageSmoothingEnabled=false;
can.scale(waku.size,waku.size);
can.fillStyle='#551155';
can.fillRect(0,0,500,500);

//sounds
var bgm=new Audio('wan/bgm.wav');
bgm.loop=true;
bgm.volume=0.5;
var kuri=new Oto('wan/click.wav');
var sban=new Oto('wan/ban.wav');
var snuchu=new Oto('wan/nuchu.wav');

//sprites
var bgmenu=new Dotto('menu',130,110,'wan/bg_menu.png',can);
bgmenu.x=0;bgmenu.x2=0;
var itbut=new Dotto('buttons',10,10,'wan/item_buttons.png',can);

var bgkouen=new Dotto('menu',130,110,'wan/bg_kouen.png',can);
var bgkouencar=new Dotto('menu',108,28,'wan/bg_kouen-car.png',can);
bgkouencar.x=120;bgkouencar.y=28;
var ol=new Dotto('ol',60,60,'wan/ol.png',can);
var sarari=new Dotto('sarari',60,60,'wan/sarari.png',can);
var ol1=new Dotto('ol',60,60,'wan/ol1.png',can);
ol1.oto(snuchu,1);ol1.oto(sban,4);

var bgerufu=new Dotto('bg_forest',130,110,'wan/bg_erufu.png',can);
var erufu=new Dotto('erufu',60,60,'wan/erufu.png',can);
var gobu=new Dotto('gobu',60,60,'wan/gobu.png',can);
var sura=new Dotto('sura',60,60,'wan/suraimu.png',can);
var sura2=new Dotto('sura',60,60,'wan/suraimu.png',can);
sura.x=200;sura.y=25;

//areas
var hibgm=new Hitto(120,1,129,10);
var hinex=new Hitto(120,11,129,20);
var hipre=new Hitto(120,21,129,30);
var hime=new Hitto(120,41,129,50);

var hist=new Hitto(44,76,89,84);
var hiscpu=new Hitto(80,87,90,96);
var hiscmi=new Hitto(40,87,50,96);
var hijp=new Hitto(9,98,66,109);
var hien=new Hitto(67,98,121,109);
//
//moji
var logs=new Array();
var letter=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','.',',','!','?',"'",'1','2','3','4','5','6','7','8','9','0','(',')',':','-'];
var moji=['あ','い','う','え','お','か','き','く','け','こ','さ','し','す','せ','そ','た','ち','つ','て','と','な','に','ぬ','ね','の','は','ひ','ふ','へ','ほ','ま','み','む','め','も','や','ゆ',"よ",'ら','り','る','れ','ろ','わ','を','ん','が','ぎ','ぐ','げ','ご','ざ','じ','ず','ぜ','ぞ','だ','ぢ','づ','で','ど','ば','び','ぶ','べ','ぼ','ぱ','ぴ','ぷ','ぺ','ぽ','ゃ','ゅ','ょ','。','、','！','？','0','1','2','3','4','5','6','7','8','9','っ','ぁ','ぃ','ぅ','ぇ','ぉ','（','）','「','」','：','ー'];
var hira=new Balloon('wan/hira.png',8,7,can);
hira.letter(moji,100,74);
hira.dialog(logs);
hira.fukif('wan/item_balloon.png');

var hirab=new Balloon('wan/hira.png',8,7,can);
hirab.letter(moji,100,74);
hirab.fukif('wan/item_balloon.png');

var roma=new BalloonEn('wan/alpha.png',5,7,can);
roma.letter(letter,45,26);
roma.dialog(logs);
roma.fukif('wan/item_balloon.png');

var romab=new BalloonEn('wan/alpha.png',5,7,can);
romab.letter(letter,45,26);
romab.fukif('wan/item_balloon.png');

var se=hira;
var ko=hirab;
logs['1jp1']='さらりーまんと　こうはいちゃん';
logs['1jp2']='しごとごの　のみにけーしょんから　ぬけだして　ちかくの　こうえんで　ふたりきりの　せんぱい　こうはい';
logs['1jp3']='せんぱい：　（にやにや　さいきん　はいった　この　しんじん　めっちゃ　かわいくて　おっぱいも　でかい！）';
logs['1jp4']='せんぱい：　（さっき　いっぱい　のませたし　ちょうどいい　ぐあい、なにを　しても　あしたは　ぜんぜん　おぼえてない　はず！）';
logs['1jp5']='こうはいちゃん：　（にこにこ　せんぱい　かっこよくて。。。）';
logs['1jp6']='こうはいちゃん：　（ずっと　はずかしくて　こっちから　ぜんぜん　いけないけど。。。さすが　せんぱい　りーど　してくれる。。。）';
logs['1jp7']='こうはいちゃん：　（きょう　やれるかな？　むらむら）';
logs['1en1']="Veteran office worker and his younger co-worker";
logs['1en2']="A 'senpai' and 'kouhai' that sneaked out of a co-workers after work party and now are at a public park";
logs['1en3']="Senpai: (smirks Man this new girl is so cute and look at those boobies!)";
logs['1en4']="Senpai: (I gave her a lot of booze and now she's so drunk she won't remember a thing I do...)";
logs['1en5']="Kouhai-chan: (Oh 'senpai' is so handsome..)";
logs['1en6']="Kouhai-chan: (I was so embarrassed I couldn't say a thing but 'senpai' took the initiative, he's so reliable...)";
logs['1en7']="Kouhai-chan: (I wonder if We're doing 'it' today? blushes)";

logs['1jp8']='こうはいちゃん：　あああ　せんぱいの　ちんこ　きもちいい！！';
logs['1jp9']='せんぱい：　（やばい　このこ　すけべすぎ！　こうえんなのに　めっちゃ　さけんでる！）';
logs['1jp10']='せんぱい：　（いけそう　だったから　ちょっと　さわったら　じぶんから　ふく　ぬいだり　のってくるんだあ！）';
logs['1en8']="Kouhai-chan: Ohh gosh 'senpai's cock is feels so good!!!";
logs['1en9']="Senpai: (Man this girl is fire! We're at a public park but she's yelling!)";
logs['1en10']="Senpai: (I had a chance so I touched her and suddenly she took her clothes off and fucked me!!)";

logs['2jp1']='えるふ　と　ごぶりん';
logs['2jp2']='えるふ：　この　いらい　かんたん　すぎて　ひとりで　きた！　この　へんで　あばれてる　1ぴきの　ごぶりんを　たおすだけ';
logs['2en1']="Elf and Goblin";
logs['2en2']="Elf: This is such an easy quest I just came by myself! I have to defeat a goblin that is messing around here";

logs['2jp3']='ごぶりんが　あらわれた！';
logs['2jp4']='えるふ：　おもった　とおり　よわそうー　わら';
logs['2jp5']='ごぶりん：　おれ　つよいよ、　まけると　おもう';
logs['2jp6']='えるふ：　おもしろい　じょうだん　いいますね　はっはっはぁ！　じゃぁさー　まけたら　いくらでも　えっち　してあげるよ';
logs['2en3']="Goblin appears!";
logs['2en4']="Elf: Just like I thought it looks so weak :D";
logs['2en5']="Goblin: I'm strong, you'll probably lose";
logs['2en6']="Elf: Your jokes are funny hahaha! Ok, if you win I'll have sex with you how many times you wish!";

logs['2jp7']='たいけんばんを　ぷれいして　ありがとう　ございます';

logs['2en7']="Thank you for playing the Trial version";

//functions
function zero(){
	ol1.koma=0;	
};
function egaku(){	
	can.fillStyle='#551155';	
	can.fillRect(0,0,500,500);
	
	if(waku.jou=='menu'){
		bgmenu.haikei(0,0);		
		bgmenu.x2-=1;
		if(bgmenu.x2<-bgmenu.yoko){
			bgmenu.x2=150;
		}
		bgmenu.haikei(bgmenu.x2,0,0,12);
		bgmenu.haikei(0,0,0,1);		
		bgmenu.x-=2;
		if(bgmenu.x<-bgmenu.yoko+25){
			bgmenu.x=0;
		}
		bgmenu.haikei(bgmenu.x,0,0,2);		
		bgmenu.haikei(bgmenu.x+(bgmenu.yoko-25),0,0,2);		
		
		if(hist.c(nez.x,nez.y)){
			if(waku.gen=='jp'){
				bgmenu.haikei(0,0,0,4);
			}else{
				bgmenu.haikei(0,0,0,11);
			}
		}else {
			if(waku.gen=='jp'){
				bgmenu.haikei(0,0,0,3);
			}else{
				bgmenu.haikei(0,0,0,10);
			}
		}
		
		if(hijp.c(nez.x,nez.y)){
			bgmenu.haikei(0,0,0,6);
		}else if(hien.c(nez.x,nez.y)){
			bgmenu.haikei(0,0,0,7);
		}else{
			bgmenu.haikei(0,0,0,5);
		}
		
		if(waku.gen=='jp'){
			bgmenu.haikei(0,0,0,8);	
		}else{
			bgmenu.haikei(0,0,0,9);	
		}
		
		if(hiscpu.c(nez.x,nez.y)){
			itbut.kyara(85,96,0,3)			
		}else{
			can.save();
			can.globalAlpha=0.7;
			itbut.kyara(85,96,0,2)
			can.restore();
		}
		if(waku.gen=='jp'){
			hirab.koto('がめん',53,86,122,14,0.7);
		}else{
			romab.koto('screen',52,87,122,14,0.7);
		}
		if(hiscmi.c(nez.x,nez.y)){
			itbut.kyara(45,96,0,5)			
		}else{
			can.save();
			can.globalAlpha=0.7;
			itbut.kyara(45,96,0,4)
			can.restore();
		}		
		
		romab.koto('Hoodie Corp 2026',68,1,122,14,0.7);
	}else{
		if(waku.scn==1){
			bgkouen.haikei(0,0);			
			bgkouencar.ani(bgkouencar.x,bgkouencar.y);
			bgkouencar.x-=15;
			if(bgkouencar.x<-700){
				bgkouencar.x=200;
			}			
			bgkouen.haikei(0,0,0,1);
			ol.kyara(78,64,2)
			ol.kyara(43,64,2)
			bgkouen.haikei(0,0,0,2);
			if(se.dian<8){
				bgkouen.haikei(0,0,0,3);
				ol.talk(78,64,1)
				sarari.talk(43,65,1)
			}else{
				ol1.ani(102,86)
			}			
			bgkouen.haikei(0,0,0,4);
		}else {
			bgerufu.haikei(0,0);
			bgerufu.haikei(0,0,0,1);
			can.save();
			can.globalAlpha=0.6;
			sura.ani(sura.x,sura.y)			
			sura2.ani(sura.x-80,sura.y+10)
			can.restore();
			if(sura.koma==5){
				sura.x-=6;
			}else if(sura.koma==0){
				sura.x-=3;
			}
			if(sura.x<-50){
				sura.x=200;
			}
			
			if(se.dian<3){
				erufu.talk(40,59,1);
			}else {
				erufu.talk(45,64,2);
				gobu.talk(73,95,1);
			}
			
			bgerufu.haikei(0,0,0,2);
		}
		
		se.seri(''+waku.scn+waku.gen,3,92,122,14,0.7);
		
		if(hibgm.c(nez.x,nez.y)){			
			itbut.kyara(125,10,0,1)
		}else{
			can.save();
			can.globalAlpha=0.7;
			itbut.kyara(125,10,0,0)
			can.restore();
		}		
		if(hinex.c(nez.x,nez.y)){			
			itbut.kyara(125,20,0,9)
		}else{
			can.save();
			can.globalAlpha=0.7;
			itbut.kyara(125,20,0,8)
			can.restore();
		}		
		if(hipre.c(nez.x,nez.y)){			
			itbut.kyara(125,30,0,11)
		}else{
			can.save();
			can.globalAlpha=0.7;
			itbut.kyara(125,30,0,10)
			can.restore();
		}		
		can.save();
		can.globalAlpha=0.9;
		itbut.kyara(125,40,0,12)
		can.restore();
		romab.koto(''+waku.scn,121,31,122,14,0.7);
		
		if(hime.c(nez.x,nez.y)){
			itbut.kyara(125,50,0,7)
		}else{
			can.save();
			can.globalAlpha=0.7;
			itbut.kyara(125,50,0,6)
			can.restore();
		}		
	}
	
	if(nez.osu){
		nez.osuc++;
		if(nez.osuc>=3){
			nez.osuc=0;
			nez.osu=false;
		}
	}
};
onmousemove=function(e){
	if(e.clientX<=parseInt(canvas.style.left)){
		nez.x=0;
	}else if(Math.floor((e.clientX-parseInt(canvas.style.left))/waku.size)>waku.cayo){
		nez.x=waku.cayo;
	}else{
		nez.x=Math.floor((e.clientX-parseInt(canvas.style.left))/waku.size);
	}
	if(e.clientY<=parseInt(canvas.style.top)){
		nez.y=0;
	}else if(Math.floor((e.clientY-parseInt(canvas.style.top))/waku.size)>waku.cata){
		nez.y=waku.cata;
	}else{
		nez.y=Math.floor((e.clientY-parseInt(canvas.style.top))/waku.size);
	};
}

onmousedown=function(e){
	waku.yoko=window.innerWidth;
	waku.tate=window.innerHeight;
	canvas.style.left=(waku.yoko/2)-(canvas.width/2);
	canvas.style.top=(waku.tate/2)-(canvas.height/2);
	
	if(e.clientX<=parseInt(canvas.style.left)){
		nez.x=0;
	}else if(Math.floor((e.clientX-parseInt(canvas.style.left))/waku.size)>waku.cayo){
		nez.x=waku.cayo;
	}else{
		nez.x=Math.floor((e.clientX-parseInt(canvas.style.left))/waku.size);
	}
	if(e.clientY<=parseInt(canvas.style.top)){
		nez.y=0;
	}else if(Math.floor((e.clientY-parseInt(canvas.style.top))/waku.size)>waku.cata){
		nez.y=waku.cata;
	}else{
		nez.y=Math.floor((e.clientY-parseInt(canvas.style.top))/waku.size);
	};	
	kuri.p();
	
	if(!nez.osu){		
		if(waku.jou=='menu'){			
			if(hiscpu.c(nez.x,nez.y)){
				if(waku.cayo*(waku.size+1)<waku.yoko&waku.cata*(waku.size+1)<waku.tate){
					waku.size++;
				}
				canvas.width=waku.cayo*waku.size;
				canvas.height=waku.cata*waku.size;
				canvas.style.left=(waku.yoko/2)-(canvas.width/2);
				canvas.style.top=(waku.tate/2)-(canvas.height/2);				
				can.imageSmoothingEnabled=false;
				can.scale(waku.size,waku.size);
			}else if(hiscmi.c(nez.x,nez.y)){
				if(waku.size>1){
					waku.size--;
				}
				canvas.width=waku.cayo*waku.size;
				canvas.height=waku.cata*waku.size;
				canvas.style.left=(waku.yoko/2)-(canvas.width/2);
				canvas.style.top=(waku.tate/2)-(canvas.height/2);				
				can.imageSmoothingEnabled=false;
				can.scale(waku.size,waku.size);
			}else if(hijp.c(nez.x,nez.y)){
				waku.gen='jp';
				se=hira;
				document.title='ワンシーンアソート　体験版';
			}else if(hien.c(nez.x,nez.y)){
				waku.gen='en';
				se=roma;
				document.title='Assorted 1scenes Trial Version';
			}else if(hist.c(nez.x,nez.y)){
				nez.osu=true;
				if(waku.bgm){				
					bgm.play();
				}
				waku.jou='girls';			
			};
		}else{
			if(hibgm.c(nez.x,nez.y)){
				if(waku.bgm){
					waku.bgm=false;
					bgm.pause();
				}else{
					waku.bgm=true;
					bgm.play();
				}
			}else if(hime.c(nez.x,nez.y)){				
				nez.osu=true;
				waku.jou='menu';
				zero();
			}else if(hinex.c(nez.x,nez.y)){				
				if(waku.scn<waku.scnt){
					waku.scn++;
				}else{
					waku.scn=1;
					zero();
				}
				se.reset();
			}else if(hipre.c(nez.x,nez.y)){
				if(waku.scn>1){
					waku.scn--;
					zero();
				}else{							
					waku.scn=waku.scnt;
					zero();
				}
				se.reset();
			}else{
				if(se.nx){
					se.next();
				}else{
					se.reset();
					zero();
				}
				
			}
		}
	}
};
window.onload=function(){			
	var egaF=setInterval(egaku,100);			
}