// JavaScript Document

var PAGE_COUNT = 0; // 最大ページ数（とりあえず0で初期化）
$(function() {
	PAGE_COUNT = $(".report").length; // 全部のページ数
	showPage(0); // 0ページ目を表示する

	// ダイアログ関係
	$(".img_thumb").each(function() {
		// ダイアログの定義
		$("#" + this.id + "_dialog").dialog({
			width: 640,
			autoOpen: false,
			resizable: false,
			closeText: '× 閉じる'
		});
	});
	// サムネイルを押したときに、ダイアログを出す
	$(".img_thumb").click(function() {
		$("#"+ this.id + "_dialog").dialog('open');
	});
	// サムネイルのマウスポインタを変える
	$(".img_thumb").css("cursor", "pointer");

});

function showPage(showPageNo, currPageNo) {
	if (showPageNo < 0) {
		showPageNo = 0;
	}
	if (showPageNo > PAGE_COUNT-1) {
		showPageNo = PAGE_COUNT-1;
	}
	

	// 今表示しているページを消す
	$(".report").each(function(count) {
		if (count == currPageNo) {
			$(this).hide();
			/*$(this).animate({opacity: "hide"}, "slow");*/
		}
	});

	
	$(".report").hide(); // まず全部消す
	
	// 表示すべきページを表示する
	$(".report").each(function(count) {
		if (count == showPageNo) {
			$(this).show();
			/*$(this).animate({opacity: "show"}, "slow");*/
		}
	});
	// ナビゲーションを作る
	var navi = "<ul>"; // とりあえず現状のに合わせてみたけどお好みで。
	if (showPageNo > 0) {
		navi += '<li><a class="prevPage" href="#report_top" onclick="showPage('+(showPageNo-1)+', '+showPageNo+')">&lt;&lt;&nbsp;前へ</a></li>';
	}
	if (showPageNo < PAGE_COUNT-1) {
		navi += '<li><a class="nextPage" href="#report_top" onclick="showPage('+(showPageNo+1)+', '+showPageNo+')">次へ&nbsp;&gt;&gt;</a></li>';
	}
	navi += "</ul>";
	$(".pagenav").html(navi);
}

