/* 
使用ページ：サイトトップページ
 */

/* ---------------------------------------
 * cKey		検索単語
 * tdNmb		検索対象列番号
 * thisObj	クリックされたオブジェクト
------------------------------------------ */
function change(cKey, tdNmb, thisObj){

	cTab(thisObj, 2);	//クリックされたＴＡＢの処理

	var tbody = document.getElementById("tdata");
	tCount = 1;
	dummyPos = 0;
	for(var i = 0; i < tbody.rows.length; i++) {
		var caData = tbody.rows[i].cells[tdNmb].innerHTML;	//検索対象文字列抽出

		if(caData.indexOf(cKey,0) != -1){
			tbody.rows[i].style.visibility = "visible";
			//番号振り イベント、アップデート、キャンペーン以外は番号を振る
			if(tdNmb != 3){
				tbody.rows[i].cells[0].innerHTML = tCount;
				tCount++;
			}

			if(dummyPos != i){
				tbody.insertBefore(tbody.rows[i], tbody.rows[dummyPos]);
			}
			dummyPos++;

		}else{
			tbody.rows[i].style.visibility = "hidden";

			if(dummyPos > i){ dummyPos = i; }
		}
	}
	//表示位置をリストトップへ
	var y = getWinYOffset();
	tbody.rows[0].scrollIntoView('true');
	scroll(0,y);
}


/* ---------------------------------------------
 * thisObj	クリックされたオブジェクト
 * flag		処理フラグ	0:OUT  1:OVER  2:ACTION
------------------------------------------------ */

//クロージャ設定
var cTab = changeTAB();

function changeTAB(){
	var publicObj;				//現クリックタブ
	var formerPublicObj;		//前クリックタブ

	return function (thisObj, flag){
		switch( flag ){
			case 0:	thisObj.style.backgroundColor   = "#09f";
						if(publicObj){ publicObj.style.backgroundColor = "#f00"; }
						break;

			case 1:	thisObj.style.backgroundColor = "#039";
						break;

			case 2:	thisObj.style.backgroundColor = "#f00";
						formerPublicObj = publicObj;	//以前のクリックオブジェクト設定
						publicObj = thisObj;				//新規のクリックオブジェクト設定
						if(formerPublicObj){ formerPublicObj.style.backgroundColor = "#09f"; }
						break;
		}
	};
}


/* ---------------------------------------------
 * thisObj	クリックされたオブジェクト
 * flag		処理フラグ	0:OUT  1:OVER  2:ACTION
 * str		文字
------------------------------------------------ */
function goh(thisObj, flag, str){
		switch( flag ){
			case 0:	thisObj.cells[0].style.backgroundColor = "";
						thisObj.cells[2].style.backgroundColor = "";
						thisObj.cells[3].style.backgroundColor = "";
						break;

			case 1:	thisObj.cells[0].style.backgroundColor = "#6f6";
						thisObj.cells[2].style.backgroundColor = "#6f6";
						thisObj.cells[3].style.backgroundColor = "#6f6";
						break;

			case 2:	location = "http://freemmorpg.web.fc2.com/onlinegame/" + str + ".html";
						break;
		}
}


function getWinYOffset(){
  if(window.scrollY) return window.scrollY; // Mozilla
  if(window.pageYOffset) return window.pageYOffset; // Opera, NN4
  if(document.documentElement && document.documentElement.scrollTop){ // 以下 IE
   return document.documentElement.scrollTop;
  }
  else if(document.body && document.body.scrollTop){
   return document.body.scrollTop;
  }
  return 0;
}

