<?php
	require("__include-common.php");
	require("../account/__logincheck.php");
//	_account_change($_GET['uid']);
	require("__include-session-variable.php");
	html_header(HTML_TITLE, '', photo_BACKGROUND_COLOR);
	page_header(False);		//ログイン表示なし
	contents_header();
	photo_body($open_path, $page);
	html_footer();
	exit();
?>
<?php
function photo_body($open_path, $page) {
?>
<script src="../scripts/JWPlayer/silverlight.js"></script>
<script src="../scripts/JWPlayer/wmvplayer.js"></script>
<script src="../scripts/JWPlayer/swfobject.js"></script>
<script src="../scripts/JWPlayer/movie_preview.js"></script>
<script>
$(function(){
	ajax_view_dir('','',true);
	ajax_view_chgopt('','','');
	ajax_view_photo('','','');
	if ($.cookie("photo_dir_pos") == "left") {
		dirPosLeft();
	} else {
		dirPosTop();
	}
});
function ajax_view_dir_photo(name, val) {
	ajax_view_dir(name, val, true);
	ajax_view_chgopt(name, val, 1);
	ajax_view_photo(name, val, 1);
}
function ajax_view_dir(name, val, sev) {
	data = "get=dir";
	if (sev) {
		data += "&sev=set";
	}
	if (name != "") {
		if (name == "path") {
			val = encodeURIComponent(val);
		}
		data += "&"+name+"="+val;
	}
	if (name == "path") {
		$("#open_path").val(decodeURIComponent(val));
	}
	$.ajax({
		type: "GET",
		url: "ajax-photo-view.php",
		data: data,
		async: false,
		success: function(res){
			if (res == 'permission_error') {
				dir_permission_error();
			} else {
				$("#photo_dir").html(res);
			}
		}
	})
}
function ajax_view_chgopt(name, val, page, sev) {
	data = "get=chgopt";
	if (sev) {
		data += "&sev=set";
	}
	if (name != "") {
		if (name == "path") {
			val = encodeURIComponent(val);
		}
		data += "&"+name+"="+val;
	}
	if (page != "") {
		if (data != "") {
			data += "&";
		}
		data += "page="+page;
	}
	$.ajax({
		type: "GET",
		url: "ajax-photo-view.php",
		data: data,
		async: false,
		success: function(res){
			if (res == 'permission_error') {
				dir_permission_error();
			} else {
				$("#photo_chgopt").html(res);
			}
		}
	})
}
function ajax_view_photo(name, val, page, sev) {
	data = "";
	if (name != "") {
		if (name == "path") {
			val = encodeURIComponent(val);
		}
		data += name+"="+val;
	}
	if (page != "") {
		if (data != "") {
			data += "&";
		}
		data += "page="+page;
	}
	if (sev) {
		sev_set = "&sev=set";
	} else {
		sev_set = "";
	}
	$.ajax({
		type: "GET",
		url: "ajax-photo-view.php",
		data: data+sev_set,
		async: false,
		success: function(res){
			if (res == 'permission_error') {
				dir_permission_error();
			} else {
				$("#photo_main").html(res);
			}
		}
	})
	$.ajax({
		type: "GET",
		url: "ajax-photo-view.php",
		data: "get=header&"+data,
		async: false,
		success: function(res){
			if (res == 'permission_error') {
				dir_permission_error();
			} else {
				$("#photo_header_opt").html(res);
			}
		}
	})
}
function dir_permission_error() {
	$("#photo_header_opt").html('指定フォルダーの表示権限がありません。');
	$("#photo_dir").html('');
	$("#photo_chgopt").html('');
	$("#photo_main").html('');
}
function open_upFolder() {
	upFolder = dirname($("#open_path").val());
	ajax_view_dir_photo("path", upFolder);
}
function open_inputFolder() {
	$("#open_path").val($("#open_path").val().replace(/\\/g,'/'));
	ajax_view_dir_photo("path", $("#open_path").val());
}
function inputKeypress(keyCode) {
	if (keyCode === 13) {
		open_inputFolder();
	}
}
function dirname(path) {
	return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');;
}
function basename(path) {
	return path.replace(/\\/g,'/').replace( /.*\//, '' );
}
function popup_win(url) {
	w01 = window.open(url,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500");
}
</script>
<script>
function dirPosChange() {
	if ($.cookie("photo_dir_pos") == "left") {
		dirPosTop();
		$.cookie("photo_dir_pos","top",{ expires: 365 });
	} else {
		dirPosLeft();
		$.cookie("photo_dir_pos","left",{ expires: 365 });
	}
}
function dirPosLeft() {
	$('#dir_pos_css').attr({href:'<?= _STYLE_SHEET_FOLDER ?>/photo-left.css'});
}
function dirPosTop() {
	$('#dir_pos_css').attr({href:'<?= _STYLE_SHEET_FOLDER ?>/photo-top.css'});
}
function upfolderOff() {
	$("#up_folder_subdir_area").css("display","none");
	$("#up_folder_subdir_on").css("display","");
	$.cookie("photo_up_folder_display","none",{ expires: 365 });
}
function upfolderOn() {
	$("#up_folder_subdir_area").css("display","");
	$("#up_folder_subdir_on").css("display","none");
	$.cookie("photo_up_folder_display","",{ expires: 365 });
}
function page_move(page) {
	ajax_view_chgopt('', '', page, true);
	ajax_view_photo('', '', page);
}
function CheckboxOnOff(name, sel, view) {
	if ($(sel).attr('checked')) {
		val = 'on';
	} else {
		val = 'off';
	}
	if (view == 'dir') {
		ajax_view_dir(name, val, true);
	} else {
		ajax_view_photo(name, val, '', true);
	}
}
function RadioViewMode(mode, page) {
	ajax_view_chgopt('mode', mode, page, true);
	ajax_view_photo('mode', mode, page);
}
</script>
<script>
function slideSizeChange(objid, sel, cookie_name) {
	size = Number($(sel).val());
	$.cookie(cookie_name,size,{ expires: 365 });
	$("img"+objid).height(size);
}
</script>
<script>
function popupImage(filepath, width, height, imgidx) {
	// by http://rgrg.blog61.fc2.com/blog-entry-593.html
	var y = 0;
	var x = 0;
	if (!popupImage.imgNode) {
		if (document.all) {
			y = document.body.scrollTop + 32;
			x = document.body.scrollLeft + 32;
			popupImage.imgNode = document.createElement('img');
			popupImage.imgNode.attachEvent('onclick', closeImage);
		} else if (document.implementation) {
			y = window.pageYOffset + 32;
			x = window.pageXOffset + 32;
			popupImage.imgNode = document.createElement('img');
			popupImage.imgNode.addEventListener('click', closeImage, true);
		} else {
			return;
		}
	}
	with(popupImage) {
		imgNode.setAttribute('src', filepath);
		imgHeight = screen.availHeight - <?= photo_SCREEN_AVAILHEIGHT_SETOFF ?>;
		imgNode.setAttribute('height', imgHeight);
<?php	if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {	// IEはwidthも指定しないと縦横比が崩れる ?>
		if (width == 0) {	// video
			w = $('#'+imgidx).width();
			h = $('#'+imgidx).height();
			imgNode.setAttribute('width', Math.round(imgHeight * w / h));
		} else if (width && height) {
			imgNode.setAttribute('width', Math.round(imgHeight * width / height));
		}
<?php	} ?>
		imgNode.style.position = 'absolute';
		imgNode.style.left = '32px';
		imgNode.style.top = y + 'px';
		imgNode.style.borderColor = '#0099ff';
		imgNode.style.borderWidth = '1px';
		imgNode.style.borderStyle = 'solid';
		imgNode.style.margin = '0';
		document.body.appendChild(imgNode);
	}
	function closeImage() {
		if (popupImage.imgNode) {
			document.body.removeChild(popupImage.imgNode);
			delete popupImage.imgNode;
		}
	}
}
</script>
<div id="photo_body">
	<div id="photo_header">
		<div>
			<input type="button" value="↑" onClick="open_upFolder();">
			<input class="text" type="text" name="path" id="open_path" value="<?= my_htmlspecialchars($open_path) ?>" style="width:400px;" onkeypress="inputKeypress(event.keyCode);">
			<input type="button" value="変更" onClick="open_inputFolder();">
			<span id="photo_chgopt"></span>
		</div>
		<div id="photo_header_opt" style="margin-left:2px;"></div>
	</div>
	<div id="photo_contents">
		<div id="photo_dir" style="float:left; clear:both; overflow-y:visible"></div>
		<div id="photo_main" style="clear: both;"></div>
	</div>
</div>
<?php
}
?>
