// JavaScript Document
<!--
$(function(){
//アニメーション効果とタイマーと透明度の設定
var _o = {
	speed : 800,
	easing : 'swing',
	interval : 5000,
	alpha : 0.5
}
//セレクターを変数に格納
var $ul_pgn = $('#pagenation ul'),
    $li_ul_pgn = $ul_pgn.children();
//各種値設定に必要のcss属性値取得
var _get = {
	imgNum : $('#slider ul li').size(),//画像数
	wSli : $('#slider').width(),//表示領域のwidth
	wLi : $('#slider ul li').width(),
	padLi : parseInt($('#slider ul li').css('padding-right').replace(/\D/g,""))
}
//値設定
var _val = {
	//margin-leftの初期値
	marLeft : -(_get.wLi - ((_get.wSli - _get.wLi)/2 - _get.padLi)),
	parDis : _get.wLi + _get.padLi//li要素1つあたりの移動量
}
//カウント
var _count = {
	current : 0,
	Max : _get.imgNum-1
}
//関数の定義
var _fnc = {
	alpha_low : function(){
					$('#slider ul li').css({
						opacity : _o.alpha,
						filter : "alpha(opacity="+_o.alpha*100+")"   
					})
				},
	alpha_100 : function(){
					$('#slider ul li:eq(1)').css({
						opacity : 1,
						filter : "alpha(opacity=100)"
					})
				},
	pageNavi  : function(){
					$li_ul_pgn.filter(':not(:eq('+_count.current+'))').removeClass('selected');
					$li_ul_pgn.filter(':eq('+_count.current+')').addClass('selected');
				},
	timer     : function(){
					timerID = setInterval(function(){
					_fnc.first();
					var $ul_slider = $('#slider ul');
					$ul_slider.filter(':not(:animated)').stop(true,false).animate({
						marginLeft : parseInt($ul_slider.css('margin-left')) - _val.parDis
					},_o.speed,_o.easing,
					function(){
						$ul_slider.children(':eq(0)').appendTo('#slider ul');
						$ul_slider.css('margin-left', _val.marLeft);
						if(_count.current == _count.Max) _count.current = 0;
						else _count.current++;
						_fnc.callback();
					});
					},_o.interval);
				},
	first     : function(){
					clearInterval(timerID);
					//this.alpha_low();
				},
	callback  : function(){
					//this.alpha_100();
					//this.pageNavi();
					this.timer();
				},
	oneMove   : function(bool){
		
		_fnc.first();
		var distance;
		distance = bool === false ? -(_val.parDis) : _val.parDis ;
	
		var $ul_slider = $('#slider ul');
		$ul_slider.filter(':not(:animated)').stop(true,false).animate({
			marginLeft : parseInt($ul_slider.css('margin-left')) - distance
		},_o.speed,_o.easing,
		function(){
			if(bool){
				
				$ul_slider.children(':eq(0)').appendTo('#slider ul');
				$ul_slider.css('margin-left', _val.marLeft);
				if(_count.current == _count.Max){
					_count.current = 0;
				} else {
					_count.current++;
				}
				
			} else {
				
				$ul_slider.children(':last').prependTo('#slider ul');
				$ul_slider.css('margin-left', _val.marLeft);
				if(_count.current == 0){
					_count.current = _count.Max;
				} else {
					_count.current--;
				}
			}
			
			_fnc.callback();
		});
		
	}
}
//読み込み時css設定
$('#slider ul li').each(function(){
	$(this).attr('id','list'+$(this).index());
});
$('#slider ul').css({
	width :	(_get.wLi+_get.padLi)*_get.imgNum,
	marginLeft : _val.marLeft
});
$('#slider ul li:last').prependTo('#slider ul');
//$li_ul_pgn.addClass('default');
//_fnc.pageNavi(_count.current);
//_fnc.alpha_low();
//_fnc.alpha_100();
_fnc.timer();

//#next
$('#next').click(function(){

	_fnc.oneMove(true);

});

$('#prev').click(function(){

	_fnc.oneMove(false);

});

//#pagenation ul liをクリックしたとき
/*$('#pagenation ul li').click(function(){
	var $li = $(this);
	var pindex = $li.index();
	if(pindex != _count.current){
		_fnc.first();
		var $ul_slider = $('#slider ul');
		var imgindex = $ul_slider.children('#list' + pindex).index();
		var distance;
		if(imgindex == 0) distance = _val.parDis;
		else if(imgindex == _count.Max) distance = _val.parDis*(imgindex - 2);
		else distance = (imgindex - 1)*_val.parDis;
		if(imgindex == _count.Max){
			$ul_slider.filter(':not(:animated)').stop(true,false).animate({
			},0,
			function(){
				//$ul_slider.children(':eq(0)').clone().appendTo('#slider ul');
				$ul_slider.children(':eq(0)').appendTo('#slider ul');
			});
			$ul_slider.filter(':not(animated)').stop(true,false).animate({
				marginLeft : parseInt($ul_slider.css('margin-left')) - distance
				},_o.speed,_o.easing,
				function(){
					//$ul_slider.children(':lt('+(imgindex - 1)+')').appendTo('#slider ul');
					$ul_slider.children(':lt('+(imgindex - 2)+')').appendTo('#slider ul');
					$ul_slider.css('margin-left',_val.marLeft);
					_count.current = pindex;
					_fnc.callback();
			});
			
		}else if(imgindex == 0){
			$ul_slider.filter(':not(:animated)').stop(true,false).animate({
			},0,
			function(){
				$ul_slider.children(':last').prependTo('#slider ul');
				$ul_slider.css('margin-left',parseInt($ul_slider.css('margin-left')) - distance);
				$ul_slider.filter(':not(animated)').stop(true,false).animate({
					marginLeft : _val.marLeft
				},_o.speed,_o.easing,
				function(){
					_count.current = pindex;
					_fnc.callback();
				});
			});
		}else{
			$ul_slider.filter(':not(animated)').stop(true,false).animate({
				marginLeft : parseInt($ul_slider.css('margin-left')) - distance
			},_o.speed,_o.easing,
			function(){
				$ul_slider.children(':lt('+(imgindex - 1)+')').appendTo('#slider ul');
				$ul_slider.css('margin-left',_val.marLeft);
				_count.current = pindex;
				_fnc.callback();
			});
		}
	}
});*/
});
//-->
