<?php
	require("__include-common.php");
	require("../account/__logincheck.php");
	html_header('Popup Study', '', '#ffffff');
	main_proc();
	html_footer();
	exit();
function main_proc() {
	$con = my_mysql_connect(_DB_SCHEMA);
	$sql = $_SESSION['study_mycheck_sql'];
	$rs= my_mysql_query($sql);
	$row = mysql_num_rows($rs);
	if ($row == 0) {
		return;
	}
?>
<style>
body {
	margin: 10px;
	background-color: #ffffff;
}
span#page {
	float: left;
	margin-right: 10px;
}
span.page_cnt {
	color: blue;
	font-weight: bold;
}
ul#hide_select {
	float: left;
}
ul#hide_select li {
	display: inline;
}
div#page_control {
	clear: both;
}
</style>
<div id="page_menu">
	<span id="page">
		<span class="page_cnt" id="current_rec">1</span> / <span class="page_cnt"><?= $row ?></span> 件
	</span>
	<ul id="hide_select">
	<li><input id="question_off" type="checkbox"><label for="question_off" class="CheckBoxLabelClass">質問を隠す</label></li>
	<li><input id="answer_off" type="checkbox"><label for="answer_off" class="CheckBoxLabelClass">解答を隠す</label></li>
	</ul>
</div>
<div id="page_control">
	<span id="page_move">
		<button onclick="m_auto_stop();m_first();">←先頭</button>
		<button onclick="m_auto_stop();m_end();">最後→</button>
		<button onclick="m_auto_stop();m_skip_p();">←10</button>
		<button onclick="m_auto_stop();m_skip_n();">10→</button>
		<button onclick="m_auto_stop();m_random();">ランダム</button>
		<br>
		<button id="auto_button" onclick="m_auto();">Auto</button>
		<select id="auto_interval" onChange="intervalChange();">
		<option value="1000">1
		<option value="2000">2
		<option value="3000">3
		<option value="4000">4
		<option value="5000">5
		<option value="6000">6
		<option value="7000">7
		<option value="8000">8
		</select>
		<button onclick="m_auto_stop();m_previous();">←前</button>
		<button onclick="m_auto_stop();m_next();">次→</button>
	</span>
	<span style="padding-left:10px;"><button onclick="view_hidden();">●</button></span>
	<img onclick="menu_hidden();" style="display:inline;padding:5px 0 0 10px;" src="../icon/arrow_left.png">
</div>
<img id="menu_view" onclick="menu_hidden();" style="display:none;" src="../icon/arrow_right.png">
<div id="memo_list">
<?php
	$display = '';
	$ix = 1;
	while ($rec=mysql_fetch_array($rs)) {
?>
	<div id="<?= $ix ?>" style="display:<?= $display ?>">
		<p class="study_mycheck_answer" style="display:;"><?= $rec['c_answer'] ?></p>
		<p class="study_mycheck_question" style="display:;"><?= $rec['c_question'] ?></p>
		<p class="study_mycheck_answer2" style="display:none;"><?= $rec['c_answer'] ?></p>
	</div>
<?php
		$display = 'none';
		$ix++;
	}
?>
</div>
<script>
var menu = true;
function menu_hidden() {
	if (menu) {
		if (!auto) {
			m_auto();
		}
		$("#page_menu").css("display","none");
		$("#page_control").css("display","none");
		$("#menu_view").css("display","");
		menu = false;
	} else {
		$("#page_menu").css("display","");
		$("#page_control").css("display","");
		$("#menu_view").css("display","none");
		menu = true;
	}
}
$(function() {
	if ($.cookie('study_auto_interval')) {
		$("#auto_interval").val($.cookie('study_auto_interval'));
	}
	if ($.cookie('study_pop_display_question') == 'off') {
		$(".study_mycheck_question").css("display","none");
		$("#question_off").attr("checked", true);
	} else if ($.cookie('study_pop_display_answer') == 'off') {
		$(".study_mycheck_answer").css("display","none");
		$("#answer_off").attr("checked", true);
	}
	$("#question_off").click(function() {
		$(".study_mycheck_answer2").css("display","none");
		if (this.checked) {
			$(".study_mycheck_question").css("display","none");
			$(".study_mycheck_answer").css("display","");
			$("#answer_off").attr("checked", "");
			$.cookie('study_pop_display_question','off',{ path:'<?= MY_SESSION_PATH ?>', expires:365 });
			$.cookie('study_pop_display_answer','',{ path:'<?= MY_SESSION_PATH ?>', expires:365 });
		} else {
			$(".study_mycheck_question").css("display","");
			$.cookie('study_pop_display_question','',{ path:'<?= MY_SESSION_PATH ?>', expires:365 });
		}
	});
	$("#answer_off").click(function() {
		$(".study_mycheck_answer2").css("display","none");
		if (this.checked) {
			$(".study_mycheck_answer").css("display","none");
			$(".study_mycheck_question").css("display","");
			$("#question_off").attr("checked", "");
			$.cookie('study_pop_display_answer','off',{ path:'<?= MY_SESSION_PATH ?>', expires:365 });
			$.cookie('study_pop_display_question','',{ path:'<?= MY_SESSION_PATH ?>', expires:365 });
		} else {
			$(".study_mycheck_answer").css("display","");
			$.cookie('study_pop_display_answer','',{ path:'<?= MY_SESSION_PATH ?>', expires:365 });
		}
	});
});
var rec_cnt = <?= $row ?>;
var current_rec = 1;
function m_first() {
	random = false;
	$("#"+current_rec).css("display","none");
	current_rec = 1;
	$("#"+(current_rec)).css("display","");
	$("#current_rec").html(current_rec);
	reset_taiyaku();
}
function m_skip_p() {
	random = false;
	if (current_rec <= 1) return;
	$("#"+current_rec).css("display","none");
	if (current_rec <= 10) {
		current_rec = 1;
	} else {
		current_rec = current_rec - 10;
	}
	$("#"+(current_rec)).css("display","");
	$("#current_rec").html(current_rec);
	reset_taiyaku();
}
function m_previous() {
	random = false;
	if (current_rec <= 1) return;
	$("#"+current_rec).css("display","none");
	$("#"+(--current_rec)).css("display","");
	$("#current_rec").html(current_rec);
	reset_taiyaku();
}
function m_next() {
	random = false;
	$("#"+current_rec).css("display","none");
	if (current_rec >= rec_cnt) {
		current_rec = 0;
	}
	$("#"+(++current_rec)).css("display","");
	$("#current_rec").html(current_rec);
	reset_taiyaku();
}
function m_skip_n() {
	random = false;
	if (current_rec >= rec_cnt) return;
	$("#"+current_rec).css("display","none");
	if (current_rec >= rec_cnt - 10) {
		current_rec = rec_cnt;
	} else {
		current_rec = current_rec + 10;
	}
	$("#"+(current_rec)).css("display","");
	$("#current_rec").html(current_rec);
	reset_taiyaku();
}
function m_end() {
	random = false;
	$("#"+current_rec).css("display","none");
	current_rec = rec_cnt;
	$("#"+(current_rec)).css("display","");
	$("#current_rec").html(current_rec);
	reset_taiyaku();
}
function reset_taiyaku() {
	if ($.cookie('study_pop_display_question') == 'off') {
		$(".study_mycheck_question").css("display","none");
		$("#question_view").attr("checked", "");
	} else if ($.cookie('study_pop_display_answer') == 'off') {
		$(".study_mycheck_answer2").css("display","none");
		$("#answer_view").attr("checked", "");
	}
}
function m_random() {
	random = true;
	$("#"+current_rec).css("display","none");
	current_rec = ransu(1, rec_cnt);
	$("#"+(current_rec)).css("display","");
	$("#current_rec").html(current_rec);
	reset_taiyaku();
}
var auto = false;
var random = false;
var tid1;
var tid2;
function m_auto_skip() {
	if (auto) {
		if (random) {
			m_random();
		} else {
			m_next();
		}
		tid1 = setTimeout('auto_view_question()', $("#auto_interval").val());
	}
}
function auto_view_question() {
	if (auto) {
		if ($.cookie('study_pop_display_question') == 'off') {
			view_question();
		}
		if ($.cookie('study_pop_display_answer') == 'off') {
			view_answer();
		}
		tid2 = setTimeout('m_auto_skip()', $("#auto_interval").val());
	}
}
function m_auto() {
	if (auto) {
		auto = false;
		$("#auto_button").css("background","");
	} else {
		if (!random) {
			current_rec--;
		}
		auto = true;
		$("#auto_button").css("background","#fffacd");
		m_auto_skip();
	}
}
function m_auto_stop() {
	clearTimeout(tid1);
	clearTimeout(tid2);
	auto = false;
	$("#auto_button").css("background","");
}
function view_question() {
	if ($(".study_mycheck_question").css("display") == "none") {
		$(".study_mycheck_question").css("display","");
	} else {
		$(".study_mycheck_question").css("display","none");
	}
}
function view_answer() {
	if ($(".study_mycheck_answer2").css("display") == "none") {
		$(".study_mycheck_answer2").css("display","");
	} else {
		$(".study_mycheck_answer2").css("display","none");
	}
}
function view_hidden() {
	if ($.cookie('study_pop_display_question') == 'off') {
		view_question();
	}
	if ($.cookie('study_pop_display_answer') == 'off') {
		view_answer();
	}
}
function intervalChange() {
	$.cookie('study_auto_interval',$("#auto_interval").val(),{ path:'<?= MY_SESSION_PATH ?>', expires:365 });
}
function ransu(min, max) {
	return min + Math.floor( Math.random() * (max-min+1) );
}
</script>
</body>
</html>
<?php
}
?>
