<?php
/**
 * @package AkeebaReleaseSystem
 * @copyright Copyright (c)2010-2011 Nicholas K. Dionysopoulos
 * @license GNU General Public License version 3, or later
 * @version $Id$
 */

defined('_JEXEC') or die('Restricted Access');
$Itemid = JRequest::getInt('Itemid',0);
$morph = Morph::getInstance();
$themeletpath = '/morph_assets/themelets/vanilla';
$templatepath = '/templates/morph';
$morph->addStyleSheetAfter($themeletpath .'/css/tabs.css');
$morph->addScriptAfterJQuery($templatepath .'/core/js/ui.js');
$morph->addScriptAfterJQuery($templatepath .'/core/js/tabs.js');
$morph->addScriptAfterJQuery($templatepath .'/core/js/cookie.js');
$download_tabs = "jQuery(function($){
    $.noConflict();
    $('#download-tabs').tabs();
});";
$morph->addScriptDeclaration($download_tabs);
?>

<?php if ($this->params->get('show_page_title', 1)) : ?>
	<h1><?php echo $this->escape($this->params->get('page_title')); ?></h1>
<?else:?>
	<h1><?php echo JText::_('ARS_VIEW_LATEST_TITLE'); ?></h1>
<?php endif; ?>

<div id="download-tabs">
	<ul>
		<li><a href="#morph-framework">Morph Framework</a></li>
		<li><a href="#themelets">Themelets</a></li>
		<li><a href="#extensions">Extensions</a></li>
	</ul>
	<?php foreach($this->vgroups as $vgroupID => $vgroupTitle): ?>
		<?php $echoedVgroupTitle = false ?>
			<?php foreach($this->items['normal'] as $id => $cat):
				if($cat->vgroup_id != $vgroupID) continue;
				if( !empty($cat->release) )
					if( !empty($cat->release->files) ){
						$params = ArsHelperChameleon::getParams('category');
						if(!$echoedVgroupTitle) {
							$echoedVgroupTitle = true;
							$space 			= " ";
							$dash 			= "-";
							$vgroupTitle 	= str_replace($space , $dash , $vgroupTitle);
							$vgroupTitle 	= strtolower($vgroupTitle);
							echo '<div id="'.$vgroupTitle.'">';
						}
						@ob_start();
						@include $this->getSubLayout('category');
						$contents = ob_get_clean();
						$module = ArsHelperChameleon::getModule($cat->title, $contents, $params);
						echo JModuleHelper::renderModule($module, $params);	
					}
			endforeach; ?>
			<?php if($echoedVgroupTitle):?>
			</div>
			<?php endif; ?>
	<?php endforeach; ?>
</div>