/**************
motel.js ver 20061213.1
(c) WATARU, 2006
http://wi-wi.jp/
**************/
var _MotelTM=32;
var _Moteldelay=0;
var _Motelsec=0;
function _Motel(){
	this.motions={};
	this.active=new Array();
	this.prefer=new Array();
	this.defines=new Array();
	this.reserved=new Array();
	this.meta={};
	this.tm=0;
	this.ajReq=null;
	this.docwidth=0;
	this.docheight=0;
	this.load=function(uri,cache,user,pass){
		if(!cache){
			var d=new Date();
			var s=d.getTime();
			uri+='?'+s;
		}
		this._loadXML(uri,user,pass);
	};//load
	this.start=function(mid,el,o,cb){
		var id=0, element, opt,callback;
		if(typeof(mid)=='number'){
			id=mid;
			if(!this.prefer[id]){
				this.reserved[id][4]=true;
				return id;
			}
		}else{
			if(!el)return -1;
			if(!this.motions[mid]){
				if(this.start.arguments[4]==true){return -1;}
				var res=[mid,el,o,cb,true];
				this.reserved.push(res);
				return this.reserved.length+this.prefer.length-1;
			}
			element=(typeof(el)=='string')?document.getElementById(el):el;
			if(!element)return -1;
			opt=o||null;
			callback=cb||null;
			id=this.set(mid, element,opt,callback);
		}
		if(id<0)return id;
		if(this.active[id]!=null){this.stop(id);}
		this.active[id]=this.prefer[id];
		if(!!element){
			this.active[id].element=element;
		}
		this.active[id]._init(0);
		if(!this.tm){
			var d=new Date();
			_Motelsec=d.getTime();
			this.tm=setInterval('Motel.run()',_MotelTM);
		}
		return id;
	};//start
	this.stop=function(id){
		this.active[id]=null;
		return true;
	};//stop
	this.stopall=function(id){
		this.tm=clearInterval(this.tm);
		for(var i=0;i<this.active.length;i++)
			this.active[i]=null;
		return true;
	};//stopall
	this.set=function(motionid,el,opt,callback){
		if(!this.motions[motionid]){
			if(this.set.arguments[4]==true){return -1;}
			var res=[motionid,el,opt,callback,false];
			this.reserved.push(res);
			return this.reserved.length-1;
		}
		newid=this.active.length;
		var moinfo=this.motions[motionid];
		if(!moinfo)return -1;
		var mo=new _Motion(moinfo[0][0], moinfo[0][1], moinfo[0][2]);//id, limit,callback
		if(!mo)return -1;
		if(typeof(el)=='string'){
			mo.elements[0]=document.getElementById(el);
		}else{
			if(typeof(el) =='Array' || el.constructor == Array || el.length){
				for(var i=0;i<el.length;i++){
					mo.elements[i]=el[i];
				}
			}else{
				mo.elements[0]=el;
			}
		}
		if(!mo.elements)return -1;
		var oldgrp=null;
		var elcnt=-1;
		var len=mo.elements.length;
		for(var i=1;i<moinfo.length;i++){
			var thisgroup=moinfo[i].group;
			if(!oldgrp){
				if(elcnt<0){
					elcnt=0;
				}else{
					var info=moinfo[i-1];
					for(var elcnt=0;elcnt<len;elcnt++){
						if(!mo.elements[elcnt])continue;
						var toon=new _Toon(info,mo.elements[elcnt]);
						mo._add(toon,elcnt==0);
					}
					elcnt=0;
				}
			}else if(oldgrp==thisgroup){
				var info=moinfo[i-1];
				var toon=new _Toon(info,mo.elements[elcnt]);
				mo._add(toon,elcnt==0);
				elcnt++;
			}else{// if(oldgrp!=thisgroup){
				var k=i-1;
				for(;elcnt<len;elcnt++){
					var toon=new _Toon(moinfo[k],mo.elements[elcnt]);
					mo._add(toon,elcnt==0);
				}
				elcnt=0;
			}//if
			oldgrp=thisgroup;
		}//for
			if(!oldgrp){
				var info=moinfo[moinfo.length-1];
				for(var elcnt=0;elcnt<len;elcnt++){
					var toon=new _Toon(info,mo.elements[elcnt]);
					mo._add(toon,elcnt==0);
				}
			}else{// if(oldgrp!=thisgroup){
				var k=moinfo.length-1;
				for(;elcnt<len;elcnt++){
					var toon=new _Toon(moinfo[k],mo.elements[elcnt]);
					mo._add(toon,elcnt==0);
				}
			}//if
		
		mo.opt=opt;
		if(!!callback) mo.callback=callback;
		this.prefer[newid]=mo;
		this.active.length=newid+1;
		this.active[newid]=null;
		return newid;
	};//set
	this.run=function(){
		var d=new Date();
		var s=d.getTime();
		_Moteldelay-=(s-_Motelsec);
		if(_Moteldelay>0){
			return;
		}
		var l=this.active.length;
		var isRun=false;
		for(var i=0;i<l;i++){
			if(this.active[i]==null || !this.active[i]._run(s)){isRun=true;continue;}
			if(this.active[i].callback){
				var c=this.active[i].callback;
				if(typeof(c)=='number'){
					this.start(c);
				}else if(c.indexOf('(')<0){
					if(fu.match(/[^\d]/)){
						this.active[i].callback=this.start(c,this.active[i].elements, null, null);
					}else{
						this.start(c);
					}
				}else{
					eval(c);
				}
			}
			this.active[i]=null;
		}//for
		d=new Date();
		_Motelsec=d.getTime();
		_Moteldelay=0;
		if(!isRun)this.tm=clearInterval(this.tm);
	};//run
	this.init=function(){
		var doc;
		if(!!document.body){
			doc=document.body;
		}else if(!!document.documentElement){
			doc=document.documentElement;
		}
		if(!doc){return;}
		for(var i=0;i<this.reserved.length;i++){
			var r=this.reserved[i];
			if(r[4]){
				this.start(r[0], r[1], r[2], r[3]);
			}else{
				this.set(r[0],r[1],r[2],r[3]);
			}
		}
		var l=this.defines.length;
		var elements=new Array();
		defs:for(var i=0;i<l;i++){
			var df=this.defines[i];
			pa=df.motparent;
			if(!pa){
				doc.appendChild(df);
			}else{
				var elm=document.getElementById(pa);
				if(!!elm){
					elm.appendChild(df);
				}else{
					doc.appendChild(df);
				}
			}
			var dfm=df.motmotion;
			if(!dfm) continue;
			for(var j in elements){
				if(j==dfm){
					elements[j].push(df);
					continue defs;
				}
			}
			elements[dfm]=new Array();
			elements[dfm].push(df);
		}
		for(var j in elements){
			this.start(j, elements[j], null, null);
		}
		var cb=this.meta['onload'];
		if(cb!==undefined && cb!==null){
			if(typeof(cb)=='function'){
				cb();
			}else{
				eval(cb);
			}
		}
	};//init
	this._parseXML=function(){
		var xml=this.ajReq.responseXML;
		if(!xml)return;
		var xmldefs=xml.getElementsByTagName('define');
		var xmlmos=xml.getElementsByTagName('motion');
		for(var i=0;i<xmlmos.length;i++){
			var xmlmo=xmlmos[i];
			var motionid=xmlmo.getAttribute('id');
			var motionlimit=xmlmo.getAttribute('limit')||1;
			var motioncb=xmlmo.getAttribute('callback')||'';
			if(!motionid){continue;}
			var m=new Array();
			m[0]=new Array(motionid, motionlimit, motioncb);
			if(!!xmlmo.childNodes){
			for(var c=0;c<xmlmo.childNodes.length;c++){
				var item=xmlmo.childNodes[c];
				if(item.nodeType!=1)continue;
				var effect=item.getAttribute('effect');
				if(!effect)continue;
				var base=item.getAttribute('base');
				var start=item.getAttribute('start');//start=start.replace(/'/g, '\\'');
				var end=item.getAttribute('end');//end=end.replace(/'/g, '\\'');
				var delay=item.getAttribute('delay')||0;
				var id=item.getAttribute('id');
				var formula=item.getAttribute('formula');
				var vector=item.getAttribute('vector');
				var range=item.getAttribute('range')||0;
				var group=item.getAttribute('group');
				var time=item.getAttribute('time')||0;
				var toon={effect:effect,base:base,start:start,end:end,delay:delay,id:id,formula:formula,vector:vector,range:range,group:group,time:time};
				m.push(toon);
			}}//if for
			this.motions[motionid]=m;
		}
		for(var i=0;i<xmldefs.length;i++){
			var xmldef=xmldefs[i];
			for(var c=0;c<xmldef.childNodes.length;c++){
				var item=xmldef.childNodes[c];
				if(item.nodeType!=1)continue;
				var id=item.getAttribute('id');
				var nodeName=item.nodeName;
				var theNode;
				var src,alt,text;
				if(nodeName=='meta'){
					var name=item.getAttribute('name');
					var content=item.getAttribute('content');
					this.meta[name]=content;
					continue;
				}
				if(nodeName!='img' && nodeName!='object') continue;
				if(!!id && (theNode=document.getElementById(id))){
					var motion=item.getAttribute('motion');
					var onclick=item.getAttribute('onclick');
					var onmouseover=item.getAttribute('onmouseover');
					var onmouseout=item.getAttribute('onmouseout');
					var ondblclick=item.getAttribute('ondblclick');
					if(!!motion)theNode.motmotion=motion;
					//if(!!onclick)theNode.onclick=function(){Motel._click(this,onclick);};
					this.defines.push(theNode);
					continue;
				}
				if(nodeName=='img'){
					src=item.getAttribute('src');
					alt=item.getAttribute('alt');
				}else if(nodeName=='object'){
					nodeName=item.getAttribute('node');
					text=item.firstChild.nodeValue;
				}
				var width=item.getAttribute('width');
				var height=item.getAttribute('height');
				var clone=item.getAttribute('clone');
				var className=item.getAttribute('class');
				var title=item.getAttribute('title');
				var motion=item.getAttribute('motion');
				var parent=item.getAttribute('parent');
				var onclick=item.getAttribute('onclick');
				var onmouseout=item.getAttribute('onmouseout');
				var ondblclick=item.getAttribute('ondblclick');
//				if(!id)continue;
				if(nodeName=='img' && !src)continue;
				for(var i=0;i<=clone;i++){
					theNode=document.createElement(nodeName);
					if(i==0){
						theNode.id=id;
					}else{
						theNode.id=id+i;
					}
					if(!!width)theNode.style.width=width+'px';
					if(!!height)theNode.style.height=height+'px';
					if(!!className)theNode.className=className;
					if(!!title)theNode.title=title;
					if(!!src)theNode.src=src;
					if(!!alt)theNode.alt=alt;
					if(!!text)theNode.appendChild(document.createTextNode(text));
					if(!!motion)theNode.motmotion=motion;
					//if(!!onclick)theNode.onclick=function(){Motel._click(this,onclick);};
					theNode.style.position='absolute';
					if(!theNode.motmotion){theNode.style.visibility='hidden';}
					if(!!parent)theNode.motparent=parent;
					this.defines.push(theNode);
				}//for(close)
			}//for(c<xmldef.childNodes.length){
		}
		this.Env.getDocWH();
		this.init();
		if(!!window.addEventListener){
			window.addEventListener('resize', Motel.Env.getDocWH, false);
			window.addEventListener('unload', Motel.Unload, false);
		}else if(!!window.attachEvent){
			window.attachEvent('onresize', Motel.Env.getDocWH);
			document.attachEvent('onunload', Motel.Unload);
		}

	};//parseXML
	this.getenv=function(name){
		return this.meta[name];
	};//getenv
	this.setenv=function(name,content){
		this.meta[name]=content;
	};//getenv
	this.Unload=function(){
		if(window.RemoveEventListener){
			window.RemoveEventListener('resize', Motel.Env.getDocWH, false);
			document.RemoveEventListener('unload', Motel.Unload, false);
		}else if(window.dettachEvent){
			window.dettachEvent('onresize', Motel.Env.getDocWH);
			document.dettachEvent('onunload', Motel.Unload);
		}
	};
	this._click=function(el,src){
		if(src.indexOf('(')<0){
//			Motel.start(src, el);
		}else{
			eval(src);
		}
	};//_click
	function _Motion(mid, limit, cb){
		this.id=mid;
		this.limit=limit;
		this.cnt=0;
		this.elements=new Array();
		this.callback=cb;
		this.toons=new Array();
		this.act=0;

		this._init=function(id){
			var mid=(!!id)?id:0;
			if(mid==0){
				this.act=0;
				this.cnt=0;
			}
			for(var i=0;i<this.toons[mid].length;i++){
				this.toons[mid][i].stime=0;
			}
		};//_init
		this._run=function(sec){
			while(1){
			var finished=true;
			var runnext=false;
			var l=this.toons[this.act].length;
			for(var i=0;i<l;i++){
				var to=this.toons[this.act][i];
				if(!to.element)continue;
				if(to.stime==0) to.__init(sec,(this.act==0)?null:this.toons[this.act-1][i].end,i);
				var re=to.__run(sec,i);
				if(re==0){
					finished=false;
				}else if(re<0){
					runnext=true;
				}
			}
			if(runnext){
				if(++this.act<this.toons.length){
					this._init(this.act);
					continue;
				}
			}//if(runnext)
			break;
			}//while
			if(!finished){return false;}
			if(++this.act<this.toons.length){
				this._init(this.act);
				return false;
			}
			if(this.limit!=0 && this.limit<=++this.cnt){
				return true;
			}
			this._init();
			return false;
		};//_run
		this._add=function(toon, isNew){
			var i;
			with(this){
			for(i=0;i<toons.length;i++){
				if(!!toon.group && toon.group==toons[i][0].group){
					toon.__setdelay(toons[i].length);
					toons[i].push(toon);
					return;
				}
			}
			if(i==toons.length && isNew){
				toons[i]=new Array();
				toon.__setdelay(0);
				toons[i].push(toon);
			}else{
				toon.__setdelay(toons[toons.length-1].length+1);
				toons[toons.length-1].push(toon);
			}
			}//with
		};//_add
	};//_Motion
	function _Toon(info,el){
		var tmp;
		this.effect=info.effect;
		this.base=info.base||'top,left';
		this.elid=info.id;//need ?
		this.element=null;
			if(!!this.elid){
				this.element=document.getElementById(this.elid);
			}else if(!!el){
				this.element=el;
			}
		this.start={top:null,left:null,right:null,bottom:null,width:null,height:null,opacity:null,list:[]};
		this._start={top:null,left:null,right:null,bottom:null,width:null,height:null,opacity:null,list:[]};
		if(!!info.start){
			this._start=ParseAttr(this._start, info.start);
		}
		this.end={formula:null,vector:null,range:null,top:null,left:null,right:null,bottom:null,width:null,height:null,opacity:null,list:[]};
		this._end={formula:null,vector:null,range:null,top:null,left:null,right:null,bottom:null,width:null,height:null,opacity:null,list:[]};
//		if(this.effect!='wait')
//			this._end={top:this._start.top,left:this.start.left,y:this.start.y,x:this.start.x,opacity:this.start.opacity};
		if(!!info.end){
			this._end=ParseAttr(this._end, info.end);
		}
		this._end['formula']=info.formula;
		this._end['vector']=info.vector;
		this._end['range']=info.range;

		this.delay=parseInt(info.delay)||0;
		this.group=info.group;
		this.time=parseInt(info.time);
		this.stime=0;
		this.__init=function(now,pre){
			this.stime=now;
			with(this){
			if(effect=='move'){
				var p;
				if((_start.top==null || _start.left==null) && !pre){
					p=Motel.Pos(this.element);
				}else{
					p=pre;
				}
				start.top=(_start.top==null)?p.top:Motel.calc(_start.top,this.element,pre);
				start.left=(_start.left==null)?p.left:Motel.calc(_start.left,this.element,pre);
				end.top=(_end.top==null)?start.top:Motel.calc(_end.top,this.element,pre);
				end.left=(_end.left==null)?start.left:Motel.calc(_end.left,this.element,pre);
			}else if(effect=='resize'){
				start.width=(_start.width==null)?p.width:Motel.calc(_start.width,this.element,pre);
				start.height=(_start.height==null)?p.height:Motel.calc(_start.height,this.element,pre);
				end.width=(_end.width==null)?start.width:Motel.calc(_end.width,this.element,pre);
				end.height=(_end.height==null)?start.height:Motel.calc(_end.height,this.element,pre);
			}else if(effect=='opacity'){
				start.opacity=(_start.opacity!==null)?Motel.calc(_start.opacity):Motel.calc(_start.list[0]);
				end.opacity=(_end.opacity!==null)?Motel.calc(_end.opacity):Motel.calc(_end.list[0]);
			}else{
				for(var i in _start)
					if(_start[i]!==null && i!=='list')
						start[i]=Motel.calc(_start[i],this.element,pre);
					else
						start[i]=_start[i];
				for(var i in _end)
					if(_end[i]!==null && i!=='list')
						end[i]=Motel.calc(_end[i],this.element,pre);
					else
						end[i]=_end[i];
			}//if(effect)
			}//with
		};//__init
		this.__run;
		this.__setdelay=function(magni){
			this.delay*=magni;
		};//__setdelay
		if(!this.element){
			this.__run=function(){return 1;};
		}else if(this.effect=='move'){
			this.__run=move;
		}else if(this.effect=='opacity'){
			if(!this.element){
					this.__run=function(){return 1;};
			}else if(this.element.filters){
//				if(this.element.filters.item && typeof(this.element.filters.item)=='function'){
					this.__run=opacity_filter;
//				}else{
//					this.__run=function(){return 1;};
//				}
			}else{
				this._start.opacity/=100;
				this._end.opacity/=100;
				this.__run=opacity_opacity;
			}
		}else if(this.effect=='clip'){
			this.__run=clip;
			with(this.start){
				if(!right || !right==null)right='auto';
				if(!right || !top==null)top='auto';
				if(!right || !left==null)left='auto';
				if(!right || !bottom==null)bottom='auto';
			}
		}else if(this.effect=='resize'){
			this.__run=resize;
		}else if(this.effect=='rect'){
			this.__run=rect;
		}else if(this.effect=='poly'){
			this.__run=poly;
		}else if(this.effect=='circle'){
			this.__run=circle;
		}else if(this.effect=='ellipse'){
			this.__run=ellipse;
		}else if(this.effect=='conc'){
			this.__run=conc;
		}else if(this.effect=='wait'){
			this.__run=wait;
		}else{
			this.__run=function(){return 1;};
		}
		function ParseAttr(o, str){
			var arys=str.split(';');
			//var rg=/\D_-\S\W\w/;
			for(var i=0;i<arys.length;i++){
				if(!arys[i])continue;
				var ar=arys[i].split(':');
				if(ar.length==1){
					var list=ar.split(',');
					var i=o['list'].length;
					o['list'].length=i+list.length;
					for(;i<list.length;i++){
						o['list'][i]=list[i];
					}
				}else{
					if(o[ar[0]]===undefined){
						o['list'].push(arys[i]);
					}else{
						o[ar[0]]=ar[1];
					}
				}
			}
			return o;
		}//ParseAttr
	};//_Toon
	function move(now){
		var sec=now;
		sec=sec-this.stime;
		var finished=0;
		with(this){
		if(delay>sec) return 0;
		sec-=delay;
		if(sec>=time){
			if(end.top!=null)element.style.top=end.top+'px';
			if(end.left!=null)element.style.left=end.left+'px';
			return 1;
		}
		var dift,difl;
		var prop=sec/time;
		if(start.top==end.top){
			dift=end.top;
		}else{
			dift=start.top+(end.top-start.top)*prop;
			if((start.top<end.top && end.top<dift) || (start.top>end.top && end.top>dift)){
				dift=end.top;
				finished=1;
			}
		}
		if(start.left==end.left){
			difl=end.left;
		}else{
			difl=start.left+(end.left-start.left)*prop;
			if((start.left<end.left && end.left<difl) || (start.left>end.left && end.left>difl)){
				difl=end.left;
				finished=1;
			}
		}
		element.style.top=parseInt(dift).toString()+'px';
		element.style.left=parseInt(difl).toString()+'px';
		}//with
		return finished;
	}//move
	function opacity_filter(now){
		var sec=now;
		sec=sec-this.stime;
		var finished=0;
		with(this){
		if(delay>sec) return 0;
		sec-=delay;
		if(sec>=time){
			try{element.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=end.opacity;}catch(e){}
			return 1;
		}
		dalpha=end.opacity-start.opacity;
		var opacity=parseInt(start.opacity+dalpha*sec/time);
		try{element.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=opacity;}catch(e){}
//		element.filters[0].opacity=opacity;
		if((start.opacity<=end.opacity && end.opacity<=opacity) || (start.opacity>end.opacity && end.opacity>=opacity)){
			return 1;
		}
		}//with
		return 0;
	}//opacity_filter
	function opacity_opacity(now){
		var sec=now;
		sec=sec-this.stime;
		var finished=0;
		with(this){
		if(delay>sec) return 0;
		sec-=delay;
		if(sec>=time){
			element.style.opacity=end.opacity;
			return 1;
		}
		dalpha=end.opacity-start.opacity;
		var opacity=(start.opacity+dalpha*sec/time);
		element.style.opacity=opacity;
		if((start.opacity<=end.opacity && end.opacity<=opacity) || (start.opacity>end.opacity && end.opacity>=opacity)){
			return 1;
		}
		}//with
		return 0;
	}//opacity_opacity
	function clip(now){
		var sec=now;
		sec=sec-this.stime;
		var finished=0;
		with(this){
		if(delay>sec) return 0;
		sec-=delay;
		var dif;
		var proportion=sec/time;
		var ct,cl,cr,cb;
		if(sec>=time){
			ct=(end.top===null || end.top=='auto')?'auto ':end.top+'px ';
			cr=(end.right===null || end.right=='auto')?'auto ':end.right+'px ';
			cb=(end.bottom===null || end.bottom=='auto')?'auto ':end.bottom+'px ';
			cl=(end.left===null || end.left=='auto')?'auto':end.left+'px';
			element.style.clip='rect('+ct+cr+cb+cl+')';
			return 1;
		}
		if(start.top==end.top){
			ct=end.top;
		}else{
			dif=start.top+(end.top-start.top)*proportion;
			if((start.top<end.top && end.top<dif) || (start.top>end.top && end.top>dif)){
				dif=end.top;
				finished=1;
			}
			ct=parseInt(dif);
		}
		if(start.right==end.right){
			cr=end.right;
		}else{
			dif=start.right+(end.right-start.right)*proportion;
			if((start.right<end.right && end.right<dif) || (start.right>end.right && end.right>dif)){
				dif=end.right;
				finished=1;
			}
			cr=parseInt(dif);
		}
		if(start.bottom==end.bottom){
			cb=end.bottom;
		}else{
			dif=start.bottom+(end.bottom-start.bottom)*proportion;
			if((start.bottom<end.bottom && end.bottom<dif) || (start.bottom>end.bottom && end.bottom>dif)){
				dif=end.bottom;
				finished=1;
			}
			cb=parseInt(dif);
		}
		if(start.left==end.left){
			cl=end.left;
		}else{
			dif=start.left+(end.left-start.left)*proportion;
			if((start.left<end.left && end.left<dif) || (start.left>end.left && end.left>dif)){
				dif=end.left;
				finished=1;
			}
			cl=parseInt(dif);
		}
		element.style.clip='rect('+ct+'px '+cr+'px '+cb+'px '+cl+'px)';
		}//with
		return finished;
	}//clip
	function resize(now){
		var sec=now;
		sec=sec-this.stime;
		var finished=0;
		with(this){
		if(delay>sec) return 0;
		sec-=delay;
		if(sec>=time){
			element.style.width=end.width+'px';
			element.style.height=end.height+'px';
			return 1;
		}
		var difw,difh;
		var prop=sec/time;
		if(start.width==end.width){
			difw=end.width;
		}else{
			difw=start.width+(end.width-start.width)*prop;
			if((start.width<end.width && end.width<difw) || (start.width>end.width && end.width>difw)){
				difw=end.width;
				finished=1;
			}
		}
		if(start.height==end.height){
			difh=end.height;
		}else{
			difh=start.height+(end.height-start.height)*prop;
			if((start.height<end.height && end.height<difh) || (start.height>end.height && end.height>difh)){
				difh=end.height;
				finished=1;
			}
		}
		element.style.width=difw+'px';
		element.style.height=difh+'px';
		}//with
		return finished;
	}//resize
	function rect(now){
	}//rect
	function font(now){
	}//font
	function color(now){
	}//color
	function bgcolor(now){
	}//bgcolor
	function poly(now){
	}//poly
	function circle(now){
	}//circle
	function ellipse(now){
	}//ellipse
	function conc(now){
	}//conc
	function wait(now){
		var sec=now;
		sec=sec-this.stime;
		with(this){
		if(sec==0){
			if(start.top!==null){element.style.top=start.top+'px';}
			if(start.left!==null){element.style.left=start.left+'px';}
			if(start.width!==null){element.style.width=start.width+'px';}
			if(start.height!==null){element.style.height=start.height+'px';}
		}
		if(sec<time) return 0;
		if(end.top!==null){element.style.top=end.top+'px';}
		if(end.left!==null){element.style.left=end.left+'px';}
		if(end.width!==null){element.style.width=end.width+'px';}
		if(end.height!==null){element.style.height=end.height+'px';}
		if(_end.formula){
			var lists=_end.formula.split(';');
			for(var i in lists){
				var pair=lists[i].split('=');
				if(pair[0]=='src')element.src=pair[1];
				else if(pair[0]=='alt')element.title=pair[1];
				else if(pair[0]=='title')element.title=pair[1];
				else if(pair[0]=='position')element.style.position=pair[1];
				else if(pair[0]=='display')element.style.display=pair[1];
				else if(pair[0]=='visibility')element.style.visibility=pair[1];
			}
		}
		if(time==0)return -1;
		return 1;
		}//with
	}//wait
}//_Motel
_Motel.prototype.Env=function(){
	this.docwidth=new Number();
	this.docheight=new Number();
	this.getDocWH=new Function();
};
_Motel.prototype.Env.docwidth=0;
_Motel.prototype.Env.docheight=0;
_Motel.prototype.Env.getDocWH=function(){
	var isIE=!!document.all && !window.opera;
	if(isIE && document.getElementById && document.compatMode=='CSS1Compat'){
		this.docwidth=document.documentElement.clientWidth.toString();
		this.docheight=document.documentElement.clientHeight.toString();
	}else{
		this.docwidth=document.body.clientWidth.toString();
		this.docheight=document.body.clientHeight.toString();
	}
};
_Motel.prototype.calc=function(o,el,pre){
	var rg,p;
	if(!!!o)return 0;
	rg=/^[+-]?[\d\.]+$/;
	if(rg.test(o)){return parseFloat(o);}
	o=o.replace(/ /g,'');
	o=o.replace(/docwidth/g, Motel.Env.docwidth);
	o=o.replace(/docheight/g, Motel.Env.docheight);
	if(el||pre){
		p=Motel.Pos(el,pre);
		o=o.replace(/width/g, p.width);
		o=o.replace(/height/g, p.height);
		o=o.replace(/top/g, p.top);
		o=o.replace(/left/g, p.left);
		o=o.replace(/right/g, p.right);
		o=o.replace(/bottom/g, p.bottom);
	}
	if(o.indexOf('random')){
		;
	}
	try{
		o=eval(o);
	}catch(e){o=0;}
	return parseInt(o);
};
_Motel.prototype._loadXML=function(url,user,password){
	this.ajReq=new createAjax();
	if(!this.ajReq) return;
	this.ajReq.onreadystatechange =function (){
		if(Motel.ajReq.readyState!=4)return;
		if(Motel.ajReq.status == 200)
			Motel._parseXML();
		else if(Motel.ajReq.status==302)
			//alert('Motell : 302 file not modified');
			Motel._parseXML();
		else if(Motel.ajReq.status==404)
			alert('Motell : 404 file not found');
		else
			alert('Motell : load error');
	};
	this.ajReq.open("GET",url,true,user,password);
	this.ajReq.send('');
	function createAjax(){
		if(!!window.XMLHttpRequest){
			try{ return new XMLHttpRequest(); }catch(e){ return null; }
		}else if(!!window.ActiveXObject){
			try{ return new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e){
				try{ return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ return null; }
			}
		}
		return null;
	}
};
_Motel.prototype.Pos=function(el,opt){
var pos={left:0,top:0,right:0,bottom:0,width:0,height:0};
var isMac=(navigator.platform.toLowerCase().indexOf("mac")!=-1);
if(!el)return pos;
//position:absolute or static only
// todo: for position:relative
	if(el.getBoundingClientRect){
		var doc,t=0,l=0;
		if(!!document.body){
			doc=document.body;
		}else if(!!document.documentElement){
			doc=document.documentElement;
		}else{
			doc={scrollTop:0,scrollLeft:0};
		}
		if(!!doc.scrollTop)t=parseInt(doc.scrollTop);
		if(!!doc.scrollLeft)l=parseInt(doc.scrollLeft);
		var rect=el.getBoundingClientRect();
		pos.top=rect.top+t;
		pos.left=rect.left+l;
		pos.right=rect.right+l;
		pos.bottom=rect.bottom+t;
		pos.width=rect.right-rect.left;
		pos.height=rect.bottom-rect.top;
	}else if(document.getBoxObjectFor){
		var rect=document.getBoxObjectFor(el);
		pos.top=rect.y;
		pos.left=rect.x;
		pos.width=rect.width;
		pos.height=rect.height;
		pos.right=rect.x+rect.width;
		pos.bottom=rect.y+rect.height;
	}else{
		pos.width=el.clientWidth;
		pos.height=el.clientHeight;
		while(el){
			pos.left+=parseInt(el.offsetLeft);
			pos.top+=parseInt(el.offsetTop);
			el=el.offsetParent;
		}
		if (!isMac){
		pos.left-=document.body.offsetLeft; // html margin-left
		pos.top-=document.body.offsetTop; // html margin-top
		}
		pos.right=pos.left+pos.width;
		pos.bottom=pos.top+pos.height;
	}
	if(!!opt){
		if(!!opt.width)pos.width=opt.width;
		if(!!opt.height)pos.height=opt.height;
		if(!!opt.top)pos.top=opt.top;
		if(!!opt.left)pos.left=opt.left;
		if(!!opt.right)pos.right=opt.right;
		if(!!opt.bottom)pos.bottom=opt.bottom;
	}
	return pos;
};

var Motel=new _Motel();
