$(function(){

// variable

	var loading = '#loading',
		slideImage = '#slideImage',
		thumArea = '#thumArea',
		thum = '.thum',
		i = 1,
		present = 0,  // スクロールの数値
		slideshowInterval = '' , // slideshowIntervalの初期化
		thumSize = $('img', thum).size(); // 画像の数取得

// setting

	settings = jQuery.extend({
		slideshowTime : 3000,  // 画像切り替え時間
		fadeSpeed : 1000, // サムネイルフェード速度
		slideSpeed : 700 // サムネイルスライド速度
	});

// style

	$('img:not(:first)', slideImage).css('opacity', 0);
	$('img:first', slideImage).addClass('show').css('opacity', 1);
	$('img:first', thum).addClass('on').css('border-color', "#4CAE47").animate({opacity: 0.8},{duration:settings.fadeSpeed , queue: false});

// play side

	startSlideshow = function(i) {
		clearInterval(slideshowInterval);
		slideshowInterval = setInterval(function() {
			if(i == thumSize){i = 0;};
			crossFade(i);
			linkChange(i);
			if(i < thumSize){ i = i + 1;}else if(i == thumSize){i = 0;};
		}, settings.slideshowTime);
	};

// crossFade function

	function crossFade(i){
		$('img.show', slideImage).removeClass("show").animate({opacity: 0},{duration: settings.fadeSpeed, queue: false});
		$('img', slideImage).eq(i).addClass("show").animate({opacity: 1},{duration: settings.fadeSpeed, queue: false});
		$('img.on', thum).removeClass("on").css('border-color', "#BBBBBB").animate({opacity: 1},{duration: settings.fadeSpeed, queue: false});
		$('img', thum).eq(i).addClass("on").css('border-color', "#4CAE47").animate({opacity: 0.8},{duration: settings.fadeSpeed, queue: false}); 
	}

// linkChange

	function linkChange(i){
		var aNow = $('a', slideImage).eq(i).attr('href');
		$('#aClick').attr('href', aNow);
	}

// click thumnail

	$('img', thum).hover(function(){
		clearInterval(slideshowInterval);
		var num = $('li img', thum).index(this);
		crossFade(num);
		startSlideshow(num + 1);
		linkChange(num);
	},function(){
		return false;
	})

// mousehover

	$('img', slideImage).hover(function(){
		clearInterval(slideshowInterval);
	},function(){
  		var currentNum = $('img', slideImage).index($('img.show'));
		startSlideshow(currentNum + 1);
	})

// loading

	$(window).load(function () {
		$(loading).fadeOut(1000,function(){
			startSlideshow(i);
			linkChange(i - 1);			
		});
	});
})
