
var slideTimeOut = 11000; // スライドショーが切り替わるまでの時間
var fadeTimeOut = 900; // フェードアニメーションにかかる時間
var imgIndex = 0;
var oldIndex = 0;
var startSlideshow;

$(function()
{
	// 初期状態
	var targetGallery = $('#topBanner .gallery');
	var countGallery = $(targetGallery).size();
	$('#topBanner .gallery:gt(0)').hide();
	$(targetGallery).css({"position":"absolute","top":"0px","left":"10px"});
	// スライドショー開始
	startSlideshow = setInterval(function(){ readySlideshow(); }, slideTimeOut);
	// ナビゲーション連動
	var targetNav = $('#header ul.nav');
	var targetAnchor = $(targetNav).find('a');
	var countAnchor = $(targetAnchor).size();
	$(targetAnchor).hover(function() // mouseover
	{
		clearInterval(startSlideshow);
		oldIndex = imgIndex;
		var indexNav = $(targetAnchor).index(this);
		if(countGallery - 1 < indexNav) { indexNav = 0; }
		imgIndex = indexNav;
		if(oldIndex != imgIndex)
		{
			$('#topBanner .gallery').fadeOut(fadeTimeOut);
			$('#topBanner .gallery:eq('+ imgIndex +')').fadeIn(fadeTimeOut);
		}
	},
	function() // mouseout
	{
		oldIndex = imgIndex;
		startSlideshow = setInterval(function(){ readySlideshow(); }, slideTimeOut);
	});
	// スライドショーセット
	function readySlideshow()
	{
		oldIndex = imgIndex;
		if(countGallery - 2 < imgIndex) { imgIndex = 0; }
		else { imgIndex ++; }
		$('#topBanner .gallery:eq('+ oldIndex +')').fadeOut(fadeTimeOut);
		$('#topBanner .gallery:eq('+ imgIndex +')').fadeIn(fadeTimeOut);
	}
});








