<?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_TILTSHIFT_BACKGROUND")) {
		define("photo_TILTSHIFT_BACKGROUND", 'background-image: url("../draw/ghostwriter/css/texture/canvas2.jpg");');
	}
	if (!defined("photo_TILTSHIFT_DIRECTION")) {
		define("photo_TILTSHIFT_DIRECTION", 'y');
	}
	if (!defined("photo_TILTSHIFT_POSITION")) {
		define("photo_TILTSHIFT_POSITION", '50');
	}
	if (!defined("photo_TILTSHIFT_BLUR")) {
		define("photo_TILTSHIFT_BLUR", '2');
	}
	if (!defined("photo_TILTSHIFT_FOCUS")) {
		define("photo_TILTSHIFT_FOCUS", '10');
	}
	if (!defined("photo_TILTSHIFT_FALLOFF")) {
		define("photo_TILTSHIFT_FALLOFF", '10');
	}
	if ($_GET['direction'].'' <> '') {
		$direction = $_GET['direction'];
	} elseif ($_COOKIE['photo_tiltshift_direction'].'' <> '') {
		$direction = $_COOKIE['photo_tiltshift_direction'];
	} else {
		$direction = photo_TILTSHIFT_DIRECTION;
	}
	if ($_GET['position'].'' <> '') {
		$position = $_GET['position'];
	} elseif ($_COOKIE['photo_tiltshift_position'].'' <> '') {
		$position = $_COOKIE['photo_tiltshift_position'];
	} else {
		$position = photo_TILTSHIFT_POSITION;
	}
	if ($_GET['blur'].'' <> '') {
		$blur = $_GET['blur'];
	} elseif ($_COOKIE['photo_tiltshift_blur'].'' <> '') {
		$blur = $_COOKIE['photo_tiltshift_blur'];
	} else {
		$blur = photo_TILTSHIFT_BLUR;
	}
	if ($_GET['focus'].'' <> '') {
		$focus = $_GET['focus'];
	} elseif ($_COOKIE['photo_tiltshift_focus'].'' <> '') {
		$focus = $_COOKIE['photo_tiltshift_focus'];
	} else {
		$focus = photo_TILTSHIFT_FOCUS;
	}
	if ($_GET['falloff'].'' <> '') {
		$falloff = $_GET['falloff'];
	} elseif ($_COOKIE['photo_tiltshift_falloff'].'' <> '') {
		$falloff = $_COOKIE['photo_tiltshift_falloff'];
	} else {
		$falloff = photo_TILTSHIFT_FALLOFF;
	}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="author" content="ok.2nd">
<meta name="description" content="Use this jQuery plugin to mimic the popular tilt-shift photography effect.">
<!--
	Powered by "tiltShift.js - a jQuery plugin using CSS3 filters to replicate the tilt shift effect"
	http://www.noeltock.com/tilt-shift-css3-jquery-plugin/
-->
<title>チルトシフト</title>
<style>
html, body {
	height: 100%;
}
body {<?= photo_TILTSHIFT_BACKGROUND ?>}
#header {
	margin: 10px 0 0 10px;
	text-align: left;
	font-size: 12px;
	color: #606060;
}
#main {
	clear: both;
	margin: 10px 0 0 10px;
}
</style>
<link rel="stylesheet" href="../scripts/tiltShift/tiltshift.css">
<link rel="stylesheet" href="../scripts/tiltShift/jquery.tiltShift.css">
<script src="../scripts/jquery-1.8.1.js"></script>
<script src="../scripts/jquery.cookie.js"></script>
<script src="../scripts/tiltShift/jquery.tiltShift.js"></script>
<script>
jQuery(document).ready(function() {
	$('.tiltshift').tiltShift();
});
</script>
<script>
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 == 240 ) {					// Caps Lock ：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">
<?php
	// direction (“x”, “y”, or 0-360), the direction of the effect with zero at right.
	// position (0-100), defines the point of focus. 66 would be two thirds of the way in.
	// blur (0-?), the blur radius in pixels. 1 or 2 are usually good numbers.
	// focus (0-100), the amount of area that is in focus. 10 would mean one tenth of the image is sharp.
	// falloff (0-100), the amount of area between complete focus and complete blur. The lower the value, the “tighter” the fade.
?>
	<span id="page"><span id="current_page"><?= $page ?></span> / <?= $_SESSION['photo_img_count'] ?></span>
	<span style="margin-left:5px;">direction:
		<select id="direction" onchange="Selection('direction')">
			<option value="y"<?= 'y' == $direction ? ' selected' : '' ?>>y
			<option value="x"<?= 'x' == $direction ? ' selected' : '' ?>>x
		<?	for ($i=0; $i<=360; $i+=15) { ?>
			<option value="<?= $i ?>"<?= $i.'' == $direction ? ' selected' : '' ?>><?= $i ?>
		<?	} ?>
		</select>
	</span>
	<span style="margin-left:5px;">position:
		<select id="position" onchange="Selection('position')">
		<?	for ($i=5; $i<=95; $i+=5) { ?>
			<option value="<?= $i ?>"<?= $i.'' == $position ? ' selected' : '' ?>><?= $i ?>
		<?	} ?>
		</select>
	</span>
	<span style="margin-left:5px;">blur:
		<select id="blur" onchange="Selection('blur')">
		<?	for ($i=1; $i<=30; $i++) { ?>
			<option value="<?= $i ?>"<?= $i.'' == $blur ? ' selected' : '' ?>><?= $i ?>
		<?	} ?>
		</select>
	</span>
	<span style="margin-left:5px;">focus:
		<select id="focus" onchange="Selection('focus')">
		<?	for ($i=1; $i<=50; $i++) { ?>
			<option value="<?= $i ?>"<?= $i.'' == $focus ? ' selected' : '' ?>><?= $i ?>
		<?	} ?>
		</select>
	</span>
	<span style="margin-left:5px;">falloff:
		<select id="falloff" onchange="Selection('falloff')">
		<?	for ($i=1; $i<=50; $i++) { ?>
			<option value="<?= $i ?>"<?= $i.'' == $falloff ? ' selected' : '' ?>><?= $i ?>
		<?	} ?>
		</select>
	</span>
</div>
<div id="main" onClick="tiltOnOff()">
	<div class="frame">
		<img id="img" src="<?= $getimg ?>" class="tiltshift" data-position="<?= $position ?>" data-blur="<?= $blur ?>" data-focus="<?= $focus ?>" data-falloff="<?= $falloff ?>" data-direction="<?= $direction ?>">
	</div>
</div>
<script>
function Selection(id) {
	seldata = $("#"+id).val();
	$.cookie('photo_tiltshift_'+id,seldata,{expires:30,path:'/'});
	window.location.href = "?page="+<?= $_GET['page'] ?>+"&"+id+"="+seldata;
}
var tilt_on = true;
function tiltOnOff(id) {
	if (tilt_on) {
		$('.tiltshift-layer').css('opacity', 0);
		tilt_on = false;
	} else {
		$('.tiltshift-layer').css('opacity', 1);
		tilt_on = true;
	}
}
</script>
</body>
</html>
