<?php
include("includes/site_info.php");
include_once __INCLUDE_CLASS_PATH."/class.Picture.php";
$picture = new Picture();

$VUserID = $_REQUEST['VUserID'];
$WUsername = $_REQUEST['VUserNAME'];

if ($_REQUEST['gid']) { $gid = $_REQUEST['gid']; }
else { $gid = 0; }
if ($_REQUEST['pid']) { $pid = $_REQUEST['pid']; }
else { $pid = 0; }
$prev_id = mysql_fetch_object(mysql_query("SELECT * FROM galleryitem WHERE Gallery_ID = '$gid' and GalleryItem_ID < '$pid' ORDER BY GalleryItem_ID ASC LIMIT 1"));
$next_id = mysql_fetch_object(mysql_query("SELECT * FROM galleryitem WHERE Gallery_ID = '$gid' and GalleryItem_ID > '$pid' ORDER BY GalleryItem_ID ASC LIMIT 1"));
$galleryitem_query=mysql_query("SELECT * FROM galleryitem WHERE GalleryItem_ID = '$pid' and  Gallery_ID = '$gid'") or die(mysql_error());
$galleryitem_TOTAL = mysql_num_rows($galleryitem_query);
$gallery_TOTAL = mysql_num_rows(mysql_query("SELECT * FROM galleryitem WHERE Gallery_ID = '$gid'"));

$gallerymain_query=mysql_query("SELECT Name FROM gallery WHERE mem_id = '$VUserID' and Gallery_ID = '$gid' AND Level='Public'") or die(mysql_error());
$gallerymain_TOTAL = mysql_num_rows($gallerymain_query);
if ($gallerymain_TOTAL >0) {
	$gallerymain=mysql_fetch_object($gallerymain_query) or die(mysql_error());
} else {
?>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
      <tr>
          <td align="center"><div class="padding_10">Can't find a photo to view.</div></td>
        </tr>
      </table></td>
  </tr>
</table>
<?php
	die;
}
?>
	<div class="pop_box">
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="5" class="white_back_t_xb">
<?php if ($galleryitem_TOTAL > 0){ 
		while ($gallery = mysql_fetch_object($galleryitem_query) ) {
		$pg = mysql_result(mysql_query("SELECT COUNT(Gallery_ID) FROM galleryitem WHERE GalleryItem_ID <= '$gallery->GalleryItem_ID' and Gallery_ID = '$gid'"),0) or die(mysql_error());
?>
            <tr class="lightgrey_10">
              <td align="center">Photo <?=$pg?> of <?=$gallery_TOTAL?> </td>
            </tr>
            <tr class="solid_line_separator">
              <td>
          <div align="center" class="padding_10 grey_10 style_left">
                <div>
				<?php if ($next_id) { 
				?>
				<img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($next_id->GalleryItem_ID)?>.<?=$next_id->ext?>" width="0" border="0">
				<a href="javascript: void(null)" title="<?=$gallerymain->Name?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/myprofile_gallery.php?VUserID=<?=$VUserID?>&VUserNAME=<?=$WUsername?>&gid=<?=$gallery->Gallery_ID?>&pid=<?=$next_id->GalleryItem_ID?>'}, this.title, 'gallery'); return false;" rel="facebox"><img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($gallery->GalleryItem_ID)?>.<?=$gallery->ext?>" class="img_b_p3" border="0"></a>
				<?php } elseif ($prev_id) { 
				?>
				<img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($prev_id->GalleryItem_ID)?>.<?=$prev_id->ext?>" width="0" border="0">
				<a href="javascript: void(null)" title="<?=$gallerymain->Name?>" onclick="javascript: jQuery.facebox({ajax:'<?=$CONST_LINK_ROOT?>/myprofile_gallery.php?VUserID=<?=$VUserID?>&VUserNAME=<?=$WUsername?>&gid=<?=$gallery->Gallery_ID?>&pid=<?=$prev_id->GalleryItem_ID?>'}, this.title, 'gallery'); return false;" rel="facebox"><img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($gallery->GalleryItem_ID)?>.<?=$gallery->ext?>" class="img_b_p3" border="0"></a>
				<?php } else { 
				?>
				<img src="<?=$SITE_MAIN_WWW_ROOT?>/members/<?=$WUsername?>/gallery/<?=md5($gallery->GalleryItem_ID)?>.<?=$gallery->ext?>" class="img_b_p3" border="0">
				<?php } ?>
				<br />
						  			  <?php 
			  if ($gallery->Description) { 
			  echo "<span class=\"line_height20 left\">";
			  echo nl2br($gallery->Description);
			  echo "<br />";
			  echo "</span>";
              } 
			  ?>
</div>
            </div>
             </td>
            </tr>
		  <?php }
		  } else {
?>
            <tr class="solid_line_separator">
          <td align="center"><div class="padding_10">Can't find a photo to view.</div></td>
        </tr>
<?php
	die;
}
?>
            <tr>
              <td>&nbsp;</td>
            </tr>
          </table></td>
  </tr>
</table>
</div>