var IKA_N = 5;/*イカの最大数*/
var AWA_N = 5; /*泡の最大数*/
var TOMOMI = 2; /*tomomiの表示数*/
var Maxwidth;/*現在のwindowの幅*/
var Maxheight;/*現在のwindowの高さ*/
var OMGi = 0.5;/*ikaの周期角を規定*/
var OMGa = 0.5;/*awaの周期角を規定*/
var mrg = 50;/*周囲からのマージン*/
var leftmrg = 50; /*左からのマージン*/
var deltaT = 0.1;/*時間変化率*/
var FONTi = 20;/*イカのベースフォントサイズ*/
var FONTa = 32;/*泡のベースフォントサイズ*/

var ika = new Array(IKA_N);/*イカ*/
var awa = new Array(AWA_N);/*泡*/
var to = new Array(TOMOMI);/*TOMOMI*/


/*TOMOMIの設定*/
function To(i,x,y,theta){
	this.Index=i;
	this.X=x;
	this.Y=y;
	this.Theta=theta;
	this.dX = 2*Math.random()+1;
	this.T=Math.PI*Math.random();
	this.Img='<img src="ika.gif">三';
	this.Size = 25;
	this.R=255;
	this.G=255;
	this.B=255;
	this.Line='<div id=to'+this.Index+' style="position:absolute;left:'+this.X+';top:'
			+this.Y+';font-size:'+this.Size+'px;color:rgb('+this.R+','+this.G+','+this.B+');visibility:hidden">'
			+this.Img+'</div>';
}

/*この関数をhtmlに組み込む*/
/*
WINDOWWIDTH　引数として読み込みブラウザの幅
WINDOWHEIGHT　引数として読み込みブラウザの高さ
*/
function Main(WINDOWWIDTH,WINDOWHEIGHT){

	Maxwidth=WINDOWWIDTH-mrg;
	Maxheight=WINDOWHEIGHT-mrg;
	initialize();
	
	for(i=0;i<IKA_N;i++){
//		document.write(ika[i].Line);
	}
	for(i=0;i<AWA_N;i++){
		document.write(awa[i].Line);
	}
	for(i=0;i<TOMOMI;i++){
		document.write(to[i].Line);
	}
//	Ikamove();
	Awamove();
	Tomomimove();
//	Toout_timeout = setTimeout("Tomomiout()",5000);
}

/*各初期位置設定*/
function initialize()
{
	/*イカの設定*/
	for(i=0;i<IKA_N;i++){
		ika[i] = new Ika(i,Math.floor(Maxwidth*Math.random()),Math.floor(Maxheight*Math.random()),OMGi*Math.random());
	}
	/*泡の設定*/
	for(i=0;i<AWA_N;i++){
		awa[i] = new Awa(i,Math.floor((Maxwidth-leftmrg)*Math.random()),Maxheight-25*Math.random(),OMGa*Math.random());
	}
	for(i=0;i<TOMOMI;i++){
		to[i] = new To(i,Math.floor(Maxwidth*Math.random()),Math.floor(Maxheight*Math.random()),OMGi*Math.random());
	}
}

/*TOMOMIの移動*/
function Tomomimove(){
	var tmp;
	for(i=0;i<TOMOMI;i++){
		tmp = to[i].X;
		if(tmp > leftmrg){
			to[i].T += deltaT; /*呼び出されるたびに時刻を増加*/
			to[i].X -= Math.abs(to[i].dX*Math.sin(to[i].Theta*to[i].T));/*各イカの変化量を計算*/
			document.all["to"+to[i].Index].style.pixelLeft = to[i].X;/*変更を反映*/
		}
		else{
			to[i].T = 0;
			to[i].X = Math.floor(Maxwidth*Math.random());
			to[i].Y = Math.floor(Maxheight*Math.random());
			to[i].Theta = OMGi*Math.random();
			document.all["to"+to[i].Index].style.pixelTop = to[i].Y;
		}
	}
	to_timeout=setTimeout("Tomomimove()",5);/*再起呼び出しにり連続的に移動を実行*/
}

/*TOMOMIを表示開始*/
function Tomomiout(){
	var i;
	for(i=0;i<TOMOMI;i++){
		document.all["to"+to[i].Index].style.visibility = 'visible';
	}
}

/*イカの設定*/
function Ika(i,x,y,theta){
	this.Index=i;
	this.X=x;
	this.Y=y;
	this.Theta=theta;
	this.dX = 2*Math.random()+1;
	this.T=Math.PI*Math.random();
	this.Img='<a href="http://www.geocities.co.jp/CollegeLife-Club/2334/index.html" style="text-decoration:none;font-style:normal;"><コ:三</a>';
	this.Size = Math.floor(FONTi*Math.random())+5;
	this.R=255;
	this.G=255;
	this.B=255;
	this.Line='<div id=ika'+this.Index+' style="position:absolute;left:'+this.X+';top:'
			+this.Y+';font-size:'+this.Size+'px;color:rgb('+this.R+','+this.G+','+this.B+');">'
			+this.Img+'</div>';
}

/*泡の設定*/
function Awa(i,x,y,theta){
	this.Index=i;
	this.X=x;
	this.Y=y;
	this.Theta=theta;
	this.dX = Math.floor(Math.random())+1;
	this.dY = Math.floor(2*Math.random())+1;
	this.T=Math.PI*Math.random();
	this.Img='○';
	this.Size = Math.floor(FONTa*Math.random());
	this.R=255;
	this.G=255;
	this.B=255;
	this.Line='<div id=awa'+this.Index+' style="position:absolute;left:'+this.X+';top:'
			+this.Y+';font-size:'+this.Size+';color:rgb('+this.R+','+this.G+','+this.B+');">'
			+this.Img+'</div>';
}

/*イカを動かす*/
function Ikamove(){
	var tmp;
	for(i=0;i<IKA_N;i++){
		tmp = ika[i].X;
		if(tmp > leftmrg){
			ika[i].T += deltaT; /*呼び出されるたびに時刻を増加*/
			ika[i].X -= Math.abs(ika[i].dX*Math.sin(ika[i].Theta*ika[i].T));/*各イカの変化量を計算*/
			document.all["ika"+ika[i].Index].style.pixelLeft = ika[i].X;/*変更を反映*/
		}
		else{
			ika[i].T = 0;
			ika[i].X = Math.floor(Maxwidth*Math.random());
			ika[i].Y = Math.floor(Maxheight*Math.random());
			ika[i].Theta = OMGi*Math.random();
			document.all["ika"+ika[i].Index].style.fontSize = Math.floor(FONTi*Math.random())+5;
			document.all["ika"+ika[i].Index].style.pixelTop = ika[i].Y;
		}
	}
	ika_timeout=setTimeout("Ikamove()",5);/*再起呼び出しにり連続的に移動を実行*/
}

/*泡を動かす*/
function Awamove(){
	var tmp;
	for(i=0;i<AWA_N;i++){
		tmp = awa[i].Y;
		if(tmp>leftmrg){
			awa[i].T += deltaT; /*呼び出されるたびに時刻を増加*/
			awa[i].X += awa[i].dX*Math.sin(awa[i].Theta*awa[i].T);/*各泡の横の変化を計算*/
			awa[i].Y -= awa[i].dY; /*各泡の縦の変化を計算*/
			document.all["awa"+awa[i].Index].style.pixelLeft = awa[i].X;/*変更を反映*/
			document.all["awa"+awa[i].Index].style.pixelTop = awa[i].Y;/*変更を反映*/
		}
		else{
			awa[i].T = 0;
			awa[i].X = Math.floor(Math.abs((Maxwidth-leftmrg)*Math.random()-1.5*leftmrg));
			awa[i].Y =Maxheight-25*Math.random();
			awa[i].Theta = OMGa*Math.random();
		}
	}
	awa_timeout=setTimeout("Awamove()",1);/*再起呼び出しにり連続的に移動を実行*/
}
