// ▼ Top Topics制御
$(document).ready(function(){

	// ▼ Topics数
	var itemsPerPage = 3;
	var numOfItems;
	var activeItem = 0;
	var items = $(".CollapsiblePanel");
	items.each(function(){
		var id = this.id.split("_");
		id = id[1];
		if(id >= itemsPerPage)
		{
			this.style.display='none';
		}
		else
		{
			this.style.display='block';
		}
		numOfItems = id;
	});

	$("#nextbtn").bind("click",function(){
		activeItem = activeItem + itemsPerPage;
		if(activeItem > numOfItems)
		{
			activeItem = numOfItems;
		}
		$("#topic").hide();
		items.each(function(){
			var id = this.id.split("_");
			id = id[1];
			if(id >= activeItem && id < activeItem+itemsPerPage)
			{
				$(this).show();
			}
			else
			{
				$(this).hide();
			}
		});
		$("#topic").fadeIn();
		showHideBtn();
		return false;
	});

	$("#backbtn").bind("click",function(){
		activeItem = activeItem - itemsPerPage;
		if(activeItem <= 0)
		{
			activeItem = 0;
		}
		$("#topic").hide();
		items.each(function(){
			var id = this.id.split("_");
			id = id[1];
			if(id >= activeItem && id < activeItem+itemsPerPage)
			{
				$(this).show();
			}
			else
			{
				$(this).hide();
			}
		});
		$("#topic").fadeIn();
		showHideBtn();
		return false;
	});

	$(".topicsopen").click(function() {
		var id = this.id.split("_");
		id = id[2];
		if($("#morecont_" + id).is(":hidden")){
			$("#morecont_" + id).slideDown("slow");
			$("#more_link_" + id).text("閉じる");
		}else{
			$("#morecont_" + id).slideUp();
			$("#more_link_" + id).text("続きを読む");
		}
		showHideBtn();
		return false;
	});

	function showHideBtn()
	{
		if(activeItem - itemsPerPage +1 <= 0)
		{
			$("#backbtn").hide();
		}
		else
		{
			$("#backbtn").show();
		}
		if(activeItem + itemsPerPage -1 >= numOfItems)
		{
			$("#nextbtn").hide();
		}
		else
		{
			$("#nextbtn").show();
		}
	}

	showHideBtn();

	$("a[@rel*=lightbox]").lightBox();

});