function movie(vie) {
	if($("btn1").onclick || $("btn2").onclick || $("btn3").onclick || $("btn4").onclick){
		moves(vie);
	}
}

function moves(mov) {

	if(ssmi < 4){
		if(mae1 == 1){
			if(mae2 == 2){
				gs3t = gs3t + 4;
				gs3l = gs3l + 4;
			}else if(mae2 == 3){
				gs3t = gs3t + 8;
			}else if(mae2 == 4){
				gs3t = gs3t + 4;
				gs3l = gs3l - 4;
			}else if(mae2 == 0){
				gs3t = gs3t + 4;
			}
		}else if(mae1 == 2){
			if(mae2 == 1){
				gs3t = gs3t - 4;
				gs3l = gs3l - 4;
			}else if(mae2 == 3){
				gs3t = gs3t + 4;
				gs3l = gs3l - 4;
			}else if(mae2 == 4){
				gs3l = gs3l - 8;
			}else if(mae2 == 0){
				gs3l = gs3l - 4;
			}
		}else if(mae1 == 3){
			if(mae2 == 1){
				gs3t = gs3t - 8;
			}else if(mae2 == 2){
				gs3t = gs3t - 4;
				gs3l = gs3l + 4;
			}else if(mae2 == 4){
				gs3t = gs3t - 4;
				gs3l = gs3l - 4;
			}else if(mae2 == 0){
				gs3t = gs3t - 4;
			}
		}else if(mae1 == 4){
			if(mae2 == 1){
				gs3t = gs3t - 4;
				gs3l = gs3l + 4;
			}else if(mae2 == 2){
				gs3l = gs3l + 8;
			}else if(mae2 == 3){
				gs3t = gs3t + 4;
				gs3l = gs3l + 4;
			}else if(mae2 == 0){
				gs3l = gs3l + 4;
			}
		}
		
		if(mov == 1){
			poyj = poyj + 4;
			$("titles").style.top = poyj + "px";
			if(mae1 == 2){
				gs2t = gs2t + 4; gs2l = gs2l + 4;
				gs3t = gs3t + 4; gs3l = gs3l + 4;
			}else if(mae1 == 3){
				gs2t = gs2t + 8;
				gs3t = gs3t + 8;
			}else if(mae1 == 4){
				gs2t = gs2t + 4; gs2l = gs2l - 4;
				gs3t = gs3t + 4; gs3l = gs3l - 4;
			}else if(mae1 == 0){
				gs2t = gs2t + 4;
				gs3t = gs3t + 4;
			}
			$("shujin2").style.top = gs2t + "px";
			$("shujin2").style.left = gs2l + "px";
			$("shujin3").style.top = gs3t + "px";
			$("shujin3").style.left = gs3l + "px";
			ssmi = ssmi + 1;
			setTimeout("moves(1)",60);
		}else if(mov == 2){
			poxj = poxj - 4;
			$("titles").style.left = poxj + "px";
			if(mae1 == 1){
				gs2t = gs2t - 4; gs2l = gs2l - 4;
				gs3t = gs3t - 4; gs3l = gs3l - 4;
			}else if(mae1 == 3){
				gs2t = gs2t + 4; gs2l = gs2l - 4;
				gs3t = gs3t + 4; gs3l = gs3l - 4;
			}else if(mae1 == 4){
				gs2l = gs2l - 8;
				gs3l = gs3l - 8;
			}else if(mae1 == 0){
				gs2l = gs2l - 4;
				gs3l = gs3l - 4;
			}
			$("shujin2").style.top = gs2t + "px";
			$("shujin2").style.left = gs2l + "px";
			$("shujin3").style.top = gs3t + "px";
			$("shujin3").style.left = gs3l + "px";
			ssmi = ssmi + 1;
			setTimeout("moves(2)",60);
		}else if(mov == 3){
			poyj = poyj - 4;
			$("titles").style.top = poyj + "px";
			if(mae1 == 1){
				gs2t = gs2t - 8;
				gs3t = gs3t - 8;
			}else if(mae1 == 2){
				gs2t = gs2t - 4; gs2l = gs2l + 4;
				gs3t = gs3t - 4; gs3l = gs3l + 4;
			}else if(mae1 == 4){
				gs2t = gs2t - 4; gs2l = gs2l - 4;
				gs3t = gs3t - 4; gs3l = gs3l - 4;
			}else if(mae1 == 0){
				gs2t = gs2t - 4;
				gs3t = gs3t - 4;
			}
			$("shujin2").style.top = gs2t + "px";
			$("shujin2").style.left = gs2l + "px";
			$("shujin3").style.top = gs3t + "px";
			$("shujin3").style.left = gs3l + "px";
			ssmi = ssmi + 1;
			setTimeout("moves(3)",60);
		}else if(mov == 4){
			poxj = poxj + 4;
			$("titles").style.left = poxj + "px";
			if(mae1 == 1){
				gs2t = gs2t - 4; gs2l = gs2l + 4;
				gs3t = gs3t - 4; gs3l = gs3l + 4;
			}else if(mae1 == 2){
				gs2l = gs2l + 8;
				gs3l = gs3l + 8;
			}else if(mae1 == 3){
				gs2t = gs2t + 4; gs2l = gs2l + 4;
				gs3t = gs3t + 4; gs3l = gs3l + 4;
			}else if(mae1 == 0){
				gs2l = gs2l + 4;
				gs3l = gs3l + 4;
			}
			$("shujin2").style.top = gs2t + "px";
			$("shujin2").style.left = gs2l + "px";
			$("shujin3").style.top = gs3t + "px";
			$("shujin3").style.left = gs3l + "px";
			ssmi = ssmi + 1;
			setTimeout("moves(4)",60);
		}
		
		if(ssmi == 1){
			
			$("btnspace").innerHTML = "<div style='color:#000;font-weight:bold;padding:35px 0 0 15px;'>Please wait....</div>";
			if(mov == 1){
				$("shujin1").style.backgroundPosition='-16px 0px';
			}else if(mov == 2){
				$("shujin1").style.backgroundPosition='-48px 0px';
			}else if(mov == 3){
				$("shujin1").style.backgroundPosition='0px 0px';
			}else if(mov == 4){
				$("shujin1").style.backgroundPosition='-32px 0px';
			}
			if(mae1 == 1){
				$("shujin2").style.backgroundPosition='-16px 0px';
			}else if(mae1 == 2){
				$("shujin2").style.backgroundPosition='-48px 0px';
			}else if(mae1 == 3){
				$("shujin2").style.backgroundPosition='0px 0px';
			}else if(mae1 == 4){
				$("shujin2").style.backgroundPosition='-32px 0px';
			}
			if(mae2 == 1){
				$("shujin3").style.backgroundPosition='-16px 0px';
			}else if(mae2 == 2){
				$("shujin3").style.backgroundPosition='-48px 0px';
			}else if(mae2 == 3){
				$("shujin3").style.backgroundPosition='0px 0px';
			}else if(mae2 == 4){
				$("shujin3").style.backgroundPosition='-32px 0px';
			}
		}

	}else{
		mae2 = mae1;
		if(mov == 1){
			mae1 = 1;
		}else if(mov == 2){
			mae1 = 2;
		}else if(mov == 3){
			mae1 = 3;
		}else if(mov == 4){
			mae1 = 4;
		}
		//alert(mae1);
		//alert(mae2);
		ssmi = 0;
		$("btnspace").innerHTML = "<form><table border='0' cellpadding='0' cellspacing='0' width='111' height='60'><tr><td valign='top'><p style='margin:0px'></p></td><td><img src='rpgmap/img/mvtop.gif' onClick='movie(1);' id='btn1' /></td><td valign='top'><p style='margin:0px'></p></td></tr><tr><td><img src='rpgmap/img/mvleft.gif' onClick='movie(4);' id='btn4' /></td><td><img src='rpgmap/img/action.gif' /></td><td><img src='rpgmap/img/mvright.gif' onClick='movie(2);' id='btn2' /></td></tr><tr><td valign='top'><p style='margin:0px'></p></td><td><img src='rpgmap/img/mvbottom.gif' onClick='movie(3);' id='btn3' /></td><td valign='top'><p style='margin:0px'></p></td></tr></table></form>";
		return;
	}
}

window.onload = function() {

	$("mainbox").innerHTML = "<div id='titles' style='left:-3296px;top:-1024px;'></div>"
		+"<div id='shujin1' style='width:16px;height:16px;left:128px;top:112px;position:absolute;z-index:100;background-image:url(icon/chara1.gif);background-position:0px 0px;'></div>"
		+"<div id='shujin2' style='width:16px;height:16px;left:128px;top:112px;position:absolute;z-index:99;background-image:url(icon/chara2.gif);background-position:0px 0px;'></div>"
		+"<div id='shujin3' style='width:16px;height:16px;left:128px;top:112px;position:absolute;z-index:98;background-image:url(icon/chara3.gif);background-position:0px 0px;'></div>";
	$("btnspace").innerHTML = "<form><table border='0' cellpadding='0' cellspacing='0' width='111' height='60'><tr><td valign='top'><p style='margin:0px'></p></td><td><img src='rpgmap/img/mvtop.gif' onClick='movie(1);' id='btn1' /></td><td valign='top'><p style='margin:0px'></p></td></tr><tr><td><img src='rpgmap/img/mvleft.gif' onClick='movie(4);' id='btn4' /></td><td><img src='rpgmap/img/action.gif' /></td><td><img src='rpgmap/img/mvright.gif' onClick='movie(2);' id='btn2' /></td></tr><tr><td valign='top'><p style='margin:0px'></p></td><td><img src='rpgmap/img/mvbottom.gif' onClick='movie(3);' id='btn3' /></td><td valign='top'><p style='margin:0px'></p></td></tr></table></form>";

}

i=1;
var poxj = -3296;
var poyj = -1024;
var gs2t = 112;
var gs2l = 128;
var gs3t = 112;
var gs3l = 128;
var mae1 = 0;
var mae2 = 0;
var ssmi = 0;