var z=new Object();
z.tate=window.innerHeight;
z.yoko=window.innerWidth;
z.gt=100;
z.gy=120;
z.scal=2;
z.x;
z.y;
z.gen='jp';
z.hx=0;
z.hy=0;
z.bgm=true;
var sute={t:'',p:'menu',gu:'',ba:'',seri:''};
var nezu={x:0,y:0};
var feido={suta:'null',count:0};

var ani={ani:1,scent:1,scen:1,ani1:9};

//class
class Renda{
	constructor(s,n,w,h,g){
		this.img=document.createElement('img');
		this.img.src=s;
		this.namae=n;		
		this.tate=h;
		this.yoko=w;
		this.koma=0;
		this.ca=g;
		this.otos=new Array();
		this.count=0;
	}
	oto(o){
		for(var i=0;i<arguments.length;i++){
			if(i>0){
				if(this.otos[arguments[i]]==undefined){
					this.otos[arguments[i]]=new Array();
					this.otos[arguments[i]].push(o);
				}else{
					this.otos[arguments[i]].push(o);
				}				
			}
			
		}
	}
	
	kyara(x,y,line,col){
		if(line==undefined){
			line=0;
		}
		if(col==undefined){
			col=0;
		}
		this.ca.drawImage(this.img,col*this.yoko,line*this.tate,this.yoko,this.tate,x-(this.yoko/2),y-this.tate,this.yoko,this.tate);
	}
	wink(x,y,line){
		if(line==undefined){
			line=0;
		}
		var ran=Math.floor(Math.random()*15)
		if(ran==0){
			this.koma=1;
		}else{
			this.koma=0;
		}			
		this.ca.drawImage(this.img,this.koma*this.yoko,line*this.tate,this.yoko,this.tate,x-(this.yoko/2),y-this.tate,this.yoko,this.tate);
	}
	talk(x,y,line){
		if(line==undefined){
			line=0;
		}
		var ran=Math.floor(Math.random()*20)
		if(ran==0){
			this.koma=1;
		}else if(ran<6){
			this.koma=2;
		}else{
			this.koma=0;
		}			
		this.ca.drawImage(this.img,this.koma*this.yoko,line*this.tate,this.yoko,this.tate,x-(this.yoko/2),y-this.tate,this.yoko,this.tate);
	}
	
	anime(x,y,line,repeat,talk){
		if(line==undefined){
			line=0;
		}
		
		if(talk&this.koma>=repeat){
			var ran=Math.floor(Math.random()*20)
			if(ran==0){
				this.koma=repeat+1;
			}else if(ran<6){
				this.koma=repeat+2;
			}else{
				this.koma=repeat;
			}			
		}else{
			if(this.koma*this.yoko>=this.img.width){
				if(repeat==undefined){
					this.koma=0;
				}else{				
					this.koma=repeat;				
				}
			}	
		}
		if(this.otos[this.koma]!=undefined){
			for(var ba=0;ba<this.otos[this.koma].length;ba++){
				this.otos[this.koma][ba].p();				
			}
		}
		this.ca.drawImage(this.img,this.koma*this.yoko,line*this.tate,this.yoko,this.tate,x-(this.yoko/2),y-this.tate,this.yoko,this.tate);
		this.koma++;				
	}
	walk(x,sy,ex,sutepu,houkou,line){
		if(line==undefined){
			line=0;
		}
		if(this.x==undefined){
			this.x=x;
		}
		if(y==undefined){
			this.y=sy;
			var y=this.y;
		}
		if(sutepu==undefined){
			sutepu=1;
		}
		if(houkou==undefined){
			this.houkou='migi';
		}		
		if(this.otos[this.koma]!=undefined){
			for(var ba=0;ba<this.otos[this.koma].length;ba++){
				this.otos[this.koma][ba].p();				
			}
		}
		this.ca.drawImage(this.img,this.koma*this.yoko,line*this.tate,this.yoko,this.tate,this.x-(this.yoko/2),this.y-this.tate,this.yoko,this.tate);
		this.koma++;				
		if(this.koma*this.yoko>=this.img.width){
			this.koma=0;
		}
		if(this.houkou=='migi'){
			if(this.koma==1|this.koma==3){
				this.x+=sutepu;				
			}else{
				this.x+=Math.floor(sutepu/2);
			}
			if(this.x>ex){
				this.houkou='hidari';
			}
		}else{
			if(this.koma==1|this.koma==3){
				this.x-=sutepu;			
			}else{
				this.x-=Math.floor(sutepu/2);
			}
			if(this.x<x){
				this.houkou='migi';
			}
		}
		
	}
	
	haikei(x,y,line,col){
		if(line==undefined){
			line=0;
		}		
		if(col==undefined){
			col=0;
		}				
		this.ca.drawImage(this.img,col*this.yoko,line*this.tate,this.yoko,this.tate,x,y,this.yoko,this.tate);
	}
}

class Oto{
	constructor(s){
		this.oto=new Audio(s);								
		this.oto1=new Audio(s);
		this.oto1.volume=0.7;
	};
	p(){
		if(this.oto.currentTime==this.oto.duration|this.oto.currentTime==0){
			this.oto.play();
		}else if(this.oto1.currentTime==this.oto1.duration|this.oto1.currentTime==0){
			this.oto1.play();
		}
	};
};
class Osu{
	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;
		};
	};
	d(x,y){
		if(y>=this.y1&y<=this.y2){
			let min=y-this.y1;
			let max=this.y2-y;
			if(x>=this.x1-min&x<=this.x2+max){
				return true;
			}else{
				return false;
			}
			
		}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){			
		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();
			this.canv.globalAlpha=0.6;
			
			this.canv.drawImage(this.fukidasi,x-4,y-3);				
			
			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){		
		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();
			this.canv.globalAlpha=0.6;			
			this.canv.drawImage(this.fukidasi,x-4,y-3);	
			
			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;						
	}		
}
class Sou{
	constructor(namae){
		this.namae=namae;
		this.main=new Array();		
		this.temp=new Array();
	}
	tasu(){		
		for(var tt=0;tt<arguments.length;tt++){
			this.main.push(arguments[tt]);						
		}				
		
	}
	hiku(aitemu){
		for(var hik=0;hik<this.main.length;hik++){
			if(this.main[hik].id==aitemu){				
				this.main.splice(hik,1);				
			}			
		}		
	}
	koushin(){		
		var nagasa=this.main.length;
		while(this.temp.length<nagasa){		
			for(var h=0;h<this.main.length;h++){
				var count=0;				
				if(this.temp.length>0){					
					for(var i=0;i<this.main.length;i++){
						if(this.main[h].id!=this.main[i].id){						
							if(this.main[h].y>this.main[i].y){						
								count++;										
							}										
						}							
					}						
					
				}else{				
					for(var i=0;i<this.main.length;i++){
						if(this.main[h].id!=this.main[i].id){						
							if(this.main[h].y>this.main[i].y){						
								count++;									
							}								
						}							
					}					
				}

				if(count==0){			
					this.temp.push(this.main[h]);										
					this.main.splice(h,1);
					h--;
				}
			}			
		}		
		this.main=this.temp;				
		this.temp=new Array();
	}
};


//canvas 
var canvas=document.createElement('canvas');
var gamen=canvas.getContext('2d');
canvas.height=z.gt*z.scal;
canvas.width=z.gy*z.scal;
canvas.style.borderRadius='10px';
gamen.scale(z.scal,z.scal);
canvas.style.position='absolute';
canvas.style.top=(z.tate/2)-(canvas.height/2);
canvas.style.left=(z.yoko/2)-(canvas.width/2);
document.body.appendChild(canvas);
gamen.imageSmoothingEnabled=false;

gamen.fillStyle='#220022';
gamen.fillRect(0,0,300,300);
gamen.fillStyle='#650065';
gamen.font='25px arial';
gamen.fillText('Loading...',7,55);
//sounds 
var bgm=new Audio('d_town/bgm.wav');
bgm.loop=true;
var kuriku=new Oto('d_town/click.wav');
var snugu=new Oto('d_town/nugu.wav');
var sthud=new Oto('d_town/thud.wav');
var ssuta=new Oto('d_town/suta.wav');
var snuchu=new Oto('d_town/nuchu.wav');
var spyun=new Oto('d_town/dopyun.wav');
var sban=new Oto('d_town/ban.wav');
var siki=new Oto('d_town/iki.wav');
var skisu=new Oto('d_town/kiss.wav');
var skosu=new Oto('d_town/kosu.wav');
var sbane=new Oto('d_town/bane.wav');
var skane=new Oto('d_town/bling.wav');
var seki=new Oto('d_town/eki.wav');
var sjipa=new Oto('d_town/jipa.wav');
var skyaa=new Oto('d_town/yell.wav');
var ssube=new Oto('d_town/suberute.wav');
var spi=new Oto('d_town/pi.wav');
//sou
var mapsou=new Sou('map');
var biru1={x:0,y:27,id:'biru1',namae:'biru'};
var biru2={x:0,y:53,id:'biru2',namae:'biru'};
var kouen1={x:0,y:67,id:'kouen1',namae:'kouen'};
var kouen2={x:0,y:71,id:'kouen2',namae:'kouen'};
var biru3={x:0,y:79,id:'biru3',namae:'biru'};
var biru4={x:0,y:95,id:'biru4',namae:'biru'};
var biru5={x:0,y:97,id:'biru5',namae:'biru'};
var biru6={x:0,y:99,id:'biru6',namae:'biru'};
mapsou.tasu(biru1,biru2,kouen1,kouen2,biru3,biru4,biru5,biru6);
//sprites
var bgmenu=new Renda('d_town/bg_menu.png','bgmenu',120,100,gamen);
bgmenu.kx=0;
bgmenu.kxc=0;
bgmenu.tx=0;
var bgmap=new Renda('d_town/bg_map.png','bgmap',150,100,gamen);

var abuttons=new Renda('d_town/a_button.png','buttons',14,14,gamen);

var acar=new Renda('d_town/a_car.png','car',14,8,gamen);
acar.x=120;
var acar2=new Renda('d_town/a_car.png','car',14,8,gamen);
acar2.x=150;
var acar3=new Renda('d_town/a_car.png','car',14,8,gamen);
acar3.x=250;

var puremi=new Renda('d_town/pure_mini.png','puremi',8,10,gamen);
puremi.id='puremi';
puremi.oto(ssuta,1);
puremi.x=62;
puremi.y=32;
puremi.tx=62;
puremi.ty=32;
puremi.joutai='stop';
mapsou.tasu(puremi);

mapsou.koushin();

var deguti=new Object();
deguti.namae='deguti';
deguti.id='deguti';
deguti.x=111;
deguti.y=95;
mapsou.tasu(deguti);
mapsou.koushin();

var mobu=new Renda('d_town/mobu.png','mobu',50,50,gamen);

var bgkabu=new Renda('d_town/bg_kabu.png','bgkabu',150,100,gamen);
var eri=new Renda('d_town/eri.png','eri',50,50,gamen);
var kanemo=new Renda('d_town/kanemo.png','kanemo',50,50,gamen);
var kanemotc=new Renda('d_town/kanemo_talkc.png','kanemo',50,50,gamen);
kanemotc.oto(skosu,1);
kanemotc.oto(skane,7);
var kanemotd=new Renda('d_town/kanemo_talkd.png','kanemo',50,50,gamen);
var erika2=new Renda('d_town/eri_kabu2.png','eri',50,50,gamen);
erika2.oto(skosu,2,6);
erika2.oto(snugu,17);
var erika3=new Renda('d_town/eri_kabu3.png','eri',50,50,gamen);
erika3.oto(skosu,1,6);
erika3.oto(skane,5);
var kanemo2=new Renda('d_town/kanemo_2.png','kanemo',50,50,gamen);
kanemo2.oto(skosu,4,9);
kanemo2.oto(snugu,6);
kanemo2.oto(sbane,8);
kanemo2.oto(ssuta,8);
var erika5=new Renda('d_town/eri_kabu5.png','eri',50,50,gamen);
var erika6=new Renda('d_town/eri_kabu6.png','eri',50,50,gamen);
erika6.oto(ssuta,4);
erika6.oto(skisu,16);
erika6.oto(snuchu,19);

//clickable areas
var jpO=new Osu(3,55,60,68);
var enO=new Osu(61,55,117,68);

var pureO=new Osu(40,71,80,78);
var watchO=new Osu(40,79,80,88);

var ooO=new Osu(100,88,117,98);
var tiiO=new Osu(2,88,21,98);

var bgmO=new Osu(1,1,15,15);

var anipO=new Osu(16,71,30,86);
var animO=new Osu(1,71,15,86);
var scnpO=new Osu(16,86,30,99);
var scnmO=new Osu(1,86,15,99);

var backO=new Osu(42,86,57,99);
var backO2=new Osu(105,62,119,75);
//map areas
var akabu=new Osu(27,51,29,54);
var amenu=new Osu(107,91,114,95);

//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('d_town/hira.png',8,7,gamen);
hira.letter(moji,100,74);
hira.dialog(logs);
hira.fukif('d_town/a_balloon.png');

var hirab=new Balloon('d_town/hira.png',8,7,gamen);
hirab.letter(moji,100,74);
hirab.fukif('d_town/a_balloon.png');

var roma=new BalloonEn('d_town/alpha.png',5,7,gamen);
roma.letter(letter,45,26);
roma.dialog(logs);
roma.fukif('d_town/a_balloon.png');

var romab=new BalloonEn('d_town/alpha.png',5,7,gamen);
romab.letter(letter,45,26);
romab.fukif('d_town/a_balloon.png');

var se=hira;
var ko=hirab;
//lines
logs['jpbamap']='もどる';
logs['enbamap']="Back";
//えり---------------------------
logs['jperikabu1']='えり：（だれも　こない、　しめいも　ぜんぜんなくて　こんげつ　どうしよう。。。なんでも　するから　だれか　きて　ほしい）';
logs['jperikabu2']='えり：（むねが　ちいさいと　はなが　ないな。。。さぶかるで　にんきあるって　きいたけど　じっさい　そうでもないよね。。。せめて　びーかっぷ　だったら　ぱっどで　たにま　つくれたけど　えいかっぷは　さすがに。。。）';

logs['enerikabu1']="Eri: (Oh girl, no customer, nobody wanting me, it'll be a rough month to pay the bills...I'll do anything, please anybody...)";
logs['enerikabu2']="Eri: (Small breasts are so uninteresting...I hear otakus like it but it doesn't seem to be true, if at least it was a B cup I could wear some pads to make it bigger but an A cup would look so fake...)";

logs['jperikabu3']='えり：　いらっしゃいませぇ！　きょう　しんきの　おきゃくさまには　20ぱーせんとの　わりびきです、いかがですか？';
logs['jperikabu4']='せれぶ：　きみ　かわいいね。。。なまえ　なに？';
logs['jperikabu5']='えり：　ぁ、ありがとう、 えりです。。。（はいぶらんどの　ふるこーで！　かね　すっごい　もてそう！）';

logs['enerikabu3']="Eri: Welcome! Today for the first time customers we a have a 20 percent discount, would you like to try?";
logs['enerikabu4']="Rich Guy: You're cute huh, what's your name?";
logs['enerikabu5']="Eri: T-thank you, I'm Eri...(High-end brand clothes! This guy looks very rich!) ";

logs['jperikabu6']='せれぶ：　きに　いった。。。';
logs['jperikabu7']='えり：（さつたば！）';
logs['jperikabu8']='せれぶ：　おれね、　そとで　ぼうけんするの　だいすき　なんだけど、　あっちの　ろじうら　いいとこ　だね、　だれにも　みられないよね。。。';
logs['jperikabu9']='えり：　。。。（えっ、　あそこで　えっちしようって？　さつたば　すっごいけど、 わな　じゃないかな？　そういうの　こわいね。。。）';
logs['jperikabu10']='せれぶ：　あそこで　おれの　むすこと　あそんでくれない？';
logs['jperikabu11']='えり：　すみません　しごとちゅう　なんです。。。（どうしよう？！　どうせ　だれも　こないし！　この　ちゃんすも　にどと　ないし！　こわいけど！）';
logs['jperikabu12']='せれぶ：　むすこね、　えりちゃんの　こと　めっちゃ　きに　いってる、　めっちゃ　びんびん　なちゃってきた';
logs['jperikabu13']='えり：　。。。（なやむぅ　ほんとう　かな？　この　さつたばの　すうまいだけでも　ほしい！）';
logs['jperikabu14']='せれぶ：　じゃさぁ、　いちびょうでも　いいから、　ここで　ぱんちら　したら。。。';
logs['jperikabu15']='えり：　いちびょうだけなら。。。';

logs['enerikabu6']="Rich Guy: I like you...";
logs['enerikabu7']="Eri: (A stack of bills!)";
logs['enerikabu8']="Rich Guy: You know, I like to have fun outdoors...see that back alley there? Nice place huh, no one can see what's going there...";
logs['enerikabu9']="Eri: ...(He mean have sex there? Those bills are tempting but...I wonder if he's just messing with me, these guys are dangerous...)";
logs['enerikabu10']="Rich Guy: Hey, would you 'play' there with my little jimmy?";
logs['enerikabu11']="Eri: Sorry I'm working right now...(What I do? There's no customer anyway and I won't have a chance like that again! This guy looks so suspicious though...)";
logs['enerikabu12']="Rich Guy: Little Jimmy really liked you, he's all hard and all...";
logs['enerikabu13']="Eri: ...(Oh girl...I'd be so happy even with just a few bills of those)";
logs['enerikabu14']="Rich Guy: So...what about showing me your panties right here, even for just some seconds...";
logs['enerikabu15']="Eri: For some seconds...I think I can do it...";

logs['jperikabu16']='えり：　。。。（だれも　みてないよね？　はずかしい！　かわいい　したぎ　きててよかった！）';
logs['jperikabu17']='せれぶ：　いいね、えりちゃん　めっちゃ　えっちぃじゃん！　わら';

logs['enerikabu16']="Eri: ...(Ok, nobody's looking? Oh girl that's so embarrassing...at least I wore some cute underwear today...)";
logs['enerikabu17']="Rich Guy: Oh yeah, Eri-chan you're naughty huh!";

logs['jperikabu18']='えり：　ありとうございます　ごしゅじんさま。。。（たすかった！）';
logs['jperikabu19']='えり：（ぱんつの　あのふくらみ、　すっごい　ぼっきしてる！　はずかしいけど　なんか、　うれしい。。。）';
logs['jperikabu20']='せれぶ：　いい　ぱんてぃー　みちゃた、　でもやっぱ　むすこまだ　さびしいよね、　えりちゃんと　あそびたくて。。。あそんでくれたら　もっと　あげるよ。。。';
logs['jperikabu21']='えり：　。。。（ほんとうに　かねくれたし、　こまってるし、　いいかな。。。）';
logs['jperikabu22']='えり：　ん。。。いいよ。。。';

logs['enerikabu18']="Eri: Thank you my master...(Oh, it really helps me!)";
logs['enerikabu19']="Eri: (Oh that volume in his pants, he's very excited! It makes me blush but it's kind of flattering...)";
logs['enerikabu20']="Rich Guy: Nice panties huh, but my little jimmy still wants to play a little more, something more 'aggressive'...if you play with him you'll get more bills from this stack...";
logs['enerikabu21']="Eri: ...(he's not lying he really gave me the money, I mean I really need that money too, nn I think it's ok...)";
logs['enerikabu22']="Eri: yup, we can play a little...";

logs['jperikabu23']='えり：　もじもじ';

logs['enerikabu23']="Eri: fidgets";

logs['jperikabu24']='せれぶ：　ほら、　えりちゃんと　めっちゃ　あそびたい';

logs['enerikabu24']="Rich Guy: Hey look little jimmy wants to play with you so much";

logs['jperikabu25']='えり：　！！！（ひぃ　とつぜん　しぬぅ！　おおきい！　えぇ　わたしで　そんなに　こうふんしてきた？）';
logs['jperikabu26']='せれぶ：　ねぇ　えりちゃん、　しゃぶって';

logs['enerikabu25']="Eri: !!!(Oh Geez! Without a notice! Girl He got thaat excited about me?!)";
logs['enerikabu26']="Rich Guy: hey, Eri-chan, suck it";

logs['jperikabu27']='せれぶ：　えりちゃん　うまいね、　なんぼんも　しゃぶったんだろう。。。';
logs['jperikabu28']='えり：　（かれしに　いっかいしか　したことないのにぃ！）';
logs['jperikabu29']='せれぶ：　えりちゃん、　ちょっと！　こんなに　つよく　しゃぶったら　いっちゃうよ！　ちんこ　しゃぶるの　めっちゃ　すき　だね';
logs['jperikabu30']='たいけんばん　を　ぷれいして　ありがとうございます';

logs['enerikabu27']="Rich Guy: Man you know how to do a blowjob huh, I wonder how many cocks you sucked...";
logs['enerikabu28']="Eri: (But I just did it once for my ex-boyfriend!)";
logs['enerikabu29']="Rich Guy: Oh Eri-chan, wait girl! Don't suck that hard or I'll cum! You really like to suck huh";
logs['enerikabu30']="Trial version ends here, thanx for playing!";

//functions
function zero(){		
	kanemotc.koma=0;
	erika3.koma=0;
	kanemotd.koma=0;
	erika2.koma=0;
	kanemo2.koma=0;
	erika5.koma=0;
	erika6.koma=0;
	
};
function aCheck(xx,yy){
	if(xx==undefined){
		xx=0;
	}
	if(yy==undefined){
		yy=0;
	}
	if(akabu.d(puremi.x+xx,puremi.y+yy)){
		feido.suta='dark';
		sute.t='event';										
		sute.ba='kabu';
		sute.seri='erikabu';
		sute.gu='';
		puremi.joutai='stop';
		puremi.tx=puremi.x;
		puremi.ty=puremi.y;
		return true
	}else if(amenu.d(puremi.x+xx,puremi.y+yy)){
		feido.suta='dark';
		sute.t='menu';										
		sute.ba='';
		sute.gu='';
		puremi.joutai='stop';
		puremi.tx=puremi.x;
		puremi.ty=puremi.y;
		return true
	}else{
		return false
	}
}

function koushin(){	
	gamen.fillStyle='#111111';
	gamen.fillRect(0,0,z.gy+10,z.gt+10);					
	if(sute.p=='event'){
		if(sute.ba=='kabu'){
			bgkabu.haikei(0,0);
			bgkabu.count++;
			if(bgkabu.count<5){
				bgkabu.haikei(0,0,1);
			}else if(bgkabu.count<8){
				gamen.save();
				gamen.globalAlpha=0.7;
				bgkabu.haikei(0,0,1);
				gamen.restore();
				if(bgkabu.count>10){
					bgkabu.count=0;
				}
			}else{
				gamen.save();
				gamen.globalAlpha=0.5;
				bgkabu.haikei(0,0,1);
				gamen.restore();
				if(bgkabu.count>12){
					bgkabu.count=0;
				}
			}
			
			if(se.dian>=23){
				if(se.dian<24){
					eri.talk(52,55,3);
					kanemo.talk(67,55,2);
				}else if(se.dian<25){
					eri.talk(52,55,3);
					kanemo2.anime(67,55,0,10,true);
				}else if(se.dian<27){
					erika5.anime(52,55,0,3,true);
					kanemo2.anime(67,55,0,10,true);
				}else {
					erika6.anime(62,55,0,18);
				}
				gamen.save();
				gamen.globalAlpha=0.6;
				bgkabu.haikei(0,0,0,1);
				gamen.restore();
			}else{		
				bgkabu.haikei(0,0,0,1);
			}
			
			if(se.dian<3){
				eri.talk(20,75,1);
			}else if(se.dian<16){
				eri.talk(20,75,2);
			}else if(se.dian<18){
				erika2.anime(20,75,0,21,true);
			}else if(se.dian<23){
				erika3.anime(20,75,0,10,true);
			}
			if(se.dian<7){
				kanemo.talk(45,80,1);
			}else if(se.dian<18){
				kanemotc.anime(45,80,0,8,true);
			}else if(se.dian<23){
				kanemotd.anime(45,80,0,6,true);
			}
			
			bgkabu.haikei(0,0,0,3);
			
			mobu.talk(73,85,4);
			mobu.talk(98,90,5);					
		}
		
		if(feido.suta=='null'){			
			se.seri(z.gen+sute.seri,5,74,109,24);			
			if(backO2.c(nezu.x,nezu.y)){
				abuttons.kyara(112,75,0,11);
				ko.koto(logs[z.gen+'bamap'],82,66,60,10);
			}else{
				abuttons.kyara(112,75,0,10);
			}
		}		
		
		if(z.bgm){
			if(bgmO.c(nezu.x,nezu.y)){
				abuttons.kyara(8,14,0,1);
			}else{
				abuttons.kyara(8,14,0,0);
			}
		}else{
			if(bgmO.c(nezu.x,nezu.y)){
				abuttons.kyara(8,14,0,3);
			}else{
				abuttons.kyara(8,14,0,2);
			}
		}
		
	}else if(sute.p=='map'){
		bgmap.haikei(0,0);		
		
		if(puremi.joutai=='walk'){
			puremi.kyara(puremi.tx,puremi.ty,2,0);
		}else{
			puremi.kyara(puremi.tx,puremi.ty,2,1);
		}		
		if(puremi.joutai!='dead'){		
			if(puremi.joutai=='walk'){
				if(Math.abs(puremi.x-puremi.tx)>2){
					if(puremi.x<puremi.tx){
						if(aCheck(2,0)){						
							
						}else{
							puremi.x+=2;
						};
					}else{
						if(aCheck(-2,0)){						
							
						}else{
							puremi.x-=2;
						};
					}
				}else{
					if(aCheck(0,0)){
						
					}else{
						puremi.tx=puremi.x;
					};
				};
				if(Math.abs(puremi.y-puremi.ty)>2){
					if(puremi.y<puremi.ty){
						if(aCheck(0,2)){
							
						}else{
							puremi.y+=2;
						};
					}else{
						if(aCheck(0,-2)){
							
						}else{
							puremi.y-=2;
						};
					}
				}else{
					if(aCheck(0,0)){
						
					}else{
						puremi.ty=puremi.y;
					}
				};
				if(puremi.y==puremi.ty&puremi.x==puremi.tx){
					puremi.joutai='stop';
				}				
			}
			
		}		
		mapsou.koushin();	
		
		for(var mp=0;mp<mapsou.main.length;mp++){
			switch(mapsou.main[mp].id){
				case 'puremi':
					if(puremi.joutai=='dead'){
						puremi.kyara(puremi.x,puremi.y,3,0);
					}else if(puremi.joutai=='walk'){
						puremi.anime(puremi.x,puremi.y,1);
					}else {
						puremi.kyara(puremi.x,puremi.y,0,0);
					}
					break;
				case 'biru1':
					gamen.save();
					if(puremi.y<biru1.y){
						gamen.globalAlpha=0.4;
					}
					bgmap.haikei(0,0,0,1);
					gamen.restore();
					break;
				case 'biru2':
					gamen.save();
					if(puremi.y<biru2.y){
						gamen.globalAlpha=0.4;
					}
					bgmap.haikei(0,0,0,2);
					gamen.restore();
					break;
				case 'kouen1':
					gamen.save();
					if(puremi.y<kouen1.y){
						gamen.globalAlpha=0.6;
					}
					bgmap.haikei(0,0,0,3);
					gamen.restore();
					break;
				case 'kouen2':
					gamen.save();
					if(puremi.y<kouen2.y){
						gamen.globalAlpha=0.6;
					}
					bgmap.haikei(0,0,0,4);
					gamen.restore();
					break;
				case 'biru3':
					gamen.save();
					if(puremi.y<biru3.y){
						gamen.globalAlpha=0.4;
					}
					bgmap.haikei(0,0,0,5);
					gamen.restore();
					break;
				case 'biru4':
					gamen.save();
					if(puremi.y<biru4.y){
						gamen.globalAlpha=0.4;
					}
					bgmap.haikei(0,0,0,6);
					gamen.restore();
					break;				
				case 'biru5':
					gamen.save();
					if(puremi.y<biru5.y){
						gamen.globalAlpha=0.4;
					}
					bgmap.haikei(0,0,0,7);
					gamen.restore();
					break;	
				case 'biru6':
					gamen.save();
					if(puremi.y<biru6.y){
						gamen.globalAlpha=0.4;
					}
					bgmap.haikei(0,0,0,8);
					gamen.restore();
					break;	
				case 'deguti':
					gamen.save();
					if(puremi.y<deguti.y){
						gamen.globalAlpha=0.4;
					}
					abuttons.kyara(deguti.x,deguti.y,0,12);
					gamen.restore();
					break;				
			}
		};
		
		if(z.bgm){
			if(bgmO.c(nezu.x,nezu.y)){
				abuttons.kyara(8,14,0,1);
			}else{
				abuttons.kyara(8,14,0,0);
			}
		}else{
			if(bgmO.c(nezu.x,nezu.y)){
				abuttons.kyara(8,14,0,3);
			}else{
				abuttons.kyara(8,14,0,2);
			}
		}
		
	}else if(sute.p=='watch'){
		if(ani.scen==1){
			bgkabu.haikei(0,0);
			bgkabu.count++;
			if(bgkabu.count<5){
				bgkabu.haikei(0,0,1);
			}else if(bgkabu.count<8){
				gamen.save();
				gamen.globalAlpha=0.7;
				bgkabu.haikei(0,0,1);
				gamen.restore();
				if(bgkabu.count>10){
					bgkabu.count=0;
				}
			}else{
				gamen.save();
				gamen.globalAlpha=0.5;
				bgkabu.haikei(0,0,1);
				gamen.restore();
				if(bgkabu.count>12){
					bgkabu.count=0;
				}
			}
			
			if(ani.ani>=6){
				if(ani.ani<7){
					eri.talk(52,55,3);
					kanemo.talk(67,55,2);
				}else if(ani.ani<8){
					eri.talk(52,55,3);
					kanemo2.anime(67,55,0,10,true);
				}else if(ani.ani<9){
					erika5.anime(52,55,0,3,true);
					kanemo2.anime(67,55,0,10,true);
				}else {
					erika6.anime(62,55,0,18);
				}
				gamen.save();
				gamen.globalAlpha=0.6;
				bgkabu.haikei(0,0,0,1);
				gamen.restore();
			}else{		
				bgkabu.haikei(0,0,0,1);
			}
			
			if(ani.ani==1){
				eri.talk(20,75,1);
			}else if(ani.ani<4){
				eri.talk(20,75,2);
			}else if(ani.ani<5){
				erika2.anime(20,75,0,21,true);
			}else if(ani.ani<6){
				erika3.anime(20,75,0,10,true);
			}
			if(ani.ani<3){
				kanemo.talk(45,80,1);
			}else if(ani.ani<5){
				kanemotc.anime(45,80,0,8,true);
			}else if(ani.ani<6){
				kanemotd.anime(45,80,0,6,true);
			}
			
			bgkabu.haikei(0,0,0,3);
			
			mobu.talk(73,85,4);
			mobu.talk(98,90,5);
		}
		
		if(z.bgm){
			if(bgmO.c(nezu.x,nezu.y)){
				abuttons.kyara(8,14,0,1);
			}else{
				abuttons.kyara(8,14,0,0);
			}
		}else{
			if(bgmO.c(nezu.x,nezu.y)){
				abuttons.kyara(8,14,0,3);
			}else{
				abuttons.kyara(8,14,0,2);
			}
		}
		
		romab.koto(''+ani.ani,33,75,40,8,1);
		romab.koto(''+ani.scen,33,90,40,8,1);
		if(animO.c(nezu.x,nezu.y)){
			abuttons.kyara(8,86,0,5);
		}else{
			abuttons.kyara(8,86,0,4);
		}
		if(anipO.c(nezu.x,nezu.y)){
			abuttons.kyara(23,86,0,7);
		}else{
			abuttons.kyara(23,86,0,6);
		}
		if(scnmO.c(nezu.x,nezu.y)){
			abuttons.kyara(8,100,0,5);
		}else{
			abuttons.kyara(8,100,0,4);
		}
		if(scnpO.c(nezu.x,nezu.y)){
			abuttons.kyara(23,100,0,7);
		}else{
			abuttons.kyara(23,100,0,6);
		}
		if(backO.c(nezu.x,nezu.y)){
			abuttons.kyara(50,100,0,9);
		}else{
			abuttons.kyara(50,100,0,8);
		}
	}else{
		bgmenu.haikei(0,0);
		if(bgmenu.kxc<3){
			bgmenu.kxc+=1;
		}else{
			bgmenu.kxc=0;
			bgmenu.kx-=1;
			if(bgmenu.kx<-z.gy){
				bgmenu.kx=z.gy;
			}
		}
		bgmenu.tx+=2;
		if(bgmenu.tx>z.gy+100){
			bgmenu.tx=-100;
		}
		bgmenu.haikei(bgmenu.kx,0,0,1);
		bgmenu.haikei(bgmenu.tx,0,0,2);
		if(z.gen=='jp'){
			bgmenu.haikei(0,0,0,3);
		}else{
			bgmenu.haikei(0,0,0,11);
		}
		if(jpO.c(nezu.x,nezu.y)){
			bgmenu.haikei(0,0,0,5);
		}else if(enO.c(nezu.x,nezu.y)){
			bgmenu.haikei(0,0,0,6);
		}else if(pureO.c(nezu.x,nezu.y)){
			bgmenu.haikei(0,0,0,7);
		}else if(watchO.c(nezu.x,nezu.y)){
			bgmenu.haikei(0,0,0,8);
		}else if(ooO.c(nezu.x,nezu.y)){
			bgmenu.haikei(0,0,0,9);
		}else if(tiiO.c(nezu.x,nezu.y)){
			bgmenu.haikei(0,0,0,10);
		}else{
			bgmenu.haikei(0,0,0,4);
		}
		
		acar.anime(acar.x,46);
		acar2.anime(acar2.x,48);
		acar3.anime(acar3.x,47);
		acar.x-=3;
		acar2.x-=3;
		acar3.x-=3;
		if(acar.x<-50){
			acar.x=z.gy+50;
		}
		if(acar2.x<-50){
			acar2.x=z.gy+50;
		}
		if(acar3.x<-50){
			acar3.x=z.gy+50;
		}		
		romab.koto('Hoodie Corp 2025',1,1,120,10,0.2);		
	}
	if(feido.suta!='null'){
		if(feido.suta=='dark'){
			feido.count+=0.1;
			if(feido.count>=1){
				feido.count=1;		
				feido.suta='bright';
				sute.p=sute.t;
				se.reset();
				zero();				
				if(sute.p=='menu'){
					bgm.pause();
					puremi.x=62;
					puremi.y=32;
					puremi.tx=puremi.x;
					puremi.ty=puremi.y;										
					puremi.joutai='stop';
				}else{
					if(sute.p=='map'){					
						puremi.tx=puremi.x;
						puremi.ty=puremi.y;										
						puremi.joutai='stop';						
					}
					if(z.bgm){											
						bgm.play();
					};
				}				
			}			
			bgm.volume=1-feido.count;
			gamen.save();
			gamen.fillStyle='#330055';
			gamen.globalAlpha=feido.count;
			gamen.fillRect(0,0,200,200);
			gamen.restore();			
		}else if(feido.suta=='bright'){
			feido.count-=0.1;
			if(feido.count<=0){
				feido.count=0;
				feido.suta='null';
			}
			bgm.volume=1-feido.count;
			gamen.save();
			gamen.fillStyle='#330055';
			gamen.globalAlpha=feido.count;
			gamen.fillRect(0,0,200,200);
			gamen.restore();			
		}
	}	
};
onmousemove=function(e){
	z.x=e.clientX;
	z.y=e.clientY;
	
	nezu.x=Math.floor((z.x-((z.yoko/2)-(canvas.width/2)))/z.scal);
	nezu.y=Math.floor((z.y-((z.tate/2)-(canvas.height/2)))/z.scal);
	if(nezu.x<0){
		nezu.x=0;		
	}else if(nezu.x>z.gy){
		nezu.x=z.gy;
	};		
	if(nezu.y<0){
		nezu.y=0;		
	}else if(nezu.y>z.gt){
		nezu.y=z.gt;
	};		
};

onmousedown=function(e){	
	kuriku.p();
	z.tate=window.innerHeight;
	z.yoko=window.innerWidth;
	canvas.style.top=(z.tate/2)-(canvas.height/2);
	canvas.style.left=(z.yoko/2)-(canvas.width/2);	
	gamen.imageSmoothingEnabled=false;
	
	z.x=e.clientX;
	z.y=e.clientY;
	
	nezu.x=Math.floor((z.x-((z.yoko/2)-(canvas.width/2)))/z.scal);
	nezu.y=Math.floor((z.y-((z.tate/2)-(canvas.height/2)))/z.scal);
	if(nezu.x<0){
		nezu.x=0;		
	}else if(nezu.x>z.gy){
		nezu.x=z.gy;
	};		
	if(nezu.y<0){
		nezu.y=0;		
	}else if(nezu.y>z.gt){
		nezu.y=z.gt;
	};		
	if(feido.suta=='null'){
		if(sute.p=='event'){								
			if(bgmO.c(nezu.x,nezu.y)){
				if(z.bgm){
					z.bgm=false
					bgm.pause();
				}else{
					z.bgm=true
					bgm.play();
				};
			}else if(backO2.c(nezu.x,nezu.y)){				
				feido.suta='dark';				
				sute.t='map';				
			}else {				
				if(se.nx){
					se.next();
				}else{
					sute.t='map';					
					feido.suta='dark';
				}				
			}			
		}else if(sute.p=='map'){					
			if(bgmO.c(nezu.x,nezu.y)){
				if(z.bgm){
					z.bgm=false
					bgm.pause();
				}else{
					z.bgm=true
					bgm.play();
				};
			}else if(puremi.joutai!='dead'){
				puremi.tx=nezu.x;
				puremi.ty=nezu.y;
				puremi.joutai='walk';
			}
		}else if(sute.p=='watch'){		
			if(bgmO.c(nezu.x,nezu.y)){
				if(z.bgm){
					z.bgm=false
					bgm.pause();
				}else{
					z.bgm=true
					bgm.play();
				};
			}else if(anipO.c(nezu.x,nezu.y)){
				if(ani.ani<ani['ani'+ani.scen]){
					ani.ani++;
				}else{
					ani.ani=1;
					zero();
				}				
			}else if(animO.c(nezu.x,nezu.y)){
				if(ani.ani>1){
					ani.ani--;						
				}else{
					ani.ani=ani['ani'+ani.scen];						
				}				
				zero();
			}else if(scnpO.c(nezu.x,nezu.y)){
				if(ani.scen<ani.scent){
					ani.scen++;					
				}else{
					ani.scen=1;
					zero();
				}				
				ani.ani=1;
			}else if(scnmO.c(nezu.x,nezu.y)){
				if(ani.scen>1){
					ani.scen--;
				}else{
					ani.scen=ani.scent;
				}
				ani.ani=1;
			}else if(backO.c(nezu.x,nezu.y)){
				sute.t='menu';				
				feido.suta='dark';
			};
		}else if(sute.p=='menu'){
			if(jpO.c(nezu.x,nezu.y)){
				z.gen='jp';
				document.title='ドットポリス（体験版）';
				se=hira;
				ko=hirab;				
			}else if(enO.c(nezu.x,nezu.y)){
				z.gen='en';
				document.title="Dottopolis(trial version)";
				se=roma;
				ko=romab;				
			}else if(pureO.c(nezu.x,nezu.y)){
				sute.t='map';
				feido.suta='dark';
			}else if(watchO.c(nezu.x,nezu.y)){
				sute.t='watch';
				feido.suta='dark';
			}else if(ooO.c(nezu.x,nezu.y)){
				if(z.gt*(z.scal+1)<z.tate&z.gy*(z.scal+1)<z.yoko){
					z.scal++;				
					z.tate=window.innerHeight;
					z.yoko=window.innerWidth;
					canvas.height=z.gt*z.scal;
					canvas.width=z.gy*z.scal;			
					gamen.scale(z.scal,z.scal);
					canvas.style.top=(z.tate/2)-(canvas.height/2);
					canvas.style.left=(z.yoko/2)-(canvas.width/2);	
					gamen.imageSmoothingEnabled=false;
				}
			}else if(tiiO.c(nezu.x,nezu.y)){
				if(z.scal>1){
					z.scal--;
					z.tate=window.innerHeight;
					z.yoko=window.innerWidth;
					canvas.height=z.gt*z.scal;
					canvas.width=z.gy*z.scal;			
					gamen.scale(z.scal,z.scal);
					canvas.style.top=(z.tate/2)-(canvas.height/2);
					canvas.style.left=(z.yoko/2)-(canvas.width/2);	
					gamen.imageSmoothingEnabled=false;
				}
				
			}
		}else {		
			sute.t='menu';	
			feido.suta='dark';
		}
	}
};


window.onload=function(){
	var kouf=setInterval(koushin,100);	
};