<?php 
error_reporting(0);
$sum = file_get_contents('http://image.sitestar.cn/banner/banner_count.php');
$cols = 3;
$rows = 2;
$page = $_GET['page'];
$start_page_number = ($page - 1) * $cols * $rows + 1;
$end_page_number = $page * $cols * $rows;
if(is_float($sum / ($cols * $rows)))
{
	$sum_page = intval($sum / ($cols * $rows)) + 1;
}
elseif(is_int($sum / ($cols * $rows)))
{
	$sum_page = $sum / ($cols * $rows);
}


if($_GET['page'] > $sum_page)
{
	die("页数错误！");
}
elseif(($_GET['page'] == $sum_page) && is_float($sum / ($cols * $rows)))
{
	$end_page_number = $start_page_number - 1 + ($sum % ($cols * $rows));
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../../script/thickbox.css" />
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/thickbox.js"></script>
<style type="text/css">
img {border-color:#DEDEDE;border-style:solid;border-width:2px;}
table {font-size:12px; line-height:30px; margin:10px 0px 0px 15px;}
</style>
<script type="text/javascript">
<!--
function getWidthHeight(src)
{
	$('#'+src).css("border","2px solid #F68B17");
	myImage = new Image();
	myImage.src = "http://image.sitestar.cn/banner/"+src+".png";
	$('#'+src).attr('title','长*宽:'+myImage.width+'*'+myImage.height);
//	alert("width=" + myImage.width);
}
function make_banner1(src)
{
	str = "id=snowPopup&banner_background=http://image.sitestar.cn/banner/"+src;
	myImage = new Image();
	myImage.src = "http://image.sitestar.cn/banner/"+src;
	var param;
	var param1;
	$.ajax({
		   type: "POST",
		   url: "server.php",
		   data: str,
		   beforeSend: function(msg){
			 $('body').append('<img id="wait" style="position:absolute;top:300px;left:500px;z-index:2;" src="images/loadingAnimation.gif"/>');
		   },
		   success: function(msg){
		   	 alert("Banner已选择！");
			 $('#wait').remove();
			 window.parent.tb_remove();
		   },
	   	   error: function(msg){
			 alert(msg);
		   }
		});
}
//-->
</script>
</head>
<body>
	  <table cellspacing="0">
	  <?php 
	  $j = 1;
	  echo "<tr>";
	  for($i = $start_page_number; $i <= $end_page_number; $i++)
	  {
	  		if($j <= $cols)
	  		{
	  			echo "<td style='border-bottom:1px dashed #ccc;height:112px;' width='25%'><div><a rel='pictures' class='thickbox' href='http://image.sitestar.cn/banner/$i.png'><img id='$i' onmouseout='$(this).css(\"border\",\"2px solid #DEDEDE\");' onmouseover='getWidthHeight(\"$i\");' width='225' height='50' src='http://image.sitestar.cn/banner/$i.png'></a></div><span onclick='make_banner1(\"$i.png\");' onmouseout='$(this).css(\"cursor\",\"default\");' onmouseover='$(this).css(\"cursor\",\"pointer\");'><img style='border:none;margin-top:5px;' src='images/select_img.png'/></span></td>";
	  		}
	  		else
	  		{
	  			echo "</tr>";
	  			echo "<tr><td style='border-bottom:1px dashed #ccc;height:112px;' width='25%'><div><a rel='pictures' class='thickbox' href='http://image.sitestar.cn/banner/$i.png'><img id='$i' onmouseout='$(this).css(\"border\",\"2px solid #DEDEDE\");' onmouseover='getWidthHeight(\"$i\");' width='225' height='50' src='http://image.sitestar.cn/banner/$i.png'></a></div><span onclick='make_banner1(\"$i.png\");' onmouseout='$(this).css(\"cursor\",\"default\");' onmouseover='$(this).css(\"cursor\",\"pointer\");'><img style='border:none;margin-top:5px;' src='images/select_img.png'/></span></td>";
	  			$j = 1;
	  		}
	  		$j++;
	  }
	  ?>
	</table>
	<div>
	<?php 
	$banner_message1 = simplexml_load_file('config_banner.xml');
	$size = $banner_message1->banner->tpl_banner;
	$str = '<div style="position:relative;top:11px;">';
	if($size != '')
	{
		$str .= "<span style='position:relative;left:29px;font-size:12px;padding-left:270px;display:block;background:url(\"images/showText.gif\");background-repeat:no-repeat;width:341px;*width:641px; height:13px;'>$size</span>";
	}
	$str .= "<a href='snowPopup.php?page=$sum_page'><img style='border:none;margin:10px 15px 0px 0px;float:right;' src='images/page_last.gif' title='末页'/></a>";
	if($page < $sum_page)
	{
		$next_page = $page + 1;
		$str .= "<a href='snowPopup.php?page=$next_page'><img style='border:none;margin:10px 15px 0px 0px;float:right;' src='images/page_next.gif' title='下一页'/></a>";
	}
	
	if($page > 1)
	{
		$prev_page = $page - 1;
		$str .= "<a href='snowPopup.php?page=$prev_page'><img style='border:none;margin:10px 15px 0px 0px;float:right;' src='images/page_prev.gif' title='上一页'/></a>";
	}
	$str .= "<a href='snowPopup.php?page=1'><img style='border:none;margin:10px 15px 0px 0px;float:right;' src='images/page_first.gif' title='首页'/></a>";
	$str .= "<span style='font-size:12px;position:relative;left:350px;top:8px;'>$page/$sum_page</span>";
	$str .= '</div>';
	echo $str;
	?>
	
	</div>
</body>
</html>