// JavaScript Document
jQuery(document).ready(function(){
//アンカースムーズスクロール
jQuery('a').click(function() {
var jumpTo = jQuery(this).attr('href');
if(jumpTo == '#top') {
$('html,body').animate({ scrollTop: 0 }, 'slow');
return false;
}
else if(jumpTo == '#') {
return false;
}
else if(jumpTo.charAt(0) == '#') {
$('html,body').animate({ scrollTop: jQuery(jumpTo).offset().top }, 'slow');
return false;
}
});
});


jQuery('a').click(function backToTop(){
$('html,body').animate({ scrollTop: 0 }, 'slow');
});





$(function(){
	$('#carousel').each(function(){
		var slideTime = 500;
		var delayTime = 4000;

		var carouselWidth = $(this).width();
		var carouselHeight = $(this).height();
		

		$('#carousel_wrap').css({
			width: (carouselWidth),
			height: (carouselHeight),
			position: 'relative',
			overflow: 'hidden'
		});

		var listWidth =189;
		var listCount = $('#carousel_move').children('ul').children('li').length;

		var ulWidth = (listWidth)*(listCount);

		$('#carousel_move').css({
			top: '0',
			left: -(ulWidth),
			width: ((ulWidth)*3),
			height: (carouselHeight),
			position: 'absolute'
		});

		$('#carousel_wrap ul').css({
			width: (ulWidth),
			float: 'left'
		});
		$('#carousel_wrap ul').each(function(){
			$(this).clone().prependTo('#carousel_move');
			$(this).clone().appendTo('#carousel_move');
		});

		carouselPosition();

		$('#carouselPrev').click(function(){
			clearInterval(setTimer);
			$('#carousel_move:not(:animated)').animate({left: '+=' + (listWidth)},slideTime,function(){
				carouselPosition();
			});
			timer();
		});

		$('#carouselNext').click(function(){
			clearInterval(setTimer);
			$('#carousel_move:not(:animated)').animate({left: '-=' + (listWidth)},slideTime,function(){
				carouselPosition();
			});
			timer();
		});

		function carouselPosition(){
			var ulLeft = parseInt($('#carousel_move').css('left'));
			var maskWidth = (carouselWidth) - ((listWidth)*(listCount));
			if(ulLeft == ((-(ulWidth))*2)) {
				$('#carousel_move').css({left:-(ulWidth)});
			} else if(ulLeft == 0) {
				$('#carousel_move').css({left:-(ulWidth)});
			};
		};

		timer();

		function timer() {
			setTimer = setInterval(function(){
				$('#carouselNext').click();
			},delayTime);
		};

	});
});
