function Field(id){
//初期設定など
	this.id=id||'';		// フィールドID, out-WP
	this.name=id||'';

// フィールド情報
	var koropokkes= [];	// コロポッケオブジェクト
	var scenes=[];
	this.action=null;
	this.loaded=false;

//以降、動的に変更されるプロパティ
	
	//追加型プロパティ
	var addprops=['actions','action','dic','koropokke','description'];

	var tm=0; // action timer
	var self=null;
	
	this.frame=null;
	this.field=null;
	var cvs=null;
	var ctx=null;
	var spacer=new Image();
	spacer.src=SPACER_URI;

	var now=0;
	var lastAction={
			talktime:0
		};
	var props={
		 author:'' // 制作者
		,home: '' // 制作者URL
		,field:'' // フィールド名
		,description:'' // フィールド概要
		,koropokkes:{} //コロポッケデータ
		,actions:{interval:0,actions:[]} // アクション辞書ファイルなど
		,balloon: '' // 吹き出しID
		,scene: { // 背景画像
			 color: 'transparent'
			,image: ''
			,y:0
			,x:0
			,repeatx: false
			,repeaty: false
		 }//scene
		,pos: { // フィールド表示基準点、表示位置
			 baseY:S_B
			,baseX:S_L
			,x:0
			,y:0
		 }//pos
	};//props

/****************
responseText分割、プロパティにセット
****************/
	this.Init=function(o){
D.Out(0,'fieldInit',this.id);
		//this.id=id;
		
		this.field=U.CE('div');
		this.field.className='field';
		this.field.id='field'+this.id;
		
		this.board=U.CE('div');
		this.board.className='board';
		this.board.id='board'+this.id;
		
		// field景色用 
		if(Config.mode){
			cvs=U.CE('canvas');
			ctx=cvs.getContext('2d');
			this.field.appendChild(cvs);
		}else{
			//cvs=U.CE('img');
			ctx=U.CE('img');
			ctx.style.position='absolute';
			ctx.style.top='0px';
			ctx.style.left='0px';
			this.field.appendChild(ctx);
		}
		
		this.field.appendChild(this.board);
		
		//吹き出し表示用スペース、field.lastChild
		this.field.appendChild(U.CE('div'));
		
//this.field.appendChild(U.CE('p'));
		if(document && document.body)
			document.body.appendChild(this.field);
		//////////
		this.ParseSetting(o.client);
		this.LoadScene();
		this.LoadKoropokke();
		this.LoadAction();

		delete addprops;
		delete props;
		delete this.ParseSetting;
		delete this.LoadScene;
		delete this.LoadKoropokke;
		delete this.LoadAction;
		
		lastAction.talktime=(new Date()).getTime();

		this.loaded=true; // in-WP
		Start(); //in-WP
		//this.Start(); //out-WP
	
		return this;
	};//
	
/**** out-WP
	this.Start=function(){
		self=this;
		tm=setInterval(function(){self.Run();}, ANIM_INTERVAL);
		return this;
		
//D.Out(1, 'Start', tm);
		//if(tm)
		//	tm=clearTimeout(tm);
		//self=this;
		//self.Run();
		//tm=setTimeout(function(){self.Start();}, ANIM_INTERVAL);
		//return this;

//		tm=setInterval(function(){self.Run();}, ANIM_INTERVAL);

//		tm=setInterval(function(id){
//			for(var i=0;i<window.fields.length;i++){
//				if(window.fields[i].id==self.id){
//					window.fields[i].Run();
//					break;
//				}
//			}
//		}, ANIM_INTERVAL);
		
//		tm=setInterval(window.fields[self.id].Run(), ANIM_INTERVAL);
	};
	
/****/
	this.Destroy=function(){
		tm=clearInterval(tm);
		for(var i=0,k;k=koropokkes[i];i++){
			k.Destroy();
			koropokkes[i]=null;
		}
		delete koropokkes;
		for(var i=0;i<scenes.length;i++){
			scenes[i]=null;
		}
		delete scenes;
		this.action.Destroy();
		delete this.action;
		self=null;
	};
	
/************
引数がStringじゃないので注意
*************/
	this.ParseSetting=function(client){
		if(client.status!=0 && client.status!=200 && client.status!=304){
alert('Load error : '+client.status);
			return this;
		}
		var lines=client.responseText.split(LF);
		LINES:for(var l=0,line,r={key:'',val:''},p,dir='',kid='',prs=props,reg=new RegExp('.');l<lines.length;l++){
			line=U.Trim(lines[l]);
			if(!line.length || line.charAt(0)=='#')
				continue LINES;

			if(dir=='koropokke'){
				if(reg.test(line)){
					dir='';
					continue LINES;
				}else if(line.charAt(0)=='<'){ //kid
					kid=(line.search('^</'+kid+'>')!=-1)?'':line.substring(1, line.length-1);
					continue LINES;
				}
				
				if(!kid||!GetProp(line, r)){
					continue LINES;
				}
				if(typeof props.koropokkes[kid]=='undefined')
					props.koropokkes[kid]={};
				props.koropokkes[kid][r.key]=r.val;
			
			}else if(dir=='action'){
				if(reg.test(line)){
					dir='';
					continue LINES;
				}
				if(!GetProp(line, r))
					continue LINES;
				
				switch(r.key){
				case 'action':
					props.actions.actions.push(r.val);
					break;
				default:
					props.actions[r.key]=r.val;
					break;
				}//switch(r.key)

			}else if(dir=='field'){
				if(reg.test(line)){
					dir='';
					continue LINES;
				}
				if(!GetProp(line, r))
					continue LINES;
				
				switch(r.key){
				case 'width':
					if(Config.mode)
						cvs.width=parseInt(r.val);
					this.field.style[r.key]=r.val+'px';
					break;
				case 'height':
					if(Config.mode)
						cvs.height=parseInt(r.val);
					this.field.style[r.key]=r.val+'px';
					break;
				default:
					props.actions[r.key]=r.val;
					break;
				}//switch(r.key)
				
			}else if(dir=='scene'){
				if(reg.test(line)){
					dir='';
					continue LINES;
				}
				if(!GetProp(line, r))
					continue LINES;
				
				switch(r.key){
				case 'action':
					break;
				default:
					props.actions[r.key]=r.val;
					break;
				}//switch(r.key)

				props.scene[r.key]=r.val;
			}else if(dir==''){
			
				if(line.charAt(0)=='<'){
				//ディレクティブ
					dir=(line.charAt(1)=='/')?'':line.substring(1, line.length-1);
					reg.compile('^</'+dir+'>');
					continue LINES;
				}
				
				if(!GetProp(line, r))
					continue LINES;
				
				if(U.ArrayInclude(r.key, addprops)){
				// 追加型プロパティーは配列に追加
//alert(r.key+' '+props[r.key]+' '+typeof prs[r.key])
					if(typeof props[r.key]=='undefined')
						props[r.key]=[];
					props[r.key].push(r.val);
				}else{
				// 既存プロパティーに上書き
					props[r.key]=r.val;
				}

			}else{ //if(dir)
				
			}

		}//LINES:for
		delete GetProp;
		return this;
		
		/****/
		function GetProp(line, r){
			var p=line.indexOf(' ');
			if(p==-1)
				p=line.indexOf('\t');
			r.key=line.substring(0, p);
			r.val=U.Trim(line.substring(p+1));
			if(r.val=='false')
				r.val=false;
			return !!r.key;
		}
	};
/****
各プロパティの保存処理とか
****/
	this.toString=function(){
		return 'Field:'+this.id;
	};//
	
/****/
	this.Load=function(){
		var url=AJAX_BASE_URL+'koropokke/descript.txt';
D.Out(0,this.id,url);
		var cb=this;
		callback=function(o){cb.Init(o);};
		Dabten.Net.Load(url, callback, {async:true, force:false});
		return this;
	};//
	
/****/
	this.LoadScene=function(){
		var uri=AJAX_BASE_URL+'koropokke/field/posture.xml';
		var o=Dabten.Net.Load(uri, null, {async:false, force:false});
		this.Isolate(o.client);
		
		delete o.client;
		delete o;
		delete this.Isolate;
		return this;
	};//
/****/
	this.Isolate=function(client){
		var xml=client.responseXML;
		var ps;
		var baseurl=AJAX_BASE_URL+'koropokke/field/';
		if(!xml)
			return this;
		
		ps=xml.getElementsByTagName('meta');
		for(var i=0,p,src,id;p=ps[i];i++){
			var nm=p.getAttribute('name');
			var con=p.getAttribute('content');
			if(nm=='width'){
				if(Config.mode)
					cvs.width=parseInt(con);
				this.field.style.width=con+'px';
			}else if(nm=='height'){
				if(Config.mode)
					cvs.height=parseInt(con);
				this.field.style.height=con+'px';
			}
		}//for xml.childNodes


		ps=xml.getElementsByTagName('scene');
		for(var i=0,p,img,id,base;p=ps[i];i++){
			if(p.nodeType!=1)
				continue;
			
			id=p.getAttribute('id');
			base=p.getAttribute('base');
			if(!id || !base)
				continue;
			//if(!Config.mode)
			//	base=base.replace(/\.png$/, '.gif');
			img=new Image();
			img.loaded=false;
			img.onload=function(){this.loaded=true;};
			img.src=baseurl+base;
			scenes[id]={id:id, img:img};
			img=null;
		}//for xml.childNodes

		return this;
	};//

/****/
	this.LoadKoropokke=function(){
		var ks=[];
		var master=null;
		var k='';
		for(var kid in props.koropokkes){
			k=props.koropokkes[kid];
			if(k['master']!==undefined && k['master']!=='0' && !!k['master']){
				master=[kid, k];
				continue;
			}
			ks.push([kid, k]);
		}
		if(master)
			ks.unshift(master);
		koropokkes.length=ks.length;
		for(var i=ks.length-1,k,koro;i>=0;i--){
			koro=new Koropokke(this, ks[i][0], ks[i][1]);
D.Out(0,'LoadKoro', koro);
			koro.Load();
			koropokkes[i]=koro;
			koro=null;
		}
		props.koropokkes=null;
		master=k=null;
		return this;
	};//

/****/
	this.LoadAction=function(){
		this.action=new Action(this, props.actions);
		this.action.Init();
		props.actions=null;
		return this;
	};//

/****/
	this.GetKoropokkeByNumber=function(num){
		return (num<koropokkes.length)?koropokkes[num]:null;
	};//
	
/****/
	this.GetKoropokkeById=function(id){
		for(var i=0;i<koropokkes.length;i++){
			if(koropokkes[i].id==id)
				return koropokkes[i];
		}
		return null;
	};//
	
/****/
	this.GetKoropokkeByName=function(nm){
		for(var i=0;i<koropokkes.length;i++){
			if(koropokkes[i].name==nm)
				return koropokkes[i];
		}
		return null;
	};//

/****/
	this.SetBalloon=function(){
		return this;
	};//

/****/
	this.SetScene=function(src){
		var tmp=src.split(',');
		var id=tmp[0],x=0,y=0, sc=null;
		if(id=='-1'){
			if(Config.mode)
				ctx.clearRect(0,0,cvs.width,cvs.height);
			else
				ctx.src=spacer.src;
			
			return this;
		}else if(tmp.length==3){
			x=tmp[1];
			y=tmp[2];
		}
		if(isNaN(id)){
			if(scenes[id]!=null){
				sc=scenes[id];
			}else if(id.indexOf('http://')!=-1 || id.indexOf('https://')!=-1){
				img=new Image();
				img.loaded=false;
				img.onload=function(){this.loaded=true;};
				img.src=id;
				scenes[id]={id:id, img:img};
				sc=scenes[id];
			}
		}else{
			var cnt=0;id=parseInt(id);
			for(var i in scenes){
				if(id==cnt++){
					sc=scenes[i];
					break;
				}
			}
		}
D.Out(D.elms[1],x,y,Config.mode?cvs.width:'0',sc?sc.img.width:'sc=null',sc?sc.img.src:'sc=null');
		if(!sc)
			return this;
			
		if(Config.mode){
			if(x=='center')
				x=(cvs.width-sc.img.width)*0.5;
			if(y=='center')
				y=(cvs.height-sc.img.height)*0.5;
			ctx.clearRect(0,0,cvs.width,cvs.height);
			if(sc.img.loaded)
				ctx.drawImage(sc.img, Number(x), Number(y));
			else
				sc.img.onload=function(){this.loaded=true;ctx.drawImage(this, Number(x), Number(y));};
		}else{
			ctx.src=sc.img.src;
			if(x=='center')
				x=0;
			if(y=='center')
				y=0;
			
			ctx.style.top=y+'px';
			ctx.style.left=x+'px';
		}
		return this;
	};//

/****/
	this.ShowMessage=function(data, geo, add){
		if(add=='-'){
			this.board.innerHTML='';
			return this;
		}
		var opts={position:'static',top:0,left:0,width:'200px',height:'200px',float:'left'}
		ParseRead(geo, opts);
		
		if(!isNaN(data))
			data=Number(data);
		
		if(!!ads[data])
			data=ads[data];
		
		if(!data)
			return this;
		
		var div='<div style="';
		for(var i in opts)
			div+=i+':'+opts[i]+';';
		div+='">'+data+'</div>';
		
		if(add=='+')
			this.board.innerHTML+=div;
		else if(add=='*')
			this.board.innerHTML=div+this.board.innerHTML;
		else
			this.board.innerHTML=div;
		return this;
	};//

/****/
	this.CloseAllBalloon=function(){
		for(var i=0,k;k=koropokkes[i];i++){
			k.balloon.Close();
		}
		return this;
	};//
/****/
	this.ClearAllBalloon=function(){
		for(var i=0,k;k=koropokkes[i];i++){
			k.balloon.Clear();
		}
		return this;
	};//
/****/
	this.ResetAllPose=function(dt){
D.Out(0, 'ResetAllPose');
		for(var i=0,k;k=koropokkes[i];i++){
			k.SetPose(0);
			k.Draw(this.field, dt);
		}
		return this;
	};//

/****/
	this.Run=function(){
//D.Out(0,'Run',''+(this==window),''+(this==window.fields[0]));
		var dt=new Date();
//D.Out(0, 'fieldRun Start', this.id, this.action.isRun, dt.getTime(), lastAction.talktime, (dt.getTime()- lastAction.talktime));
		if(this.action.isRun){
		//実行中
			lastAction.talktime=dt.getTime();
//D.Out(1,'fieldRun isRun',this.id, lastAction.talktime);
			this.action.Run(dt);
		}else if(dt.getTime()-lastAction.talktime>TALK_INTERVAL){
		//フリートーク
			lastAction.talktime=dt.getTime();
//D.Out(1,'fieldRun Free',this.id, lastAction.talktime);
			this.action.FreeTalk(dt);
			
		}else{
//D.Out(1,'fieldRun else',this.id, now);
		}
		//アニメーション
		//if(Config.mode){
		for(var i=0;i<koropokkes.length;i++){
			koropokkes[i].Draw(this.field, dt);
		}
		//}
//D.Out(1, 'fieldRun End', this.id, dt.getTime());
		return this;
	};
};//

