<?php
/*
 *
 * @package		ARI Smart Content
 * @author		ARI Soft
 * @copyright	Copyright (c) 2011 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;

require_once dirname(__FILE__) . '/mediagallery.php';

class AriSmartContentWidgetMediaGallerySimple extends AriSmartContentWidgetMediaGalleryBase
{
	function getJsOptions($itemCount = 0)
	{
		$jsOptions = parent::getJsOptions($itemCount);
		
		$jsOptions['galleryType'] = 'ARIMediaGallerySimple';

		return $jsOptions;
	}

	function render()
	{
		$params = $this->_params;
		$mainParams = AriUtils::getParam($params, '_default');
		$galleryParams = AriUtils::getParam($params, 'gallery', array());
		$visibleItemCount = intval(AriUtils::getParam($galleryParams, 'visibleItemCount'), 10);

		$source = AriUtils::getParam($mainParams, 'source');
		$sourceData = AriSmartContentProvidersHelper::resolveSource($source);
		$data = AriSmartContentProvidersHelper::getData($sourceData, null);
		$hiddenData = null;

		if ($visibleItemCount > 0)
		{
			$hiddenData = array_splice($data, $visibleItemCount);
			$hiddenData = AriSmartContentWidgetMediaGalleryHelper::prepareHiddenData($hiddenData, $params);
		}

		$data = AriSmartContentWidgetMediaGalleryHelper::prepareData($data, $params, true);

		$this->loadAssets();
		$this->registerClientInstance(count($data));
		
		$this->renderTemplate($data, $hiddenData);
	}

	private function renderTemplate($data, $hiddenData)
	{
		$params = $this->_params;
		$pagingParams = $this->getPagingOptions();
		$galleryId = $this->getId();

		require dirname(__FILE__) . '/../tmpl/simple/gallery.php';
	}
}