/*------------------------------------

	入力中のフォームの色の変更

------------------------------------*/
function bgcOver(element) {
	element.style.backgroundColor = '#ccc';
}
function bgcOut(element) {
	element.style.backgroundColor = '#fff';
}
/*------------------------------------

	OPEN WINDOW

------------------------------------*/
function getA(idName) {
	var x = document.getElementById(idName).getElementsByTagName('a');
	for (var i=0; i<x.length; i++) {
		x[i].onclick = function () { return openWin(this.href); }
		x[i].onkeypress = function () { return openWin(this.href); }
	}
}

function openWin(target) {
	newWin = open(target, "", "resizable=yes,scrollbars=yes,width=" + window.screen.width + ",height=" + window.screen.height);
	newWin.moveTo(0,0);
	newWin.focus();
	return false; 
}

/*------------------------------------

	WINDOW CLOSE

------------------------------------*/
function CloseWin(){
    window.close();
}

/*------------------------------------

	SLIDE MENU

------------------------------------*/
var speed = 5;

var tabboxPos = 1;
var btnPos = 30;

var timerID;

var tabPosition;
var btnPosition;

var moveJudge;

function slider(inout) {
	ua = uaJudge();

	if (inout == "display") {
		if(ua == 1) {
			tabPosition = 0;
			btnPosition = 530;
			moveJudge = 713;
		} else {
			tabPosition = 10;
			btnPosition = 540;
			moveJudge = 723;
		}
		moveIn();
	}	
	if (inout == "hide") {
		if(ua == 1){
			tabPosition = -500;
			btnPosition = 0;
			moveJudge = 539;
		} else {
			tabPosition = -510;
			btnPosition = 10;
			moveJudge = 549;
		}
		moveOut();
	} else {
		return false;
	}
}

function moveIn() {
	
	tabboxPos = tabboxPos + (tabPosition - tabboxPos) / speed;
	document.getElementById('tabArea').style.top = tabboxPos + 'px';
	btnPos = btnPos + (btnPosition - btnPos) / speed;
	document.getElementById('tabIndex').style.top = btnPos + 'px';
	timerID = setTimeout("moveIn()",20);
	if (tabboxPos > moveJudge) {
		document.getElementById('tabArea').style.top = tabPosition + 'px';
		document.getElementById('tabIndex').style.top = btnPosition + 'px';
		clearTimeout(timerID);
	}
	createBtn('hide');
}

function moveOut() {
		
	tabboxPos = tabboxPos + (tabPosition - tabboxPos) / speed;
	document.getElementById('tabArea').style.top = tabboxPos + 'px';
	btnPos = btnPos + (btnPosition - btnPos) / speed;
	document.getElementById('tabIndex').style.top = btnPos + 'px';
	timerOut = setTimeout("moveOut()",50);
	if (tabboxPos < moveJudge) {
		document.getElementById('tabArea').style.top = tabPosition + 'px';
		document.getElementById('tabIndex').style.top = btnPosition + 'px';
		clearTimeout(timerOut);
	}
	createBtn("display");
}

function createBtn(inout) {
	if(inout == "display") {
		var idName = "tabBtn";
		var txt = "open";
		var funcName = "slider('display');";
	} else {
		var idName = "tabCloseBtn";
		var txt = "close";
		var funcName = "slider('hide');";
	}
	// IDも属性も内容もない空の要素ノードを作成します。
	var sp1 = document.createElement("h2");
	
	// それに'newSpan'というid属性を与えます。
	sp1.setAttribute("id", idName);
	
	if(uaJudge() == 1) sp1.setAttribute("onclick", new Function(funcName));
	else sp1.setAttribute("onclick", funcName);
	
	// 新しい要素のためにいくつかの内容を作成します。
	var sp1_content = document.createTextNode("SLIDE BAR");
	
	// 新しい要素にさきほどの内容を適用します。
	sp1.appendChild(sp1_content);
	
	// 置き換えるべく存在するノードへの参照を構築します。
	var sp2 = document.getElementById("tagIndex");
	var parentDiv = sp2.parentNode;
	
	// 存在するノード sp2 を新しいspan要素のsp1で置き換えます。
	parentDiv.replaceChild(sp1, sp2);
	  
	/*var element = document.getElementById("tagIndex");
	var newElement = document.createElement("h2");
	newElement.innerHTML = "SLIDE BAR";
	newElement.id = idName;
	newElement.title = txt;
	if(uaJudge() == 1) newElement.setAttribute("onclick", new Function(funcName));
	else newElement.setAttribute("onclick", funcName);*/

	var target = element.childNodes.item(0);
	element.replaceChild(newElement, target);

	
	
	/*var element = document.getElementById("tagIndex").getElementsByTagName("h2");
	element.removeAttribute("onclick");
	element.removeAttribute("id");
	element.id = idName;
	element.title = txt;
	if(uaJudge() == 1) element.setAttribute("onclick", new Function(funcName));
	else element.setAttribute("onclick", funcName);*/


	
	/*var element = document.getElementById("tabIndex");
	var newElement = document.createElement("h2");
	newElement.id = idName;
	newElement.title = txt;
	newElement.innerHTML = txt;
	if(uaJudge() == 1) newElement.setAttribute("onmouseover", new Function(funcName));
	else newElement.setAttribute("onmouseover", funcName);
	var target = element.childNodes.item(0);
	element.replaceChild(newElement, target);*/

}

function uaJudge() {
	ua = 0;
	if(navigator.userAgent.indexOf("Opera") >= 0){
		ua = 2;
	}
	else if(navigator.userAgent.indexOf("MSIE 5.") >= 0){
		ua = 1;
	}
	else if(navigator.userAgent.indexOf("MSIE 6.") >= 0){
		ua = 1;
	}
	else {
		ua = 2;
	}
	return ua;
}