<?php
/*
 * ARI Media Gallery Joomla! module
 *
 * @package		ARI Data Tables Joomla! module.
 * @version		1.0.0
 * @author		ARI Soft
 * @copyright	Copyright (c) 2009 www.ari-soft.com. All rights reserved
 * @license		GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
 * 
 */

(defined('_JEXEC') && defined('ARI_FRAMEWORK_LOADED')) or die;

AriKernel::import('Template.Template');

$mainParams = AriUtils::getParam($params, '_default', array());
$galleryParams = AriUtils::getParam($params, 'gallery', array());
$mainClass = AriUtils::getParam($galleryParams, 'mainClass');
$theme = AriUtils::getParam($galleryParams, 'theme');
$pagingPos = $pagingParams['position'];
$currentPage = $pagingParams['currentPage'];
$pageSize = $pagingParams['pageSize'];
$itemCount = count($data);
$pageCount = $pageSize > 0 ? ceil($itemCount / $pageSize) : 1;

if ($currentPage >= $pageCount)
	$currentPage = $pagingParams['currentPage'] = 0;
?>
<div id="<?php echo $galleryId; ?>" class="ari-media-gallery <?php if ($theme):?> <?php echo $theme; ?><?php endif; ?><?php if ($mainClass):?> <?php echo $mainClass; ?><?php endif; ?>">
<?php
	if ($itemCount > 0): 
?>
	<?php
		if ($pagingParams['enabled'] && ($pagingPos == 'top' || $pagingPos == 'both')): 
	?>
	<div class="ari-media-gallery-paging">
		<?php 
			AriTemplate::display(
				dirname(__FILE__) . '/../paging.php', 
				array(
					'pagingParams' => $pagingParams,
					'pageCount' => $pageCount
				)
			);
		?>
	</div>
	<?php
		endif; 
	?>
	<div class="ari-media-gallery-items">
		<?php
			for ($pageNum = 0; $pageNum < $pageCount; $pageNum++):
				$pageData = $pageSize > 0 ? array_slice($data, $pageNum * $pageSize, $pageSize) : $data;

				AriTemplate::display(
					dirname(__FILE__) . '/../items.php', 
					array(
						'data' => $pageData,
						'isCurrentPage' => ($currentPage == $pageNum)
					)
				);
			endfor; 
		?>
	</div>
	<?php
		if ($hiddenData):
	?>
	<div class="ari-media-gallery-hidden-items">
	<?php
			AriTemplate::display(
				dirname(__FILE__) . '/../hidden_items.php', 
				array('data' => $hiddenData)
			);
	?>
	</div>
	<?php
		endif; 
	?>
	<br class="ari-media-gallery-break" />
	<?php
		if ($pagingParams['enabled'] && ($pagingPos == 'bottom' || $pagingPos == 'both')): 
	?>
	<div class="ari-media-gallery-paging">
		<?php 
			AriTemplate::display(
				dirname(__FILE__) . '/../paging.php', 
				array(
					'pagingParams' => $pagingParams,
					'pageCount' => $pageCount
				)
			);
		?>
	</div>
	<?php
		endif; 
	?>
<?php
	else: 
?>
	<div class="ari-media-gallery-nodata"><?php echo JText::_('LIB_ARISMARTCONTENTMEDIAGALLERY_LABEL_NODATA'); ?></div>
<?php
	endif; 
?>
</div>