<?php
require_once("config.php");
require_once("defs.php");
require_once("modules/Gallery.php");
$page=$_GET['page'];
$total=Gallery::countGallery();
if(!$page){ $page=1;}
$PAGESIZE=8;

$numpages=floor($total/$PAGESIZE);
if($total%$PAGESIZE!=0) $numpages++;
require_once("header.php");

require_once("nav.php");
?>
<div id="content">
<div id="gallery_intro">
<span>
<h4>Gallery</h4>
<p>Welcome to the Blackguard gallery. Click on the images and videos below to take a closer look.</p>
</span>
</div>
<?php require_once("gallery_search_box.php");?>

<div id="gallery">
	<?php $items=Gallery::getGalleryPage($page);
		$odd=1;
		foreach($items as $it){
			$odd=!$odd;
			?><div class="panel gallery_panel<?php print $odd?" last_panel":""?>">
					<h2><?php print htmlentities(stripslashes($it->title))?></h2>
					<?php if($it->videoURL){?>				
						<div class="gallery_movie" id="gallery_movie_<?php print $it->id?>">
							<p>Sorry, to see this you need to have Flash player installed and Javascript turned on</p>
						</div>
						<script>
							var so = new SWFObject("<?php print $it->getVideoSWF()?>", "v3", "300", "250", "8", "#000000");
							so.addParam("menu", "false");			
							so.addParam("allowFullScreen", "true");
							so.addVariable("border","0");
							so.addVariable("color2","0x555555");			
							so.addVariable("color1","0x331122");			
							//so.addVariable("color2","0x000000");			
							so.write("gallery_movie_<?php print $it->id?>");
						</script>
					<?php }else{?>
						<div class="gallery_image">
							<a title="<?php print htmlentities($it->title)?>" class="lightbox_link" href="uploads/<?php print $it->id?>_main.png"><img src="uploads/<?php print $it->id?>_listing.png" alt="<?php print htmlentities($it->title)?>" width="420" height="260"/></a>
						</div>
					<?php }?>
				<p><?php print htmlentities(stripslashes($it->description))?></p>
				<span class="poster">Posted by <?php print $it->getAuthorName()?> on <?php print date("jS F Y",$it->createDate)?></span>
				<?php if($userdata['isAdmin'] || $it->idAuthor==$userdata['user_id']){?>(<a href="addGallery.php?id=<?php print $it->id?>">Edit</a>)<?php }?>		
			</div>	
			<?php
			}
	?>	
</div>

<div id="paging">
	<?php
	for($i=1;$i<=$numpages;$i++){
		echo('<div class="page_number'.($i==$page?" page_number_active":"").'"><a href="gallery.php?page='.$i.'">'.$i.'</a></div>');		
	}
	?>
</div>
</div>
<?php
require_once("footer.php");
?>