<?php
	require("__include-common.php");
	require("../account/__logincheck.php");
	if ($_SESSION['photo_open_path'] == '') {
		header("Location: index.php");
	}
	if (empty($_SESSION['photo'])) {
		header("Location: index.php");
	}
	if (empty($_SESSION['photo_img_count'])) {
		header("Location: index.php");
	}
	if ($_SESSION['photo_img_count'] < 1) {
		header("Location: index.php");
	}
	$open_path = $_SESSION['photo_open_path'];
	if (defined("photo_LIMITED_IMAGES_FOLDER") and photo_LIMITED_IMAGES_FOLDER <> '') {
		if ($_SESSION['システム管理者'] <> 'YES' or photo_LIMITED_ADMIN_NOLIMIT <> 'YES') {
			$len = strlen(photo_LIMITED_IMAGES_FOLDER);
			if (substr($open_path.'/', 0, $len+1) <> photo_LIMITED_IMAGES_FOLDER.'/') {
				header("Location: index.php");
			}
		}
	}
	if ($_GET['page'].'' <> '') {
		$page = intval($_GET['page']);
		if ($page < 1) {
			$page = 1;
		}
	} else {
		$page = 1;
	}
	$filename = $_SESSION['photo'][$page-1]['file'];
	$filepath = $open_path.'/'.$filename;
	if ($_SESSION['photo'][$page-1]['type'] == 'video' and photo_VIDEO_FFMPEG == 'YES' and $_SESSION['slide_flv_preview'] == 'on' and $slidemode <> 'ajax') {
		// 動画の再生時間を取得 (ffmpegのstderrを利用)
		$ret = shell_exec('ffmpeg -i "'.myfile_ENCODE($filepath).'" 2>&1');
		$time = trim(get_intag($ret, 'duration:', ',', $pos=0));
		$time_ar = explode(":", $time);
		$interval_time = (int)$time_ar[0]*3600+(int)$time_ar[1]*60+(int)$time_ar[2] + 2;
	} else {
		$interval_time = $_COOKIE['slide_interval_time'];
	}
	$add_meta = '';
	if ($_SESSION['slide_fullview_auto'] == 'on' and $slidemode <> 'ajax') {
		if ($page < ceil($_SESSION['photo_img_count'])) {
			$add_meta = '<meta http-equiv="refresh" content="'.$interval_time.';';
			$add_meta .= 'url='.$_SERVER['SCRIPT_NAME'].'?page='.strval($page+1);
			$add_meta .= '&mode=s&slidemode='.$slidemode.'">';
		} elseif ($_SESSION['slide_view_repeat'] == 'on') {
			$add_meta = '<meta http-equiv="refresh" content="'.$interval_time.';';
			$add_meta .= 'url='.$_SERVER['SCRIPT_NAME'].'?page=1';
			$add_meta .= '&mode=s&slidemode='.$slidemode.'">';
		}
	}
	if (VIDEO_PREVIEW == 'YES' && $_SESSION['slide_flv_preview'] == 'on' && $slidemode <> 'ajax' && is_preview_video_filename($filename) && is_ext_filename_str($filename, VIDEO_PREVIEW_CONVERT)) {
		$filepath = $open_path.'/'.$filename.'.flv';	// JWPlayerは拡張子が.flvでないと駄目なため
	} else {
		$filepath = $open_path.'/'.$filename;
	}
	$filepath_url = urlencode($filepath);
	if ($_SESSION['photo'][$page-1]['type'] == 'video') {
		$getimg = "video-jpeg.php?file=".$filepath_url."&ss=".$_SESSION['video_thumb_ss'];
	} else {
		$getimg = "img-view.php?img=".$filepath_url;
	}
	if ($page > 1) {
		$move_prev = $page - 1;
	} else {
		if ($_SESSION['slide_view_repeat'] == 'on') { 
			$move_prev = $_SESSION['photo_img_count'];
		} else {
			$move_prev = $page;
		}
	}
	if ($page < $_SESSION['photo_img_count']) {
		$move_next = $page + 1;
	} else {
		if ($_SESSION['slide_view_repeat'] == 'on') { 
			$move_next = 1;
		} else {
			$move_next = $page;
		}
	}
	if ($page + SLIDE_SMALL_NUM < $_SESSION['photo_img_count']) {
		$skip_next = $page + SLIDE_SMALL_NUM;
	} else {
		$skip_next = $_SESSION['photo_img_count'];
	}
	if ($page - SLIDE_SMALL_NUM > 1) {
		$skip_back = $page - SLIDE_SMALL_NUM;
	} else {
		$skip_back = 1;
	}
	if (!defined("photo_ZOOMINOUT_BACKGROUND")) {
		define("photo_ZOOMINOUT_BACKGROUND", 'background-image: url("../draw/ghostwriter/css/texture/kabe_getto.jpg");');
	}
	if (!defined("photo_ZOOMINOUT_RATIO")) {
		define("photo_ZOOMINOUT_RATIO", '50');
	}
	if (!defined("photo_ZOOMINOUT_TIME")) {
		define("photo_ZOOMINOUT_TIME", '5');
	}
	if (!defined("photo_ZOOMINOUT_FIRST")) {
		define("photo_ZOOMINOUT_FIRST", '1');
	}
	if (!defined("photo_ZOOMINOUT_END")) {
		define("photo_ZOOMINOUT_END", '1.05');
	}
	if ($_GET['ratio'].'' <> '') {
		$ratio = $_GET['ratio'];
		setcookie('photo_zoom_inout_ratio', $ratio);
	} elseif ($_COOKIE['photo_zoom_inout_ratio'].'' <> '') {
		$ratio = $_COOKIE['photo_zoom_inout_ratio'];
	} else {
		$ratio = photo_ZOOMINOUT_RATIO;
	}
	if ($_GET['time'].'' <> '') {
		$time = $_GET['time'];
		setcookie('photo_zoom_inout_time', $time);
	} elseif ($_COOKIE['photo_zoom_inout_time'].'' <> '') {
		$time = $_COOKIE['photo_zoom_inout_time'];
	} else {
		$time = photo_ZOOMINOUT_TIME;
	}
	if ($_GET['first'].'' <> '') {
		$first = $_GET['first'];
		setcookie('photo_zoom_inout_first', $first);
	} elseif ($_COOKIE['photo_zoom_inout_first'].'' <> '') {
		$first = $_COOKIE['photo_zoom_inout_first'];
	} else {
		$first = photo_ZOOMINOUT_FIRST;
	}
	if ($_GET['end'].'' <> '') {
		$end = $_GET['end'];
		setcookie('photo_zoom_inout_end', $end);
	} elseif ($_COOKIE['photo_zoom_inout_end'].'' <> '') {
		$end = $_COOKIE['photo_zoom_inout_end'];
	} else {
		$end = photo_ZOOMINOUT_END;
	}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="author" content="ok.2nd">
<title>拡大縮小</title>
<style>
html, body {
	height: 100%;
	overflow: hidden;
}
body {<?= photo_ZOOMINOUT_BACKGROUND ?>}
#header {
	margin: 0 0 0 0;
	text-align: center;
	font-size: 12px;
	color: #606060;
	height: 18px;
	padding: 0;
}
#main {
	clear: both;
}
</style>
<style>
#zoominout {
	-moz-animation: zoominout linear <?= $time ?>s infinite;
	-moz-transform-origin: center -20px 0;
	-webkit-animation: zoominout linear <?= $time ?>s infinite;
	-webkit-transform-origin: center -20px 0;
	-ms-animation: zoominout linear 20s infinite;
	-ms-transform-origin: center -20px 0;
	-o-animation: zoominout linear 20s infinite;
	-o-transform-origin:center -20px 0;
	animation: zoominout linear 20s infinite;
	transform-origin: center -20px 0;
	display: block;
	float: left;
	box-shadow: 5px 5px 10px rgba(0,0,0,0.5);
	margin-top: 10px;
}
#zoominout img {
	border: 5px solid #f8f8f8;
	z-index: 2;
	display: block;
}
@-webkit-keyframes zoominout {
	0% { -webkit-transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
	<?= $ratio ?>% { -webkit-transform: scale3d(<?= $end ?>, <?= $end ?>, <?= $end ?>); }
	100% { -webkit-transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
}
@-moz-keyframes zoominout {
	0% { -moz-transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
	<?= $ratio ?>% { -moz-transform: scale3d(<?= $end ?>, <?= $end ?>, <?= $end ?>); }
	100% { -moz-transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
}
@-o-keyframes zoominout {
	0% { -o-transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
	<?= $ratio ?>% { -o-transform: scale3d(<?= $end ?>, <?= $end ?>, <?= $end ?>); }
	100% { -o-transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
}
@-ms-keyframes zoominout {
	0% { -ms-transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
	<?= $ratio ?>% { -ms-transform: scale3d(<?= $end ?>, <?= $end ?>, <?= $end ?>); }
	100% { -ms-transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
}
@keyframes zoominout {
	0% { transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
	<?= $ratio ?>% { transform: scale3d(<?= $end ?>, <?= $end ?>, <?= $end ?>); }
	100% { transform: scale3d(<?= $first ?>, <?= $first ?>, <?= $first ?>) }
}
</style>
<script src="../scripts/jquery.js"></script>
<script src="../scripts/jquery.cookie.js"></script>
<script>
$(window).load(function(){	// 画像もすべて読み込まれた後
//	var w_width = screen.availWidth - 100;
//	var w_height = screen.availHeight - 200;
	var w_width = window.innerWidth - 120;
	var w_height = window.innerHeight - 100;
	var img = new Image();
	img.src = $('#img').attr('src');
	var i_width  = img.width;
	var i_height = img.height;
	if (i_width/i_height > w_width/w_height) {	// 横にかなり長い画像
		$('#img').css('width', w_width+'px');
	} else {
		$('#img').css('height', w_height+'px');
		v_width = i_width * w_height / i_height;
		left_margin = Math.floor((w_width - v_width) / 2) + 30;
		$('#zoominout').css('margin-left', left_margin+'px');
	}
});
document.onkeydown = keyPress;
function keyPress( e ) {
	// IEでは e は未定義
	// 第一引数の e が未定義なら、window.event を使う。
	// by http://d.hatena.ne.jp/language_and_engineering/20081124/1227474876
	e = e || window.event;
	//alert( "キーコード：" + e.keyCode );
	if (e.keyCode == 27) {	// Esc
		window.close();
	} else if (e.keyCode == 37 || e.keyCode == 100 || e.keyCode == 33 || e.keyCode == 29) {	// ←, Page Up, 無変換 ：Page Prev
		window.location.href = "?page=<?= $move_prev ?>";
	} else if (e.keyCode == 39 || e.keyCode == 102 || e.keyCode == 34) {	// →, Page Down ：Page Next
		window.location.href = "?page=<?= $move_next ?>";
	} else if (e.keyCode == 13 || e.keyCode == 32 || e.keyCode == 229) {	// Enter, Space (229:日本語モード) ：Page Next
		window.location.href = "?page=<?= $move_next ?>";
	} else if (e.keyCode == 9 ) {					// Tab ：Page Skip(10)
		window.location.href = "?page=<?= $skip_next ?>";
	} else if (e.keyCode == 17 ) {					// Ctrl ：Page Skip(10) Back
		window.location.href = "?page=<?= $skip_back ?>";
	} else if (e.keyCode == 36) {					// Home ：Page Top
		window.location.href = "?page=1";
	} else if (e.keyCode == 35) {					// End ：Page Last
		window.location.href = "?page=<?= $_SESSION['photo_img_count'] ?>";
	} else if (e.keyCode == 122) {					// F11 ：全画面
		window.location.href = "?page=<?= $page ?>";		// リロード
		return true;
	} else {					// その他 (ファンクションキーなどを有効にするため)
		return true;
	}
	return false;
}
</script>
</head>
<body>
<div id="header">
<span id="page"><span id="current_page"><?= $page ?></span> / <?= $_SESSION['photo_img_count'] ?></span>
<span style="margin-left:5px;">Large Time (%):
<select id="ratio" onchange="Selection('ratio')">
<?	for ($i=5; $i<=95; $i+=5) { ?>
	<option value="<?= $i ?>"<?= $i.'' == $ratio ? ' selected' : '' ?>><?= $i ?>%
<?	} ?>
</select>
<span style="margin-left:5px;">Time:
<select id="time" onchange="Selection('time')">
<?	for ($i=0.1; $i<=0.9; $i+=0.1) { ?>
	<option value="<?= $i ?>"<?= $i.'' == $time ? ' selected' : '' ?>><?= $i ?>
<?	} ?>
<?	for ($i=1; $i<=10; $i++) { ?>
	<option value="<?= $i ?>"<?= $i.'' == $time ? ' selected' : '' ?>><?= $i ?>
<?	} ?>
<?	for ($i=20; $i<=240; $i+=20) { ?>
	<option value="<?= $i ?>"<?= $i.'' == $time ? ' selected' : '' ?>><?= $i ?>
<?	} ?>
</select>
</span>
<span style="margin-left:5px;">First Scale:
<select id="first" onchange="Selection('first')">
<?	for ($i=0.0; $i<1.0; $i+=0.1) { ?>
	<option value="<?= $i ?>"<?= $i.'' == $first ? ' selected' : '' ?>><?= $i ?>
<?	} ?>
</select>
<span style="margin-left:5px;">End Scale:
<select id="end" onchange="Selection('end')">
<?	for ($i=1.0; $i<1.31; $i+=0.01) { ?>
	<option value="<?= $i ?>"<?= $i.'' == $end ? ' selected' : '' ?>><?= $i ?>
<?	} ?>
</select>
</span>
</div>
<div id="main">
<figure id="zoominout"><img id="img" src="<?= $getimg ?>"></figure>
</div>
<script>
function Selection(id) {
	seldata = $("#"+id).val();
	$.cookie('photo_zoom_inout_'+id,seldata,{expires:30,path:'/'});
	window.location.href = "?page="+<?= $_GET['page'] ?>+"&"+id+"="+seldata;
}
function ChangeType(tp) {
	$.cookie('photo_zoom_inout_type',tp,{expires:30,path:'/'});
	window.location.href = "?page="+<?= $_GET['page'] ?>+"&type="+tp;
}
</script>
</body>
</html>
