(function($) {  
	$(function(){  
		var _imgNum = 0;    //画像の枚数  
		var _imgSize = 0;   //画像のサイズ  
		var _current = 0;   //現在の画像  
		var _timer = 5000;  //タイマー時間
		var _altText;    //画像のAltテキスト

		//各ボタンの配置  
		$('#container-top').append('<div id="pagenation-top"><ul></ul></div>');  

		//画像サイズ取得  
		_imgSize = $('#banner-top div.box-top div').height();  

		//メイン画像の数だけ繰り返す  
		$('#banner-top div.box-top div').each(function(){  

			//画像をずらして外に配置  
			$(this).css('margin-top', -_imgSize);

			//divのidを割り振り

			//画像の数だけページネーションボタンを作成  
			if (_imgNum == _current) {  

				//currentだったらアクティブ、メインの画像は表示  
				
				$(this).css('margin-top', '0px');  
			}

			//画像の数だけページネーションボタンを作成
			_altText=$(this).attr('title');
			if (_imgNum == _current) {  

				//currentだったらアクティブ、メインの画像は表示
				$('#pagenation-top ul').append('<li class="active"><a href="#banner'+ _imgNum +'">'+_altText+'</a></li>');  
				$(this).css('margin-left', '0px');  
			} else {  
				$('#pagenation-top ul').append('<li><a href="#banner'+ _imgNum +'">'+_altText+'</a></li>');  
			}

			//ループの数をカウントして_imgNumに入れる  
			_imgNum++;  
		});

		//ページネーションクリック  
		$('#pagenation-top ul li').click(function() {  
			var thisNum = $('#pagenation-top li').index(this);  

			//押したボタンが現在の画像じゃなかったら実行  
			if(thisNum  != _current) {  
				imageMove(thisNum );  
			}
		});

		//一定時間ごとにimageMoveを実行  
		setInterval(function(){  
			imageMove(_current +1);  
		}, _timer);  
		function imageMove(next) {  
		
		//次の画像が次の画像より多きかったら右に配置（小さかったら左）
		var pos;
		if (_current < next) {
			pos = -_imgSize;
		} else {
			pos = _imgSize;
		}

		//次の画像が最後なら1枚目、１枚目なら最後
		if (next == _imgNum) {
			next = 0;
		} else if(next == -1) {
			next = (_imgNum-1);
		}

		//次の画像を動かす
		$("#banner-top div.box-top div").eq(next)

		//次の画像を次の位置に配置
		.css("margin-top", pos)
		.animate({marginTop: "0"},"slow");

		//現在の画像を動かす
		$("#banner-top div.box-top div").eq(_current)
		.animate({marginTop: -pos},"slow");

		//ページネーション現在のを消し次のをアクティブに  
		$('#pagenation-top li').eq(_current).removeClass('active');
		$('#pagenation-top li').eq(next).addClass('active');  

		//現在の番号を次の番号にする。  
		_current = next;
	}
});
})(jQuery);
