function eyecatch() {
	//アニメーションスピード
	var scroll_speed = 20;
	//リスト全体の初期幅
	var topwidth_org = $('#eyecatch-top ul').width();
	var bottomwidth_org = $('#eyecatch-bottom ul').width();
	//リンクにマウスが乗っているか
	var stop = false;
	
	//初期化
	$('#eyecatch-top')
		.append($('#eyecatch-top').html())
		.width(topwidth_org * $('#eyecatch-top ul').length);
	$('#eyecatch-bottom')
		.prepend($('#eyecatch-bottom').html())
		.width(bottomwidth_org * $('#eyecatch-bottom ul').length)
		.css({left:($('#eyecatch-bottom').width() * -1) + $('#eyecatch-bottom').parent().width()});
	$('#eyecatch-middle li img').css({
		position:'absolute',
		top:0,
		left:0
	});
	$('#eyecatch-middle li:eq(0) img').height(0);
	
	//リストの位置
	var topleft_pos = $('#eyecatch-top').position().left;
	var bottomleft_pos = $('#eyecatch-bottom').position().left;
	//下段リストの折り返しポジション
	var bottom_resetpos = bottomleft_pos + bottomwidth_org;
	
	//アニメーション
	//リストスクロール
	function animate_list() {
		if(!stop) {
			topleft_pos--;
			if(topleft_pos <= topwidth_org * -1) topleft_pos = 0;
			$('#eyecatch-top').css({left:topleft_pos});
			bottomleft_pos++;
			if(bottomleft_pos >= 0) bottomleft_pos = bottomwidth_org * -1;
			$('#eyecatch-bottom').css({left:bottomleft_pos});
		}
		clearTimeout(timer);
		timer = setTimeout(animate_list, scroll_speed);
	}
	var timer = setTimeout(animate_list, scroll_speed);
	
	//メッセージ
	function animate_middle() {
		var message_speed = 700;
		var delay = 2000;
		$('#eyecatch-middle li:eq(0) img').animate(
			{
				top:52,
				height:0
			},
			{
				duration:message_speed,
				easing:'swing',
				complete:function() {
					$('#eyecatch-middle li:eq(1) img').animate(
						{
							top:0,
							height:114
						},
						{
							duration:message_speed,
							easing:'swing',
							complete:function() {
								setTimeout(function() {
									$('#eyecatch-middle li:eq(1) img').animate(
										{
											top:52,
											height:0
										},
										{
											duration:message_speed,
											easing:'swing',
											complete:function() {
												$('#eyecatch-middle li:eq(0) img').animate(
													{
														top:0,
														height:114
													},
													{
														duration:message_speed,
														easing:'swing',
														complete:function() {
															setTimeout(function() {
																animate_middle();
															}, delay);
														}
													}
												);
											}
										}
									);
								}, delay);
							}
						}
					);
				}
			}
		);
	}
	animate_middle();
	
	//リンクにマウスが乗った場合
	$('#main-eyecatch a').hover(
		function() {
			stop = true;
			var that = this;
			var interview_speed = 300;
			$('img.interview', that).animate({bottom:5},{
				duration:interview_speed,
				easing:'swing',
				complete:function() {
					$('img.interview', that).animate({bottom:0},{
						duration:interview_speed,
						easing:'swing',
						complete:function() {
							$(that).trigger('mouseover');
						}
					});
				}
			});
		},
		function() {
			stop = false;
			var that = this;
			$('img.interview', that)
				.stop()
				.css({bottom:0});
		}
	);
	$('#main-eyecatch a').click(function() {
		$(this).trigger('mouseout');
	});
}

$(function() {
	eyecatch();
});

