// img要素
var img;

// アニメーションの配列、アニメーションの位置
var anim;
var animIndex;

// キャラクターの座標と速度
var x,y,ix,ex;
var vx,vy;
var yradi,vyradi,ys,yw;
// メインルーチン（プログラムの主要な処理）
function main() {
	//return;
	// キャラクターの画像を表示する
	img=document.createElement("img");
	document.body.appendChild(img);
	//img.src="images/18-18-45leftrotate.gif";
	
	// アニメーションの配列を初期化する
	anim=new Array(
		"images/18-18-45rotate.gif","images/18-18-45leftrotate.gif"
	);
	
	// アニメーションの位置を初期化する
	animIndex=0;

	// 画像の表示位置を絶対値で指定する
	img.style.position="absolute";

	// 座標と速度の初期化
	sx=(screen.width/2+800/2-50);
	ex=(screen.width/2-800/2-0);
//	sy=(screen.width/2+800/2-100);
//	ey=(screen.width/2-800/2);
//	document.write(sx);
//	document.write(" ");
//	document.write(ex);
	x=sx;
	ys=114;
	y=120;
	yradi=0;
	// １回の移動量
	vx=-8;
	vy=-15;
	vyradi=0.15;
	yw=0.5
	// 一定時間ごとに実行する処理を登録する
	setInterval(update, 200);
}

//一定時間ごとに実行する処理
function update() {
	
	// アニメーションを再生する
	img.src=anim[animIndex];
	if( vx<0 ) 	animIndex=1;
	else animIndex=0;
	// 座標を変更する
	x+=vx;
	yradi+=vyradi;
	y=Math.sin(yradi)*ys;
	// 画面上の一定の範囲から外れたら、速度の符号を反転させる
	if(x<=ex || x>=sx) 	vx=-vx;
	if(yw<=0) yw=0.5;
//	if(y<=50 || y>=114) vy=-vy;
	if(yradi>=3) {
		yradi=0;
		//yw-=0.1;
	}
	// 画像の座標を変更する
	img.style.left = x+"px";
	img.style.top = 55+(120-y)*yw+"px";
}
	

 