<?php

	define("MAX_PAGES", 4);
	define("CEATEC_TITLE1", "SONY、Panasonic、SANYO、SHARP 編");			//	1 to 47
	define("CEATEC_TITLE2", "MITSUBISHI、Victor、TOSHIBA、HITACHI 編");		//	48 to 83
	define("CEATEC_TITLE3", "Pioneer、BOSE、SED方式薄型ディスプレイ、NTT ほか 編");	//	84 to 110
	define("CEATEC_TITLE4", "キレイなお姉さん 編");									//	111 to 138

	mb_http_output("EUC-JP");

	array_key_exists("p", $_GET) ? $p = intval($_GET["p"]) : $p = 1;
	if($p < 1 || MAX_PAGES < $p)
	{
		$p = 1;
	}

	switch($p)
	{
		case 1:
			$title = CEATEC_TITLE1;
			$start = 1;
			$end   = 47;
			break;
		case 2:
			$title = CEATEC_TITLE2;
			$start = 48;
			$end   = 84;
			break;
		case 3:
			$title = CEATEC_TITLE3;
			$start = 84;
			$end   = 110;
			break;
		case 4:
			$title = CEATEC_TITLE4;
			$start = 111;
			$end   = 138;
			break;
	}


function printalbum($start, $end)
{
	$currentcols = 0;
	$maxrows = 4;
	$maxcols = ($end - $start + 1 + $maxrows) / $maxrows;
	$tablebody = NULL;

	while($currentcols < $maxcols-1)
	{
		$temp = NULL;

		for($i=0; $i<4; $i++)
		{
			$current = $start + $i + ($currentcols * $maxrows);

			if($current <= $end)
			{
				$data = getdata($current);
				$temp .= "<td style=\"border: 1px solid #666666;\" onMouseOver=\"this.style.backgroundColor='#dddddd';\" onMouseOut=\"this.style.backgroundColor='#ffffff';\">".$data."</td>\n";
			}
			else
			{
				$temp .= "<td>&nbsp;</td>\n";
			}
		}

		$tablebody .= "<tr align=\"center\" valign=\"middle\">".$temp."</tr>\n";

		$currentcols++;
	}

	echo <<<EOF
<table width="800" border="0" cellspacing="10" cellpadding="10" style="border:1px solid #666666;">
{$tablebody}
</table>

EOF;

}



function getdata($id)
{
	$img = sprintf("images/s%03d.jpg", $id);
	$img_local = sprintf("./images/s%03d.jpg", $id);

	$width  = 160;
	$height = 120;
	// 該当イメージが存在するとき
	if(file_exists($img_local))
	{
		// イメージの幅と高さを取得
		$ImageArray = getimagesize($img_local);
		$width  = $ImageArray[0];
		$height = $ImageArray[1];
	}

	return sprintf(
		"<a href=\"view.php?id=%d\"".
		" onClick=\"view(this.href); return false;\">".
		"<img src=\"%s\" border=\"%d\" width=\"%d\" height=\"%d\">".
		"</a>",
		$id,
		$img,
		0,
		$width,
		$height);
}



function printfooter($p)
{
	switch($p)
	{
		case 1:
			$back = NULL;
			$next = 2;
			break;
		case 2:
			$back = 1;
			$next = 3;
			break;
		case 3:
			$back = 2;
			$next = 4;
			break;
		case 4:
			$back = 3;
			$next = NULL;
			break;
	}

	$strback = "&nbsp;";
	if($back != NULL)
	{
		switch($back)
		{
			case 1:
				$backtitle = CEATEC_TITLE1;
				break;
			case 2:
				$backtitle = CEATEC_TITLE2;
				break;
			case 3:
				$backtitle = CEATEC_TITLE3;
				break;
			case 4:
				$backtitle = CEATEC_TITLE4;
				break;
		}
		$strback = sprintf("<a href=\"list.php?p=%d\">&lt;&lt; %s</a>", $back, $backtitle);
	}

	$strnext = "&nbsp;";
	if($next != NULL)
	{
		switch($next)
		{
			case 1:
				$nexttitle = CEATEC_TITLE1;
				break;
			case 2:
				$nexttitle = CEATEC_TITLE2;
				break;
			case 3:
				$nexttitle = CEATEC_TITLE3;
				break;
			case 4:
				$nexttitle = CEATEC_TITLE4;
				break;
		}
		$strnext = sprintf("<a href=\"list.php?p=%d\">%s &gt;&gt;</a>", $next, $nexttitle);
	}

	echo <<<EOF
<table width="800" border="0">
<tr style="font-size:8pt; font-weight:bold;">
	<td align="left">{$strback}</td>
	<td align="right">{$strnext}</td>
</tr>
</table>

EOF;

}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
	<meta name="Author" content="spanstyle.com">
	<title><?php echo $title ?></title>
	<meta name="description" content="CEATEC 写真集">
	<meta name="keywords" content="CEATEC,写真,動画">

	<style type="text/css">
	a {
		text-decoration:none;
	}

	a:hover, a:active {
		text-decoration:underline;
	}
	</style>

	<script language="javascript"><!--
		function view(url)
		{
			window.open(url, 'viewer', 'width=550, height=535');
		}
	//--></script>

</head>

<body style="margin:20px 10px; padding:0px;">

<div style="width:800px;">

<h1 style="margin-top:5px; margin-bottom:5px; font-size:14pt; font-weight:bold; text-align:center"><?php echo $title?></h1>


<div style="height=30px;">&nbsp;</div>

<?php printfooter($p)?>

<div class="left" style="margin:5px 0px; font-size:8pt;">※画像をクリックすると拡大します。</div>

<?php printalbum($start, $end)?>

<?php printfooter($p)?>

</div>

</body>

</html>
