$(function(){

//メインイメージ
onload = function () {

	mainTimer = 0;
	current = 1;
	button = 1;

	showTime = 4500; // 4500

	pictures = $('#rBanner li').length;
	width = $('#rb01 img').outerWidth();

	$('#rb01').css("left","0px");

//	mainTimer = setTimeout(autoPlay, showTime);

//右矢印操作

	$("#scrBtn01").click(function () {
		button = current;
		current--;
		if (current == 0) { current = pictures }
		animateLeft(current, button)
	});

//左矢印操作

	$("#scrBtn02").click(function () {
		button = current;
		current++;
		if (current == (pictures + 1)) { current = 1 }
		animateRight(current, button)
	});

	$("#thumbnail li").click(function () {
		button = current;
		clickButton = $(this).attr('id');
		current = parseInt(clickButton.slice(3));
		if (current > button) { animateRight(current, button) }
		if (current < button) { animateLeft(current, button) }
		});

	function animateRight(current, button) {
		$('#rb0' + current).css("left", width + "px");
		$('#rb0' + current).animate({ "left": "0px" }, "slow", "swing");
		$('#rb0' + button).animate({ "left": -width + "px" }, "slow", "swing");
		setbutton();
		}

//	$("#mainImg").mouseover(function () { clearTimeout(mainTimer); });
//	$("#mainImg").mouseout(function () { mainTimer = setTimeout(autoPlay, showTime); });



/*	function autoPlay(){
		button = current;
		current++
		if (current == (pictures + 1)) { current = 1 }
		animateRight(current, button)
		clearTimeout(mainTimer)
		mainTimer = setTimeout(autoPlay, showTime);
	}*/

	function animateLeft(current, button) {
		$('#rb0' + current).css("left", -width + "px");
		$('#rb0' + current).animate({ "left": "0px" }, "slow", "swing");
		$('#rb0' + button).animate({ "left": width + "px" }, "slow", "swing");
		setbutton();
	}

	function setbutton() {
		$('#sb0' + button + ' img').attr("src","/images/main_ico02.gif");
		$('#sb0' + current + ' img').attr("src","/images/main_ico01.gif");
	}
}

//ニュースのスクロール
	var cnt = $("div#news ul li").size();
	var scrHeight = 0;
	var timer = setTimeout(loop, 3000);

	function loop() {
	setTimeout(function() {
		clearTimeout(timer);
		if(scrHeight<-66) scrHeight = 0;
		$("div#news ul").stop(true, false).animate({marginTop:scrHeight+"px"},"slow","swing");
		scrHeight -= 33;
		timer = setTimeout(loop, 3000);
		}, 3000);
	}

	$("div#news ul").mouseover(function(){
		clearTimeout(timer);
		}).mouseout(function () {
		timer = setTimeout(loop, 3000);
		});

//募集中の職種のパタパタ

	var ulHeight= $("div#invite ul").height(); //ulの本来の高さの取得
	$("div#invite ul").css("height","103px"); //ulを畳んだ状態に戻す
	$("div#invite p.btn").css("margin-top","108px"); //ulを畳んだ状態に戻す

	$("div#invite p.btn").toggle(function(){
		$("div#invite ul").animate({height:ulHeight},"normal","swing");
		$("div#invite p.btn").animate({marginTop:ulHeight+5+"px"},"normal","swing"); //ulを畳んだ状態に戻す
		$("img#open",this).css("display","none");
		$("img#close",this).css("display","block");
		},function(){
		$("div#invite ul").animate({height:"103px"},"normal","swing");
		$("div#invite p.btn").css("margin-top","108px"); //ulを畳んだ状態に戻す
		$("img#open",this).css("display","block");
		$("img#close",this).css("display","none");
	});




});
