﻿var mouseoverFlag = -1;//どのメニューにマウスが載っているか。-1は載っていない
var cancelFD = new Array();//フェードアウト中のIDを添え字とする連想配列で、trueのときフェードアウトをキャンセルする

//マウスが乗ったとき
function mouseover(id, y) {
	mouseoverFlag = id;
	cancelFD[("ex"+id)] = cancelFD[("arrow"+id)] = true;

	//メニューの位置をずらす
	obj = document.getElementById("menu"+id);
	obj.style.left = -8 + 40 * ((id+1) % 2) + "px";
	obj.style.top = "4px";

	document.getElementById("news").style.display = "none";

	//説明を表示
	document.getElementById("ex"+id).style.top = 95 + 65 * id + "px";
	document.getElementById("ex"+id).style.left = document.getElementById("main").offsetLeft + 30 + 40 * ((id+1) % 2) + "px";
	document.getElementById("ex"+id).style.display = "block";
	document.getElementById("ex"+id).style.opacity = 0.8;

	//矢印を表示
	if(!document.getElementById("arrow"+id)) document.getElementById("arrows").innerHTML += '<img src="img/arrow.png" alt="" width="100" height="48" id="arrow'+id+'" style="position:absolute">';
	else document.getElementById("arrow"+id).style.display = "block";
	document.getElementById("arrow"+id).style.opacity = 1;
	arrowZoomAnimation(id, 1);
}

//マウスが離れたとき
function mouseout(id){
	mouseoverFlag = -1;
	move();

	cancelFD[("ex"+id)] = cancelFD[("arrow"+id)] = false;
	fadeout("ex"+id, 1);
	fadeout("arrow"+id, 1);
}

//指定されたオブジェクトの背景色を変える
function changeBgColor(obj, color){
	obj.style.backgroundColor = color;
}

//アニメ処理
function move(){
	var flag = false;//アニメを繰り返す必要があるか
	for(var i=0; i<5; i++){
		var left = document.getElementById('menu'+i).style.left;
		var top = document.getElementById('menu'+i).style.top;
		if(mouseoverFlag != i && (-20 + 40 * ((i+1) % 2)) < left.substr(0, left.length-2)){
			flag = true;
			document.getElementById('menu'+i).style.left = left.substr(0, left.length-2) - 3 + "px";
			document.getElementById('menu'+i).style.top = top.substr(0, top.length-2) - 1 + "px";
		}
		else if(mouseoverFlag != -1) flag = true;
	}
	if(flag) setTimeout("move()", 40);//まだ終了していないアニメ処理があれば続行
	else if(mouseoverFlag == -1) document.getElementById("news").style.display = "block";
}

function arrowZoomAnimation(id, c){//c = カウント1..5
	var size = -0.25*(c-5)*(c-5)+5;
	document.getElementById("arrow"+id).width = 20 * size;
	document.getElementById("arrow"+id).height = 9.6 * size;
	document.getElementById("arrow"+id).style.left = document.getElementById("main").offsetLeft + 450 + 40 * ((id+1) % 2) - 20 * size + "px";
	//↑画面中mainの左端までの距離＋位置調節＋奇数偶数による位置調節－サイズによる位置調節（右あわせ）
	document.getElementById("arrow"+id).style.top = 130 + 65 * id - 4.8 * size + "px";
	//↑位置調節＋IDごとに上からの位置調節－サイズによる位置調節（中央あわせ）

	if(c<5) setTimeout("arrowZoomAnimation("+id+", "+(c+1)+")", 30);
}

function fadeout(id, count){//カウント1..4
	/*IE7～8はフェードアウトしない（半透明PNGが変になる）*/
	var appVersion = window.navigator.appVersion.toLowerCase();
	if (appVersion.indexOf("msie 7.0") > -1 || appVersion.indexOf("msie 8.0") > -1) document.getElementById(id).style.display = "none";

	if(cancelFD[id]){
		document.getElementById(id).style.display = "block";
	}
	else if(count<4){
		document.getElementById(id).style.opacity = 1 - count * 0.3;

		setTimeout("fadeout('"+id+"', "+(count+1)+")", 50);
	}
	else{
		document.getElementById(id).style.display = "none";
	}
}
