<?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_SWINGING_BACKGROUND")) {
		define("photo_SWINGING_BACKGROUND", 'background-image: url("../draw/ghostwriter/css/texture/kabe_getto.jpg");');
	}
	if (!defined("photo_SWINGING_TIME")) {
		define("photo_SWINGING_TIME", '2s');
	}
	if (!defined("photo_SWINGING_ROTATE")) {
		define("photo_SWINGING_ROTATE", '3deg');
	}
?>
<!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_SWINGING_BACKGROUND ?>}
#wrapper {
	min-height: 100%;
	height: auto !important;
	height: 100%;
	margin: 0 auto -30px;
}
#footer {
	height: 30px;
	text-align: center;
}
#page {
	font-size: 12px;
	color: #606060;
}
</style>
<style>
/*	Powered by http://jsfiddle.net/codepo8/MXq9x/		*/
#swing {
	-moz-animation: swing linear <?= photo_SWINGING_TIME ?> infinite;
	-moz-transform-origin: center -20px 0;
	-webkit-animation: swing linear <?= photo_SWINGING_TIME ?> infinite;
	-webkit-transform-origin: center -20px 0;
	-ms-animation: swing linear 20s infinite;
	-ms-transform-origin: center -20px 0;
	-o-animation: swing linear 20s infinite;
	-o-transform-origin:center -20px 0;
	animation: swing 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: 30px;
}
#swing img {
	border: 5px solid #f8f8f8;
	z-index: 2;
	display: block;
}
#swing:after{
	content: '';
	border: 1px solid #999;
	top: -10px;
	z-index: 0;
	left: 50%;
	width: 20px;
	height: 20px;
	border-bottom: none;
	border-right: none;
	-moz-transform: rotate(45deg);
	-webkit-transform: rotate(45deg);
	-ms-transform: rotate(45deg);
	-o-transform: rotate(45deg);
	transform: rotate(45deg);
	position: absolute;
}
/*
#swing:before{
	content: '';
	top: -14px;
	z-index: 5;
	left: 52%;
	width: 5px;
	border-radius: 50% 50%;
	background: #000;
	height: 5px;
	position: absolute;
}
*/
<?	$rotate = photo_SWINGING_ROTATE ?>
@-moz-keyframes swing {
	0% { -moz-transform: rotate(0deg) }
	25% { -moz-transform: rotate(<?= $rotate ?>); }
	50% { -moz-transform: rotate(0deg); }
	75% { -moz-transform: rotate(-<?= $rotate ?>); }
	100% { -moz-transform: rotate(0deg); }
}
@-webkit-keyframes swing {
	0% { -webkit-transform: rotate(0deg); }
	25% { -webkit-transform: rotate(<?= $rotate ?>); }
	50% { -webkit-transform: rotate(0deg); }
	75% { -webkit-transform: rotate(-<?= $rotate ?>); }
	100% { -webkit-transform: rotate(0deg); }
}
@-o-keyframes swing {
	0% { -o-transform: rotate(0deg); }
	25% { -o-transform: rotate(<?= $rotate ?>); }
	50% { -o-transform: rotate(0deg); }
	75% { -o-transform: rotate(-<?= $rotate ?>); }
	100% { -o-transform: rotate(0deg); }
}
@-ms-keyframes swing {
	0% { -ms-transform: rotate(0deg); }
	25% { -ms-transform: rotate(<?= $rotate ?>); }
	50% { -ms-transform: rotate(0deg); }
	75% { -ms-transform: rotate(-<?= $rotate ?>); }
	100% { -ms-transform: rotate(0deg); }
}
@keyframes swing {
	0% { transform: rotate(0deg); }
	25% { transform: rotate(<?= $rotate ?>); }
	50% { transform: rotate(0deg); }
	75% { transform: rotate(-<?= $rotate ?>); }
	100% { transform: rotate(0deg); }
}
</style>
<script src="../scripts/jquery.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;
		$('#swing').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 == 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="wrapper">
<figure id="swing"><img id="img" src="<?= $getimg ?>"></figure>
</div>
<div id="footer">
<span id="page"><span id="current_page"><?= $page ?></span> / <?= $_SESSION['photo_img_count'] ?></span>
</div>
</body>
</html>
