//-------------------------------------------------------------------
//HTML-MARIO by takenaka  http://falsetown.hp.infoseek.co.jp/kapela/
//-------------------------------------------------------------------
var Keybuf = 0;
var charaposx = 50;
var rightflag = 0 ; var leftflag = 0 ; var idolingflag = 1;
var backpos = 0;
var unnone = -20;

if (navigator.appName=="Netscape")
{
	document.write("<link rel='stylesheet' href='htmlmario_nn.css' type='text/css'>");
}

document.onkeydown = function(e) {
	//キーが押された場合の処理
	//var shift, ctrl;
	// Mozilla(Firefox, NN) and Opera
	if (e != null) {
		keycode = e.which;
		//ctrl = typeof e.modifiers == 'undefined' ? e.ctrlKey : e.modifiers & Event.CONTROL_MASK;
		//shift = typeof e.modifiers == 'undefined' ? e.shiftKey : e.modifiers & Event.SHIFT_MASK;
		// イベントの上位伝播を防止
		e.preventDefault();
		e.stopPropagation();
	}
	//Internet Explorer
	else {
		keycode = event.keyCode;
		//ctrl = event.ctrlKey;
		//shift = event.shiftKey;
		// イベントの上位伝播を防止
		event.returnValue = false;
		event.cancelBubble = true;
	}
	// キーコードの文字を取得 
	Keybuf = keycode;
	MoveChara();
	ChangeIMG();
}

document.onkeypress = function(e) {
	//キーが押され続けた場合の処理
	if (navigator.appName=="Opera")
	{
		MoveChara();
		ChangeIMG();
	}
}

document.onkeyup = function(e) {
	//キーが離された場合の処理
	SetMotion();
	ChangeIMG();
}

function MoveChara()
{
	nWidth = document.body.clientWidth;

	if (Keybuf == 39)
	{
		charaposx = charaposx + 5;
		rightflag = 1 ; leftflag = 0 ; idolingflag = 0;
		backpos = 0;
	}
	if (Keybuf == 37)
	{
		charaposx = charaposx - 5;
		leftflag = 1 ; rightflag = 0 ; idolingflag = 0;
		backpos = 1;
	}
	if (charaposx > nWidth)
	{
		charaposx = nWidth;
	}
	if (charaposx < 9.5)
	{
		charaposx = 9.5;
	}
}

function ChangeIMG()
{
	if (navigator.appName=="Netscape")
	{
		if(document.layers)
		{
			ChangeIMGNN4();
		}
		else
		{
			ChangeIMGNN6();
		}
	}
	else
	{
		ChangeIMGIE();
	}
}

function ChangeIMGIE()
{
	if (rightflag == 1)
	{
		mario_left0.style.left = unnone + "px";
		mario_left.style.left = unnone + "px";
		mario_right0.style.left = unnone + "px";
		mario_right.style.left = charaposx + "px";
	}
	if (leftflag == 1)
	{
		mario_right0.style.left = unnone + "px";
		mario_right.style.left = unnone + "px";
		mario_left0.style.left = unnone + "px";
		mario_left.style.left = charaposx + "px";
	}
	if (idolingflag == 1)
	{
		if (backpos == 0)
		{
			mario_right0.style.left = charaposx + "px";
			mario_right.style.left = unnone + "px";
			mario_left0.style.left = unnone + "px";
			mario_left.style.left = unnone + "px";
		}
		if (backpos == 1)
		{
			mario_right0.style.left = unnone + "px";
			mario_right.style.left = unnone + "px";
			mario_left0.style.left = charaposx + "px";
			mario_left.style.left = unnone + "px";
		}
	}
}

function ChangeIMGNN4()
{
	if (rightflag == 1)
	{
		document.mario_left0.style.left = unnone + "px";
		document.mario_left.style.left = unnone + "px";
		document.mario_right0.style.left = unnone + "px";
		document.mario_right.style.left = charaposx + "px";
	}
	if (leftflag == 1)
	{
		document.mario_right0.style.left = unnone + "px";
		document.mario_right.style.left = unnone + "px";
		document.mario_left0.style.left = unnone + "px";
		document.mario_left.style.left = charaposx + "px";
	}
	if (idolingflag == 1)
	{
		if (backpos == 0)
		{
			document.mario_right0.style.left = charaposx + "px";
			document.mario_right.style.left = unnone + "px";
			document.mario_left0.style.left = unnone + "px";
			document.mario_left.style.left = unnone + "px";
		}
		if (backpos == 1)
		{
			document.mario_right0.style.left = unnone + "px";
			document.mario_right.style.left = unnone + "px";
			document.mario_left0.style.left = charaposx + "px";
			document.mario_left.style.left = unnone + "px";
		}
	}
}

function ChangeIMGNN6()
{
	if (rightflag == 1)
	{
		document.getElementById("mario_left0").style.left = unnone + "px";
		document.getElementById("mario_left").style.left = unnone + "px";
		document.getElementById("mario_right0").style.left = unnone + "px";
		document.getElementById("mario_right").style.left = charaposx + "px";
	}
	if (leftflag == 1)
	{
		document.getElementById("mario_right0").style.left = unnone + "px";
		document.getElementById("mario_right").style.left = unnone + "px";
		document.getElementById("mario_left0").style.left = unnone + "px";
		document.getElementById("mario_left").style.left = charaposx + "px";
	}
	if (idolingflag == 1)
	{
		if (backpos == 0)
		{
			document.getElementById("mario_right0").style.left = charaposx + "px";
			document.getElementById("mario_right").style.left = unnone + "px";
			document.getElementById("mario_left0").style.left = unnone + "px";
			document.getElementById("mario_left").style.left = unnone + "px";
		}
		if (backpos == 1)
		{
			document.getElementById("mario_right0").style.left = unnone + "px";
			document.getElementById("mario_right").style.left = unnone + "px";
			document.getElementById("mario_left0").style.left = charaposx + "px";
			document.getElementById("mario_left").style.left = unnone + "px";
		}
	}
}

function SetMotion()
{
	eventno = 0 ; rightflag = 0 ; leftflag = 0 ; idolingflag = 1;
}