function Koropokke(fld, id, props){
	this.id=id;
	this.name=props.name||id;
	this.balloon=null;
	this.aiEvents=new AiEvents();

	var field=fld;
	
	//var tm=0;
	
	var onDrag=false;
	var dragpos={x:0,y:0};

	var cvs=null;
	var ctx=null;

	if(!props)
		props={};
	
	//var defaultPosture=props.defaultposture||0; //デフォルトポーズ
	var postures={};
	var pose=0;//defaultPosture;

	if(!props.pos)
		props.pos={};

	//var pos={ // デフォルトポジション
	//	 baseY:props.pos.basey||S_B
	//	,baseX:props.pos.basex||S_L
	//	,y:props.pos.y==undefined?0:props.pos.y
	//	,x:props.pos.x==undefined?0:props.pos.x
	//};//pos

	if(!props.size)props.size={};
	this.geo={
		 width:props.size.width||K_WIDTH
		,height:props.size.height||K_HEIGHT
		,baseY:props.pos.basey||S_B
		,baseX:props.pos.basex||S_L
		,y:(props.pos.y==undefined)?0:props.pos.y
		,x:(props.pos.x==undefined)?0:props.pos.x
	};//size

	var balgeo={
		 basex:props['balloon-position']||'left'
		,type:props['balloon-type']||'default'
		,x:null
		,y:null
	};//balpos

/*************/
	this.Load=function(){
		this.Init();
		var uri=AJAX_BASE_URL+'koropokke/koropokke/'+this.id+'/posture.xml';
		var self=this;
		var o=Dabten.Net.Load(uri, null, {async:false,force:false});
		this.Isolate(o.client);
		delete o.client;
		delete o;
		return this;
	};//

/*************/
	this.Init=function(){
		var self=this;
		if(Config.mode){
			cvs=U.CE('canvas');
			ctx=cvs.getContext('2d');
		}else{
			cvs=U.CE('img');
			ctx=cvs;
		}

		cvs.style.position='absolute';
		cvs.style.top='auto';
		cvs.style.bottom='0px';
		cvs.style.left='auto';
		cvs.style.right='0px';
		cvs.width=this.geo.width;
		cvs.height=this.geo.height;
		cvs.onclick=function(e){self.OnClick(e);};
		//cvs.onmousemove=function(e){self.OnMouseMove(e);};
		//cvs.onmousedown=this.OnMouseDown;
		//cvs.onmouseup=this.OnMouseUp;
		this.balloon=new Balloon();
		this.balloon.Init(field, this);
		this.balloon.SetStyle({
					 top:0
					,left:(balgeo.x - B_WIDTH )+'px'
					});
		this.balloon.SetClass(balgeo.type, (balgeo.size=='normal')?'mini':'normal');

		field.field.insertBefore(cvs, field.field.lastChild);
		//this.balloon.AddTo(field.field, field.field.lastChild);
		this.balloon.AddTo(field.field.lastChild, null);
		
		delete this.balloon.Init;
		delete this.balloon.AddTo;
		
		return this;
	};//

	/****/
	this.Destroy=function(){
		this.balloon=null;
		field.field.removeChild(cvs);
		cvs=ctx=null;
		for(var i in postures)
			postures[i]=null;
		
	};
	
/*************/
	this.Isolate=function(client){
		var xml=client.responseXML;
		var ps;
		var baseurl=AJAX_BASE_URL+'koropokke/koropokke/'+this.id+'/';
		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=='name')
				this.name=con;
			else if(nm=='width')
				cvs.width=this.geo.width=parseInt(con);
			else if(nm=='height')
				cvs.height=this.geo.height=parseInt(con);
			else if(nm=='x'){
				this.geo.x=parseInt(con);
				if(this.geo.baseX==S_L)
					cvs.style.left=this.geo.x+'px';
				else if(this.geo.baseX==S_R)
					cvs.style.right=this.geo.x+'px';
				
			}else if(nm=='y'){
				this.geo.y=parseInt(con);
				if(this.geo.baseY=='top')
					cvs.style.top=this.geo.y+'px';
				else if(this.geo.baseY=='bottom')
					cvs.style.bottom=this.geo.y+'px';

			}else if(nm=='basex'){
				if(con=='right'){
					cvs.style.left='auto';
					cvs.style.right=this.geo.x+'px';
					this.geo.baseX=S_R;
				}else if(con=='left'){
					cvs.style.right='auto';
					cvs.style.left=this.geo.x+'px';
					this.geo.baseX=S_L;
				}
			}else if(nm=='basey'){
				if(con=='top'){
					cvs.style.top=this.geo.y+'px';
					cvs.style.bottom='auto';
					this.geo.baseY=S_T;
				}else if(con=='bottom'){
					cvs.style.top='auto';
					cvs.style.bottom=this.geo.y+'px';
					this.geo.baseY=S_B;
				}
			}else if(nm=='balloon'){
				balgeo.basex=(con=='left')?'left':'right';
			}else if(nm=='balloon-type'){
				this.balloon.SetClass(con);
			}else if(nm=='balloon-top'){
				balgeo.y=parseInt(con);
			}else if(nm=='balloon-left'){
				balgeo.x=parseInt(con);
			}
		}
		
		ps=xml.getElementsByTagName('posture');
		PS:for(var i=0,p,src,id;p=ps[i];i++){
			if(p.nodeType!=1)
				continue;
			
			id=p.getAttribute('id');
			base=p.getAttribute('base');
			if(!id || !base)
				continue;
			
			postures[id]=new Posture(id, base, baseurl, this.geo);
			//if(Config.mode){
			TOON:for(var j=0,elm;elm=p.childNodes[j];j++){
				switch(elm.nodeName){
				case 'anim':
				case 'animate':
				case 'animation':
					postures[id].AddAnim(elm);
					break;
				case 'point':
					postures[id].SetPoint(elm);
					break;
				case 'region':
					postures[id].SetRegion(elm);
					break;
				default:
					break;
				}
			}//TOON:for
			//}//if(Config.mode)
		}//for PS:for

if(1){
	var left=0,top=0;
		if(balgeo.x!==null)
			left=balgeo.x;
		else
			left=(balgeo.basex=='right')
					?( (this.geo.basex=='right')?field.field.clientWidth-this.geo.x:this.geo.x+this.geo.width)
					:( ( (this.geo.basex=='left')?this.geo.x:field.field.clientWidth-this.geo.x-this.geo.width )-B_WIDTH);
		
		if(balgeo.y!==null)
			top=balgeo.y;
		else
			top=(this.geo.height<B_HEIGHT)?field.field.clientHeight-B_HEIGHT:field.field.clientHeight-this.geo.height;
		
		this.balloon.SetStyle({
			 top:top+'px'
			,left:left+'px'
		});

}
		return this;
	};//

/*************
postures.Draw
 posturesのアニメーションIDを返す。
 アニメーションが終了したら0を返す。
/*************/
	this.SetPose=function(id){
		if(id===undefined)
			pose=0;
		else if(isNaN(id))
			pose=postures[id]?id:0;
		else if(id=='-1'){
			if(Config.mode)
				ctx.clearRect(0,0, this.geo.width, this.geo.height);
			else
				cvs.src=SPACER_URI;
			pose=-1;
			return this;
		}else{
			var c=0;
			pose=0;
			for(var i in postures){
				if(id==c++){
					pose=i;
					break;
				}
			}
		}
		
		var p=postures[pose];
		if(p)
			p.Init();

		return this;
	}
/*************/
	this.Draw=function(doc, dt){
		var now=dt.getTime();
		var p=postures[pose];
		
		if(!p)
			return null;

		var ret=p.Draw(ctx, now);
		
		return ret;
	};//

/*************/
	this.IsAnim=function(doc, dt){
		var p=postures[pose];
		return (p && p.IsAnim());
	};//

/*************/
	this.Talk=function(elm, msg, rgn){
		//field.CloseAllBalloon();
		//field.action.Stop();
		if(!rgn)
			rgn='onmenu';
		field.action.GetEvent(rgn, this);
		
		return this;
	};//

/*************/
	this.Move=function(x,y){
		cvs.style.top=y+'px';
		cvs.style.left=x+'px';
		return this;
	};//

/*************/
	this.OnClick=function(e){
		if(!e)e=window.event;
		var tar=e.target||e.srcElement;
		onDrag=false;
		var po=U.GetPos(tar);
		if(!postures[pose])
			return this;
		var x=(e.x||e.pageX||e.clientX||0)-po[0];
		var y=(e.y||e.pageY||e.clientY||0)-po[1];
		var region=postures[pose].HitTest(x, y);
//alert(['x '+e.x,'pageX '+e.pageX,'clientX '+e.clientX,'offsetX '+e.offestX,'po '+po[0],'x '+x, 'y '+y, 'region:'+region].join('\n'));
		this.Talk(tar, 'click', region);
		return this;
	};//

/*************/
	this.OnMouseMove=function(e){
		if(!e)e=window.event;
		var tar=e.target||e.srcElement;
		var po=U.GetPos(tar);
		if(onDrag){
			var x=(e.x||e.pageX||e.clientX||0)-po[0];
			var y=(e.y||e.pageY||e.clientY||0)-po[1];
			this.style.top=(dragpos.y-y)+'px';
			this.style.left=(dragpos.x-x)+'px'
			dragpos.x=e.x||e.pageX;
			dragpos.y=e.y||e.pageY;
			return this;
		}
		if(!postures[pose])
			return this;
		var x=(e.x||e.pageX||e.clientX||0)-po[0];
		var y=(e.y||e.pageY||e.clientY||0)-po[1];
		var region=postures[pose].HitTest(x, y);
		if(region){
			//action.Talk('move', region);
		}
		return this;
	};//

/*************/
	this.OnMouseDown=function(e){
		onDrag=true;
		dragpos.x=e.x||e.pageX||e.clientX||0;
		dragpos.y=e.y||e.pageY||e.clientY||0;
		return this;
	};//

/*************/
	this.OnMouseUp=function(){
		if(!onDrag)
			return this;
		onDrag=false;
		var x=(e.x||e.pageX||e.clientX||0)-po[0];
		var y=(e.y||e.pageY||e.clientY||0)-po[1];
		this.style.top=(dragpos.y-y)+'px';
		this.style.left=(dragpos.x-x)+'px'
		return this;
	};//

/*************/
	this.toString=function(){
		return 'poke:'+this.id;
	};//

};//
