var dy =4;
var stLineY = new Array(-73,-41,-25,-41, -25);  //各ステージの初期のy値。
var y = new Array(-73, -41, -25, -41, -25);      //各ステージの現在のy値。
var show = new Array(false, false, false, false, false);
var timer = new Array(null, null, null, null, null, null);
var Num;

function start(Link){
	clearTimeout(timer[5]);
	Num = Link;
	show[Num] = true;
	clearInterval(timer[Link]);
	timer[Link] = setInterval("slide()", 10);
}

function slide(){
	if(y[Num] < 19){
		y[Num] += dy;
		document.getElementById("link" + Num).style.top = y[Num] + "px";
	}else if(y[Num] == 19){
		clearInterval(timer[Num]);
		timer[Num] = !timer[Num];
	}
} 

function back(BNum){
	for(var i=0; i<5; i++){
		if(BNum != i){
		
			if(show[i]){
				switch(i){
					case 0:
						clearInterval(timer[0]);
						timer[0] = setInterval("slideBack(0)", 10);
						break;
					case 1:
						clearInterval(timer[1]);
						timer[1] = setInterval("slideBack(1)", 10);
						break;
					case 2:
						clearInterval(timer[2]);
						timer[2] = setInterval("slideBack(2)", 10);
						break;
					case 3:
						clearInterval(timer[3]);
						timer[3] = setInterval("slideBack(3)", 10);
						break;
					case 4:
						clearInterval(timer[4]);
						timer[4] = setInterval("slideBack(4)", 10);
						break;
				}
			}
		}
	}
}

function slideBack(BackNum){
	if(y[BackNum] > stLineY[BackNum]){
		y[BackNum] -= dy;
		document.getElementById("link" + BackNum).style.top = y[BackNum] + "px";
	}else if(y[BackNum] == stLineY[BackNum]){
		clearInterval(timer[BackNum]);
		timer[BackNum] = !timer[BackNum];
		show[BackNum] = false;
	}
}

function autoBack(){
	timer[5] = setTimeout("back(5)", 300);
}