   //
   // Avatars Walking version 0.1 
   // (c)2001 HistoryWalker and Miko-Aisa aisa@miko.to
   //
function Walker(){
 this.bx = -50;
 this.by = -50;
 this.xspeed = 10;
 this.yspeed = 5;
 this.dir = 0;
 this.show = 0;
 this.waittime = 0;
}
 var walkerNum = 3;     //number of walkers
 var walker = new Array( walkerNum );
 
 var imageKindNum = 4;
 
 var imgnames = new Array( imageKindNum );

 var dimg = new Array( imageKindNum*4 );

 var bMoveLight = 0;

function imgset(){
 imgnames[ 0 ] = "chiro";
 imgnames[ 1 ] = "chiko";
 imgnames[ 2 ] = "Okame";
 imgnames[ 3 ] = "OkameNami";
  for( i=0;i<imageKindNum;i++ ){
	for( j=0;j<4;j++ ){
	   dimg[i*4+j] = new Image( 50,50 );
	   dimg[i*4+j].src = "item/image/"+imgnames[ i ]+j*2+".gif";

//	   if( i==0 && j==0 ){
//		defaultStatus = "item/image/"+imgnames[ i ]+j*2+".gif";
//	   }
	}
  }
  for( i=0;i<walkerNum;i++ ){
   walker[ i ] = new Walker;
  }
	var ns=document.layers ? 1 : 0;
	var ex=document.all ? 1 : 0;
	var ns6= document.getElementById ? 1 : 0; 
  
  if( ex && !ns ){
//  if( Math.random() < 0.5 ){
//		bMoveLight = 1;
//		HWMainlogo.filters[ 0 ]="progid:DXImageTransform.Microsoft.Light()";
//	}else{
//		HWMainlogo.filters[0].AddAmbient( 255,255,255,100 );
//	}
  }
}
function walkWalker1( anum,objName,imgName ){
	var x = walker[anum].bx;
	var y = walker[anum].by;
	var xspeed = walker[anum].xspeed;
	var yspeed = walker[anum].yspeed;
	var waittime = walker[anum].waittime;
	var ns=document.layers ? 1 : 0;
	var ex=document.all ? 1 : 0;
	var ns6= document.getElementById ? 1 : 0; 
	if( ns || ex || ns6 ){
		var theLayer;
		 var widthMax = 1000;
		 var heightMax = 600;
		if( ns ){
			theLayer = document.layers[objName];
			widthMax = innerWidth-50;
			heightMax = innerHeight-50;
		}else if( ex ){
			widthMax = document.body.clientWidth-50;
			heightMax = document.body.clientHeight-50;
		}else if( ns6 ){
			widthMax = innerWidth-50;
			heightMax = innerHeight-50;
		}
//		defaultStatus = "heightMax="+heightMax;
		if( waittime==0 &&(x <= -50 || y <= -50 || x > widthMax || y > heightMax )){	//Out of screen

			var d = Math.floor( Math.random()*4 );
			walker[anum].dir = d;
			if( d==0 || d==2 ){		//up or down
				x = Math.floor( Math.random()*widthMax );
			}
			if( d==1 || d==3 ){
				y = Math.floor( Math.random()*heightMax );
			}
			xspeed = yspeed = 0;
			if( d==0 ){ y = heightMax; yspeed = -1; xspeed = 1; }
			else if( d==2 ){ y = 20; yspeed = 1;  xspeed = -1; }
			else if( d==1 ){ x = 20; xspeed = 1;  }
			else{ x = widthMax; xspeed=-1; }

			var m = 7+Math.floor( Math.random()*50 );
//			var m = 4;
			xspeed *= m;
			yspeed *= m;

			walker[anum].xspeed = xspeed;
			walker[anum].yspeed = yspeed;

			var img = Math.floor( Math.random()*imageKindNum )*4+d;
//			var img = Math.floor( 0 )*4+0;
			if( ns ){
				theLayer.document.images[imgName].src=dimg[img].src;
			}else{
				document.images[imgName].src=dimg[img].src;
			}
//			defaultStatus = "d="+d+",=img="+img+",x="+x+",y="+y+",xspeed="+xspeed+",yspeed="+yspeed;
			if( Math.floor( Math.random()*4 ) > 0 ){
				waittime = Math.floor( Math.random()*120 )+30;
//		defaultStatus = "waitime="+waitime;
			}
			walker[anum].waittime = waittime;
			if( waittime > 0 ){
				if( ns ){
					theLayer.top = -50;
					theLayer.left = -50;
				}else if( ns6 ){
					document.getElementById(objName).style.top = -50;
					document.getElementById(objName).style.left = -50;
				}else{
					document.all[objName].style.top = -50;
					document.all[objName].style.left = -50;
				}
			}
		}
		if( waittime > 0 ){
			walker[anum].waittime = waittime-1;
		}else{
			if( ns ){
				theLayer.top = y;
				theLayer.left = x;
			}else if( ns6 ){
				document.getElementById(objName).style.top = y;
				document.getElementById(objName).style.left = x;
			}else{
				document.all[objName].style.top = y;
				document.all[objName].style.left = x;
			}
			x += xspeed;
			y += yspeed;
			walker[anum].bx = x;
			walker[anum].by = y;
		}
	}
}
var count = 0;

var wave = 0;

var lightPhase = 0;
var lx = 0;
var ly = 0;
var lz = 200;
var xs = 12;
var ys = 4;
var zs = 0;
var colorRedFrom = 255;
var colorGreenFrom = 255;
var colorBlueFrom = 255;
var colorRedTo = 255;
var colorGreenTo = 255;
var colorBlueTo = 0;
var colorPhase = 0;
var colorPhaseMax = 150;
function lightLogo(){
	if( document.all ){ // only IE
		if( lightPhase == 0 ){
	  		HWMainlogo.filters[0].AddPoint( lx,ly,lz,255,255,255,255 );
//			lightPhase = 1;
		}
		if( colorPhase >= colorPhaseMax || lightPhase==0 ){
			colorRedFrom = colorRedTo;
			colorGreenFrom = colorGreenTo;
			colorBlueFrom = colorBlueTo;
			colorPhase = 0;
			var c = Math.floor( Math.random()*7 )+1;
			colorRedTo = ( c & 1 )?255:0;
			colorGreenTo = ( c & 2 )?255:0;
			colorBlueTo = ( c & 4 )?255:0;
			
			colorPhaseMax = Math.floor( Math.random()*130 )+5;
		}
		lightPhase = 1;
		lx += xs;
		ly += ys;
		lz += zs;
		
		if( lx > 631 ){
			lx = 631; xs = -xs;
//			bMoveLight = 0;
		}
		if( ly > 146 ){
			ly = 146; ys = -ys;
		}
		if( lx < 0 ){
			lx = 0; xs = -xs;
//			bMoveLight = 0;
		}
		if( ly < 0 ){
			ly = 0; ys = -ys;
		}
		var r = ( colorRedTo-colorRedFrom )*colorPhase/colorPhaseMax+colorRedFrom;
		var g = ( colorGreenTo-colorGreenFrom )*colorPhase/colorPhaseMax+colorGreenFrom;
		var b = ( colorBlueTo-colorBlueFrom )*colorPhase/colorPhaseMax+colorBlueFrom;
		colorPhase++;
		
  		HWMainlogo.filters[0].ChangeColor( 0,r,g,b,1 );
  		HWMainlogo.filters[0].MoveLight( 0,Math.floor(lx),Math.floor(ly),Math.floor(lz),1 );
//		defaultStatus = lx+","+ly+","+lz+","+xs+","+ys;
	}
}
function walking( bird,objName,imgName ){
	if( bMoveLight==0 ){
		for( i=0;i<walkerNum;i++ ){
			walkWalker1( i,"Walker"+(1+i),"Walker"+(1+i)+"Img"  );
		}
		setTimeout("walking()",30);
	}else{
//		if( count++ >= 6 ){
			lightLogo();
//			count = 0;
//		}
		setTimeout("walking()",280);
	}
}
