
$(function(){
	
	var duration = 500;
	var easing = 'swing';
	var list_wrap = $('#SlideBnr ul');
	var list_frames = $('li',list_wrap);
	
	//初期設定
	if($(list_frames).size() < 6){
		list_frames.clone().appendTo(list_wrap);
		$(list_wrap).css('width',213*($(list_frames).size()*2)+'px');
	}else{
		$(list_wrap).css('width',213*$(list_frames).size()+'px');
	}
	$('li:last',list_wrap).prependTo(list_wrap);
	$(list_wrap).css('margin-left','-213px');

	//アクション
	$(document).everyTime(5000, "autoPlay", autoPlay);
	
	function autoPlay(){
		next_frame();
	}
	
	$('#SlideBnr p.next').click(function(){
		if(!$(list_wrap).is(':animated')){
			$(document).stopTime("autoPlay");
			next_frame();
		}
	});

	$('#SlideBnr p.prev').click(function(){
		if(!$(list_wrap).is(':animated')){
			$(document).stopTime("autoPlay");
			prev_frame();
		}
	});
	
	//進むボタン
	function next_frame(){
		$(list_wrap).animate({
			marginLeft:parseInt($(list_wrap).css('margin-left'))-213+'px'
		},duration,easing,
		function(){
			$(list_wrap).css('margin-left','-213px');
			$('li:first',list_wrap).appendTo(list_wrap);
			$(document).everyTime(5000, "autoPlay", autoPlay);
		});
	}

	//戻るボタン
	function prev_frame(){
		$(list_wrap).animate({
			marginLeft:parseInt($(list_wrap).css('margin-left'))+213+'px'
		},duration,easing,
		function(){
			$(list_wrap).css('margin-left','-213px');
			$('li:last',list_wrap).prependTo(list_wrap);
			$(document).everyTime(5000, "autoPlay", autoPlay);
		});
	}
});


