//
/*トップページのボード画像に説明表示用*/
function initTop(){

	var fireMenuElem = document.getElementById("fire");
	var liElem = fireMenuElem.getElementsByTagName("li");
	for(var i=0;i<liElem.length;i++){
		liElem[i].onmouseover = hoverInFire;
	}

}

function init2(){
	var subMenuElem = document.getElementById("submenu_p");
	var aElem = subMenuElem.getElementsByTagName("a");
	for(var i=0;i<aElem.length;i++){
		aElem[i].onmouseover = hoverInBtn;
		aElem[i].onmouseout = hoverOutBtn;
	}

}


function init3(){
	var subMenuElem = document.getElementById("submenu_p");
	var aElem = subMenuElem.getElementsByTagName("a");
	for(var i=0;i<aElem.length;i++){
		aElem[i].onmouseover = hoverInBtn;
		aElem[i].onmouseout = hoverOutBtn;
	}

/*
	var defectElem = document.getElementById("defect");
	var imgElem = defectElem.getElementsByTagName("img");
	for(var i=0;i<imgElem.length;i++){
		if(imgElem[i].id.indexOf("popupImg",0) >-1){
			imgElem[i].onmouseover = hoverInImage;
			imgElem[i].onmouseout = hoverOutImage;
			imgElem[i].onmouseup = createPopupImgArea;
		}
	}
*/

}







function initEventList(){
	
	var divElem = document.getElementById("event");
	var h4Elem = divElem.getElementsByTagName("h4");
	for(var i=0;i<h4Elem.length;i++){
		if(h4Elem[i].id != "except"){
			h4Elem[i].onmouseover = changeStyle1;
			h4Elem[i].onmouseout = changeStyle2;
			h4Elem[i].onmouseup = showAndHideMyList;
		}
	}

}

function showAndHideMyList(){
	var ytext = this.firstChild.nodeValue;
	if(ytext.indexOf("2009") > -1){
		if(document.getElementById("y2009").style.display !="block"){
			document.getElementById("y2009").style.display = "block";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▼";
		}else if(document.getElementById("y2009").style.display =="block"){
			document.getElementById("y2009").style.display = "none";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▲";
		}
	}else if(ytext.indexOf("2008") > -1){
		if(document.getElementById("y2008").style.display !="block"){
			document.getElementById("y2008").style.display = "block";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▲";
		}else if(document.getElementById("y2008").style.display =="block"){
			document.getElementById("y2008").style.display = "none";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▼";
		}
	}else if(ytext.indexOf("2007") > -1){
		if(document.getElementById("y2007").style.display !="block"){
			document.getElementById("y2007").style.display = "block";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▲";
		}else if(document.getElementById("y2007").style.display =="block"){
			document.getElementById("y2007").style.display = "none";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▼";
		}
	}else if(ytext.indexOf("2006") > -1){
		if(document.getElementById("y2006").style.display !="block"){
			document.getElementById("y2006").style.display = "block";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▲";
		}else if(document.getElementById("y2006").style.display =="block"){
			document.getElementById("y2006").style.display = "none";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▼";
		}
	}else if(ytext.indexOf("2005") > -1){
		if(document.getElementById("y2005").style.display !="block"){
			document.getElementById("y2005").style.display = "block";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▲";
		}else if(document.getElementById("y2005").style.display =="block"){
			document.getElementById("y2005").style.display = "none";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▼";
		}
	}else if(ytext.indexOf("2004") > -1){
		if(document.getElementById("y2004").style.display !="block"){
			document.getElementById("y2004").style.display = "block";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▲";
		}else if(document.getElementById("y2004").style.display =="block"){
			document.getElementById("y2004").style.display = "none";
			this.getElementsByTagName("em")[0].firstChild.nodeValue = "▼";
		}
	}
}

function changeStyle1(){
	this.style.textDecoration = "underline";
	this.style.cursor = "pointer";
}
function changeStyle2(){
	this.style.textDecoration = "none";
}




function hoverInBtn(){
	
	this.parentNode.style.backgroundColor = "#f5fbd1";
	this.style.color="#000000";
}

function hoverOutBtn(){
	
	this.parentNode.style.backgroundColor = "#ffffff";
	this.style.color="#5b6710";

}

function hoverInFire(){
	var kanbanElem = document.getElementById("board");

	switch(this.id){
		case "fmenu1":
			if(kFlag==1){
				//
			}else{
				kanbanElem.getElementsByTagName("img")[0].src = "images/f1k.jpg";
				kFlag = 1;
			}
			break;
		case "fmenu2":
			if(kFlag==2){
				//
			}else{
				kanbanElem.getElementsByTagName("img")[0].src = "images/f2k.jpg";
				kFlag = 2;
			}
			break;
		case "fmenu3":
			if(kFlag==3){
				//
			}else{
				kanbanElem.getElementsByTagName("img")[0].src = "images/f3k.jpg";
				kFlag = 3;
			}
			break;
		case "fmenu4":
			if(kFlag==4){
				//
			}else{
				kanbanElem.getElementsByTagName("img")[0].src = "images/f4k.jpg";
				kFlag = 4;
			}
			break;
	}
}

function smh(n){
	var subMenuElem = document.getElementById("submenu_p");
	var imgElem = subMenuElem.getElementsByTagName("img");
	switch(n){
		case 1:
			imgElem[1].src = "../images/03hover.gif";
			break;
		case 2:
			imgElem[2].src = "../images/04hover.gif";
			break;
		case 3:
			imgElem[3].src = "../images/05hover.gif";
			break;
		case 4:
			imgElem[4].src = "../images/06hover.gif";
			break;
		case 5:
			imgElem[5].src = "../images/07hover.gif";
			break;
		case 6:
			imgElem[6].src = "../images/08hover.gif";
			break;
		case 7:
			imgElem[7].src = "../images/09hover.gif";
			break;
	}
}
function smho(n){
	var subMenuElem = document.getElementById("submenu_p");
	var imgElem = subMenuElem.getElementsByTagName("img");
	switch(n){
		case 1:
			imgElem[1].src = "../images/03no.gif";
			break;
		case 2:
			imgElem[2].src = "../images/04no.gif";
			break;
		case 3:
			imgElem[3].src = "../images/05no.gif";
			break;
		case 4:
			imgElem[4].src = "../images/06no.gif";
			break;
		case 5:
			imgElem[5].src = "../images/07no.gif";
			break;
		case 6:
			imgElem[6].src = "../images/08no.gif";
			break;
		case 7:
			imgElem[7].src = "../images/09no.gif";
			break;
	}
}





function hoverInImage(){
	this.style.cursor="pointer";
}

function hoverOutImage(){

}


function createPopupImgArea(){//idが「popupImg01_500_250_jpg」という形式

	doTheLightBox();

	var thisID = this.id;
	if(document.getElementById("popupImgArea")){//すでに変更用ダイアログが出ているときは三角旗を押しても反応しない
	//	delBlockDiv();
	}else{
		var ua = navigator.userAgent;
		var nameArray = this.id.split("_");
		var popupFileName = nameArray[0] + "." + nameArray[3];
		//Div表示エリアのサイズ
		var dispImgWidth = parseInt(nameArray[1]) + 30;
		var dispImgHeight = parseInt(nameArray[2]) + 55;

		var globalYPos = 0;
		if(isMSIE(ua) == "safari"){
			globalYPos = document.body.scrollTop;
		}else{
			globalYPos = document.documentElement.scrollTop;
		}

		//ブラウザの幅およびウインドウの高さを取得
		var uaWidth;
		var uaHeight;
		if(isMSIE(ua)=="yes"){
			uaWidth = document.documentElement.clientWidth;
			uaHeight = document.documentElement.clientHeight;
		}else{
			uaWidth = window.innerWidth;
			uaHeight = window.innerHeight;
		}

		//基準センター座標
		var centerX = Math.floor(uaWidth / 2) ;
		var centerY = Math.floor(uaHeight / 2) + globalYPos;


		/******エリアを拡大し可視化するための関数の引数を設定します*/
		var startx = centerX;
		var starty = centerY;
		var startw = 0;
		var starth = 0;
		var endx = startx - Math.floor(dispImgWidth / 2);
		var endy = starty - Math.floor(dispImgHeight / 2);

		var endw = dispImgWidth;
		var endh = dispImgHeight;


		//divタグを新規に生成
		var popupDivAreaElem = document.createElement("div");
		popupDivAreaElem.setAttribute("id","popupImgArea");


		//ドキュメントにdivタグを追加する
		document.body.appendChild(popupDivAreaElem);


//=============スタート位置をブラウザのセンターではなくクリックした旗にする場合
startx = getElemPos(document.getElementById(this.id)).x;
starty = getElemPos(document.getElementById(this.id)).y;

//=============



		dispDialog(popupDivAreaElem,thisID,popupFileName,startx,starty,startw,starth,endx,endy,endw,endh);
	}
}


function dispDialog(elem, flag,fname, startx, starty, startw, starth, endx, endy, endw, endh) {
	var x = startx;
	var y = starty;
	var w = startw;
	var h = starth;

	// エフェクト時間（ミリ秒）
	var period = 100;
	// エフェクト間隔（ミリ秒）
	var interval = 10;
	// 処理回数
	var times = Math.floor(period / interval);
	
	// 表示開始
	elem.style.left   = x + 'px';
	elem.style.top    = y + 'px';
	elem.style.width  = w + 'px';
	elem.style.height = h + 'px';
	
	// 処理回数カウンター
	var  n = 0;
	// タイマーオブジェクト
	var timer;

	var funcRef = function() {
		// カウンターをインクリメント
		n ++;
		// 表示位置
		x += Math.floor( (endx - startx) / times );
		y += Math.floor( (endy - starty) / times );
		elem.style.left = x + 'px';
		elem.style.top  = y + 'px';
		// 表示サイズ
		w += Math.floor( (endw - startw) / times );
		h += Math.floor( (endh - starth) / times );
		elem.style.width  = w + 'px';
		elem.style.height = h + 'px';
		
		//途中から表示。intervalが10なので、その中の割合数字
		if(n==2){
			elem.style.visibility = 'visible';
		}
		// カウンターの値を評価
		if(n >= times) {
			// 最終のサイズに調整
			elem.style.left   = endx + 'px';
			elem.style.top    = endy + 'px';

			elem.width  = endw + 'px';
			elem.height = endh + 'px';
			// タイマー解除
			clearInterval(timer);

		var popupImgElem = document.createElement("img");
		popupImgElem.setAttribute("src","../images/" + fname);
		popupImgElem.setAttribute("width",endw - 30);
		popupImgElem.setAttribute("height",endh - 55);


		elem.appendChild(popupImgElem);
		}
	}
	

	// タイマーセット
	timer = setInterval(funcRef, interval);

	
	var bx = parseInt(endx) + endw - 20;
	var by = parseInt(endy);
	setEraseButton(elem,flag,bx,by);

}

function setEraseButton(elem,flag,bx,by){
	var btnElem = document.createElement("span");
	var closeMsgElem = document.createTextNode("×CLOSE");
	btnElem.setAttribute("id","closeBtn");
	btnElem.appendChild(closeMsgElem);
	document.body.appendChild(btnElem);

	btnElem.style.left = bx + "px";
	btnElem.style.top = by -10 + "px";
	
	var timer;
	var counter=5;
	
	var funcBtn = function() {
		if(counter==0){
			btnElem.style.visibility = "visible";
			clearInterval(timer);
		}
		counter--;
	}
	timer = setInterval(funcBtn,"100");

	btnElem.onclick = function(){
		delBlockDiv(flag);
	}
}


function delBlockDiv(flag) {
	if(document.getElementById("popupImgArea")) {
		
		//まずボタンを消す
		var btnElem = document.getElementById("closeBtn");
		btnElem.parentNode.removeChild(btnElem);
		
		var divElem= document.getElementById("popupImgArea");
		//器の中のdiv要素を消して移動する。
		//器ノードを削除する前に、追加した子ノードをすべて移動。html内に固定的に作成してあるため、器ごと消したら呼び出してもnullになる
/*		var num = divElem.childNodes.length;
		for(var i=0;i<num;i++){
			divElem.firstChild.style.display="none";
			document.body.appendChild(divElem.firstChild);
		}
*/
		divElem.removeChild(divElem.childNodes.item(0));




		var startx =  getElemPos(divElem).x;
		var starty = getElemPos(divElem).y;
		var startw = parseInt(divElem.style.width);
		var starth = parseInt(divElem.style.height);

		//自分のセンター位置に向かって縮小する
		
		var endx = getElemPos(divElem).x + Math.floor(startw / 2);
		var endy = getElemPos(divElem).y + Math.floor(starth / 2);
		
		var endw = 0;
		var endh = 0;

//=============ブラウザのセンターではなくクリックした旗に向って収束する場合
endx = getElemPos(document.getElementById(flag)).x;
endy = getElemPos(document.getElementById(flag)).y;

//=============

		smallerImg(divElem,flag,startx,starty,startw,starth,endx,endy,endw,endh);
	}
}

function smallerImg(elem, flag, startx, starty, startw, starth, endx, endy, endw, endh) {
	var x = startx;
	var y = starty;
	var w = startw;
	var h = starth;

	// エフェクト時間（ミリ秒）
	var period = 100;
	// エフェクト間隔（ミリ秒）
	var interval = 10;
	// 処理回数
	var times = Math.floor(period / interval);
	
	// 表示開始
	elem.style.left   = x + 'px';
	elem.style.top    = y + 'px';
	elem.width  = w + 'px';
	elem.height = h + 'px';
	
	// 処理回数カウンター
	var  n = 0;
	// タイマーオブジェクト
	var timer;


	// エフェクト処理の無名関数
	var funcRef = function() {
		// カウンターをインクリメント
		n ++;
		// 表示位置
		x += Math.floor( (endx - startx) / times );
		y += Math.floor( (endy - starty) / times );
		elem.style.left = x + 'px';
		elem.style.top  = y + 'px';
		// 表示サイズ
		w += Math.floor( (endw - startw) / times );
		h += Math.floor( (endh - starth) / times );
		elem.style.width  = w + 'px';
		elem.style.height = h + 'px';

		//途中から消す
		if(n==8){
			elem.style.visibility = 'hidden';
dontTheLightBox();

		}

		// カウンターの値を評価
		if(n >= times) {
			// 最終のサイズに調整
			elem.style.left   = endx + 'px';
			elem.style.top    = endy + 'px';
			elem.width  = endw + 'px';
			elem.height = endh + 'px';
			// タイマー解除
			clearInterval(timer);

			elem.parentNode.removeChild(elem);

		}
	}
	
	// タイマーセット
	timer = setInterval(funcRef, interval);
}








//■MSIEのみを判別する
function isMSIE(ua){
	if (ua.indexOf("MSIE")<0){
		if (ua.indexOf("Safari")>0){
			return "safari";
		}else{
			return "no";
		}
	}else{
		return "yes";
	}
}
// 要素の位置を取得し、オブジェクトとして返す
function getElemPos(elem) {
	var obj = new Object();
	obj.x = elem.offsetLeft;
	obj.y = elem.offsetTop;
	while(elem.offsetParent) {
		elem = elem.offsetParent;
		obj.x += elem.offsetLeft;
		obj.y += elem.offsetTop;
	}
	return obj;
}

function doTheLightBox(){
	var containerElem = document.getElementById("container");
	containerElem.style.filter = "alpha(opacity=70)";
	containerElem.style.MozOpacity = "0.7";
	containerElem.style.opacity = "0.7";
}
function dontTheLightBox(){
	var containerElem = document.getElementById("container");
	containerElem.style.filter = "alpha(opacity=100)";
	containerElem.style.MozOpacity = "1";
	containerElem.style.opacity = "1";
}

