var nn=7;//蝶の数（あまり多くしないでね）
var speed=30;//蝶の飛行速度（ピクセル）
var htime=30;//蝶の出現頻度（秒）飛び立った蝶はこの時間内に再出現します。
var bai=1;//蝶の倍率
action=new Array();
xx1=new Array();
yy1=new Array();
th1=new Array();
rn1=new Array();
var rn
var nnp=ayanaoT.children.length
body1.style.overflow=""
for (i=0;i<nn;i++){
	document.write('<v:group id="butterfly'+i+'" style="width:1; height:1; left:-1000; top:-1000; position:absolute; rotation:'+i*60+'; visibility:hidden;" onmouseover="action['+i+']=3" coordsize="1,1" coordorigin="0,0">')
	document.write('<v:image id="batac'+i+'" src="" style="left:0; top:0; width:0; height:0;"/>')
	document.write('<v:group id="butterflyH'+i+'" style="width:100; height:100; left:0; top:0; position:absolute; rotation:0;" coordsize="100,100" coordorigin="0,0">')
	document.write('<v:image id=batal'+i+' src="" style="left:0; top:0; width:0; height:0;"/>')
	document.write('<v:image id=batar'+i+' src="" style="left:0; top:0; width:0; height:0; flip:x;"/>')
	document.write('</v:group>')
	document.write('</v:group>')
	eval('batac'+i+'.src=ayanaoT.children('+((i*2)%nnp+1)+').src')
	eval('batal'+i+'.src=ayanaoT.children('+(i*2)%nnp+').src')
	eval('batar'+i+'.src=ayanaoT.children('+(i*2)%nnp+').src')
	action[i]=0
	xx1[i]=-1000
	yy1[i]=-1000
	setTimeout('butterflyaction('+i+')',htime*1000*Math.random())
}

function setmado(){
rr=Math.pow(document.body.clientWidth*document.body.clientWidth+document.body.clientHeight*document.body.clientHeight,0.5)
rn=Math.ceil(rr/speed)
}

function batafly(no,dt){
www=Math.ceil(Math.sin(dt*Math.PI/180)*100)
eval('butterflyH'+no+'.style.width='+www)
}

function butterflyaction(no,dt,dtt,ttime){
	switch(action[no]){
		case 0:
				xx1[no]=Math.floor(box0.style.pixelLeft+box0.offsetWidth*Math.random());
				yy1[no]=Math.floor(box0.style.pixelTop+box0.offsetHeight*Math.random());
				dkl=10000000
				for (i=0;i<nn;i++){
					if(no!=i){
						xo=eval('butterfly'+i+'.style.pixelLeft')
						yo=eval('butterfly'+i+'.style.pixelTop')
						dkl=Math.min(dkl,Math.pow(xx1[no]-xo,2)+Math.pow(yy1[no]-yo,2))
					}
				}
//				status=dkl+","+bw*bw
				bw=Math.max(eval('ayanaoT.children((no*2)%nnp).offsetWidth')*2,eval('ayanaoT.children((no*2)%nnp).offsetHeight'))
				if(dkl>=bw*bw){
					action[no]=1
					rn1[no]=rn
					dt=0
					dtt=45
					th1[no]=Math.floor(Math.random()*360)
					eval('butterfly'+no+'.coordorigin="0,'+ayanaoT.children(1).offsetHeight*bai/2+'"')
					eval('butterfly'+no+'.style.rotation='+th1[no])
					eval('butterfly'+no+'.style.visibility="visible"')
					eval('butterfly'+no+'.style.zIndex=5')
					eval('batac'+no+'.style.width=ayanaoT.children((no*2)%nnp+1).offsetWidth*bai')
					eval('batac'+no+'.style.height=ayanaoT.children((no*2)%nnp+1).offsetHeight*bai')
					eval('batac'+no+'.style.left=-ayanaoT.children((no*2)%nnp+1).offsetWidth/2*bai')
					eval('batal'+no+'.style.width=ayanaoT.children((no*2)%nnp).offsetWidth*bai')
					eval('batal'+no+'.style.height=ayanaoT.children((no*2)%nnp).offsetHeight*bai')
					eval('batal'+no+'.style.left=-ayanaoT.children((no*2)%nnp).offsetWidth*bai')
					eval('batar'+no+'.style.width=ayanaoT.children((no*2)%nnp).offsetWidth*bai')
					eval('batar'+no+'.style.height=ayanaoT.children((no*2)%nnp).offsetHeight*bai')
					ttime=45;
				}else{
					action[no]=0
					ttime=1000;
				}
		break;
		case 1:
			th=th1[no]*Math.PI/180
			rn1[no]=rn1[no]-1;
			eval('butterfly'+no+'.style.left='+(xx1[no]-speed*rn1[no]*Math.sin(th)))
			eval('butterfly'+no+'.style.top='+Math.floor(yy1[no]+speed*rn1[no]*Math.cos(th)))
			dt=dt+dtt
			if(dt<=0){
 				dt=5
				dtt=-dtt
			}else if(dt>90){
 				dt=90
				dtt=-dtt
			}
			batafly(no,dt)
			ttime=100;
			if(rn1[no]==0){
				action[no]=2
				eval('butterfly'+no+'.style.zIndex=1')
				dtt=2+3*Math.random()
				ttime=100;
			}
		break;
		case 2:
			dt=dt+dtt
			if(dt<=0){
 				dt=5
				dtt=-dtt
			}else if(dt>90){
 				dt=90
				dtt=-dtt
			}
			batafly(no,dt)
			if(Math.random()<0.002){
				action[no]=3
			}
		break;
		case 3:
			if(ttime!=50){
				dtt=45;ttime=50;dt=0;
				eval('butterfly'+no+'.style.zIndex=5')
			}
			th=th1[no]*Math.PI/180
			rn1[no]=rn1[no]-1;
			eval('butterfly'+no+'.style.left='+(xx1[no]-speed*rn1[no]*Math.sin(th)))
			eval('butterfly'+no+'.style.top='+Math.floor(yy1[no]+speed*rn1[no]*Math.cos(th)))
			dt=dt+dtt
			if(dt<=0){
 				dt=5
				dtt=-dtt
			}else if(dt>90){
 				dt=90
				dtt=-dtt
			}
			batafly(no,dt)
			if(eval('butterfly'+no+'.style.pixelLeft')<-500 || eval('butterfly'+no+'.style.pixelLeft')>document.body.clientWidth || eval('butterfly'+no+'.style.pixelTopt')<-500 || eval('butterfly'+no+'.style.pixelTop')>document.body.clientHeight){
				action[no]=0
				eval('butterfly'+no+'.style.left=-1000')
				eval('butterfly'+no+'.style.top=-1000')
				eval('butterfly'+no+'.style.visibility="hidden"')
				ttime=htime*1000*Math.random();
			}
		break;
	}

setTimeout('butterflyaction('+no+','+dt+','+dtt+','+ttime+')',ttime)
}


setmado();
window.onresize =setmado;