﻿var Lchk,MPos;

/*
function init(){
chkLogin();
}
*/
var movingflag =0;

function chkLogin(){
	new Ajax.Request(
	'../index.php',
	{
		parameters: "m=chkLogin",
		onComplete : getchkLogin = function(resp)
		{
		  var data = resp.responseText.evalJSON();
		  var state = data.ret[0].state;
		  if(state == 1)
			{
			if(Element.visible("logout"))
				{
				$("logout").style.visibility = "hidden";
				$("login").style.visibility = "visible";
				$("signup").style.visibility = "visible";
				$("nicname").style.visibility = "hidden";
				Element.hide("withdraw");


				if(!Element.visible("moving-child"))
					{
					Element.hide("golist");
					Element.show("moving-child");
					MovingPos();
					}
				}				
			}
			else
			{
			if(Element.visible("login")){
				Element.show("withdraw");
				$("nicname").innerHTML = "ようこそ"+data.nic[0].name+"さん";
				$("nicname").style.visibility = "visible";
				$("logout").style.visibility = "visible";
				$("login").style.visibility = "hidden";
				$("signup").style.visibility = "hidden";
				Element.hide("moving-child");
				clearTimeout(MPos);
				Element.show("golist");

				Lchk =setTimeout("chkLogin()",60000);
			}
			}
		},
		method:"get"
	}
	);
}

function MovingPos(){
var setmovingpos;
var movingpos = parseInt(Element.getStyle($('moving-child'), "left"));
if(movingpos<-417){
setmovingpos ="591px"
Element.setStyle("moving-child", {left:setmovingpos});
}else{
setmovingpos = (movingpos-10)+"px";
Element.setStyle("moving-child", {left:setmovingpos});
}

MPos = setTimeout("MovingPos()",100);
}


function LogOut2(){
	new Ajax.Request(
	'../index.php',
	{
		parameters: "m=LogOut2",
		onComplete : getLogOut2 = function(resp)
		{
			$("logout").style.visibility = "hidden";
			$("login").style.visibility = "visible";
			$("signup").style.visibility = "visible";
			$("nicname").style.visibility = "hidden";
			Element.hide('golist');
			if(!Element.visible("moving-child")){
			Element.show("moving-child");
			MovingPos();
			}
			
      clearTimeout(Lchk);
		},
		method:"get"
	}
	);
}

//Event.observe(window,'load',init);
