<?php

if( !isset($ace) || !isset($ace->config)){
die('Error. This can only be accessed from another file.');
}

if( !isset($images) ){
	require_once(dirname(__FILE__).'/../classes/images.class.php');
	$images =& new images($ace);
}

if( !isset($galleries_per_page) ) $galleries_per_page = 6;
if( !isset($galleries_gwidth) ) $galleries_gwidth = 150;
if( !isset($galleries_gheight) ) $galleries_gheight = 150;

$page = $ace->getint('p', $_REQUEST);
$gallerycount = $images->getgallerycount();
if( $page < 1 ) $page = 1;
$first = ($page-1) * $galleries_per_page;
if( $first >= $gallerycount ) $first = $gallerycount - $galleries_per_page;
if( $first < 0 ) $first = 0;

$page = ($first / $galleries_per_page)+1;
$totalpages = ceil($gallerycount / $galleries_per_page);
$last = $first + $galleries_per_page;
if( $last > $gallerycount) $last = $gallerycount;

$gals = $images->getgallerythumbnails('', $first, $galleries_per_page);
$first += 1;

?><div style="font-weight: bold; text-align: center;">
Page <?php echo $page;?> of <?php echo $totalpages;?>.
Galleries <?php echo $first.' to '.$last.' of '.$gallerycount;?>.
<br />Page:
<?php for( $i = 1; $i <= $totalpages; $i++){?>
<a href="<?php echo $_SERVER['SCRIPT_NAME'];?>?p=<?php echo $i;?>"><?php echo $i;?></a>

<?php }?>
</div>
<?php

foreach( $gals as $g ){
?>
<div style="width: <?php echo $galleries_gwidth;?>px; height: <?php echo $galleries_gheight;?>px; float: left; text-align: center; padding: 4px; margin: 5px; vertical-align: middle;">
<a target="_blank" href="<?php echo $g->gallery_url;?>"><img style="border: 1px solid black;" src="<?php echo $g->thumb_url;?>" alt="Click to view gallery" /></a>
<br clear="all" />
<a target="_blank" href="<?php echo $g->gallery_url;?>"><?php echo htmlspecialchars($g->gallery_name);?></a>
</div>
<?php
}

?>
