<!-- categories block -->

{assign var='types' value=','|explode:$types}

{if !$block.Tpl}
	{if $types|@count > 1}
		<div class="caption" style="padding-bottom: 0;">
			{$lang.categories}
		</div>
	{/if}
{else}
	<div style="padding-top: 5px"></div>
{/if}

{foreach from=$types item='type'}
	{assign var='box_listing_type' value=$listing_types.$type}

	{if $types|@count > 1}
		{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_header.tpl' name=$box_listing_type.name id='addcatblock'|cat:$box_listing_type.Key class='categories_padding'}
	{/if}
	
	{if $box_categories.$type}
		{math assign='pages_number' equation='ceil(count/num)' count=$box_categories.$type|@count num=$box_listing_type.Ablock_visible_number}
		{*if $pageInfo.Key == 'home' && $block.Key == 'ltcb_listings'}
			{assign var='pages_number' value=$pages_number+1}
		{/if*}
		<div class="categories{if $box_listing_type.Ablock_show_subcats} sub_categories_exist{/if}" id="categories_{$type|replace:'_':''}_{$pages_number}">
			<div>
				<ul>
					{*if $block.Key == 'ltcb_listings'}
						<li>{include file='blocks'|cat:$smarty.const.RL_DS|cat:'map.tpl'}</li>
						<li class="hide">
					{else*}
						<li>
					{*/if*}
					
					<div class="categoty-column categories_{$type|replace:'_':''}">
						
					{foreach from=$box_categories.$type item='cat' name='fCats'}
						{rlHook name='tplBetweenCategories'}
						
						<div class="item">
							<div class="parent-cateory">
								{if !$box_listing_type.Ablock_show_subcats}
								<div class="category-name">
								{/if}
									{rlHook name='tplPreCategory'}
									<a class="category" title="{if $lang[$cat.pTitle]}{$lang[$cat.pTitle]}{else}{$lang[$cat.pName]}{/if}" href="{$rlBase}{if $config.mod_rewrite}{$pages[$box_listing_type.Page_key]}/{$cat.Path}{if $box_listing_type.Cat_postfix}.html{else}/{/if}{else}?page={$pages[$box_listing_type.Page_key]}&amp;category={$cat.ID}{/if}">{$lang[$cat.pName]}</a>
									{rlHook name='tplPostCategory'}
								
								{if !$box_listing_type.Ablock_show_subcats}
								</div>
								
									{if $box_listing_type.Cat_listing_counter}
									<div class="category-counter">
										<span>{$cat.Count|number_format}</span>
									</div>
									{/if}
									
								{else}
									{if $box_listing_type.Cat_listing_counter}
										<span>({$cat.Count|number_format})</span>
									{/if}
								{/if}
							</div>
							
							{if !empty($cat.sub_categories) && $box_listing_type.Ablock_show_subcats}
							<div class="sub_categories">
								{if $box_listing_type.Ablock_subcat_number}
									{section loop=$cat.sub_categories name='sub_cat' max=$box_listing_type.Ablock_subcat_number}
										{rlHook name='tplPreSubCategory'}
										{assign var='subcat_title' value=$cat.sub_categories[sub_cat].pTitle}
										<a title="{if $lang.$subcat_title}{$lang.$subcat_title}{else}{$cat.sub_categories[sub_cat].name}{/if}" href="{$rlBase}{if $config.mod_rewrite}{$pages[$box_listing_type.Page_key]}/{$cat.sub_categories[sub_cat].Path}{if $box_listing_type.Cat_postfix}.html{else}/{/if}{else}?page={$pages[$box_listing_type.Page_key]}&amp;category={$cat.sub_categories[sub_cat].ID}{/if}">{$cat.sub_categories[sub_cat].name}</a>{if $smarty.section.sub_cat.last}{if $cat.sub_categories|@count > $box_listing_type.Ablock_subcat_number}<span class="more" title="{$lang.show_other_categories}">&nbsp;&raquo;</span>{/if}{else}, {/if}
									{/section}
									
									<div class="hide other_categories">
											{section loop=$cat.sub_categories name='sub_cat' start=$box_listing_type.Ablock_subcat_number}
											{rlHook name='tplPreSubCategory'}
											{assign var='subcat_title' value=$cat.sub_categories[sub_cat].pTitle}
												<a title="{if $lang.$subcat_title}{$lang.$subcat_title}{else}{$cat.sub_categories[sub_cat].name}{/if}" href="{$rlBase}{if $config.mod_rewrite}{$pages[$box_listing_type.Page_key]}/{$cat.sub_categories[sub_cat].Path}{if $box_listing_type.Cat_postfix}.html{else}/{/if}{else}?page={$pages[$box_listing_type.Page_key]}&amp;category={$cat.sub_categories[sub_cat].ID}{/if}">{$cat.sub_categories[sub_cat].name}</a>{if !$smarty.section.sub_cat.last}, {/if}
										{/section}
									</div>
								{else}
									{foreach from=$cat.sub_categories item='sub_cat' name='subCatF'}
										{rlHook name='tplPreSubCategory'}
											<a title="{if $lang[$sub_cat.pTitle]}{$lang[$sub_cat.pTitle]}{else}{$sub_cat.name}{/if}" href="{$rlBase}{if $config.mod_rewrite}{$pages[$box_listing_type.Page_key]}/{$sub_cat.Path}{if $box_listing_type.Cat_postfix}.html{else}/{/if}{else}?page={$pages[$box_listing_type.Page_key]}&amp;category={$sub_cat.ID}{/if}">{$sub_cat.name}</a>{if !$smarty.foreach.subCatF.last}, {/if}
									{/foreach}
								{/if}
							</div>
							{/if}
						</div>
						
						{*if $smarty.foreach.fCats.iteration%$box_listing_type.Ablock_columns_number == 0 && ($smarty.foreach.fCats.iteration%$box_listing_type.Ablock_visible_number != 0 || !$box_listing_type.Ablock_visible_number) && !$smarty.foreach.fCats.last}
						</div>
						<div class="categoty-column categories_{$type|replace:'_':''}">
						{/if*}
						
						{if $smarty.foreach.fCats.iteration%$box_listing_type.Ablock_visible_number == 0 && $box_listing_type.Ablock_visible_number && !$smarty.foreach.fCats.last}
							</div>
							{if $box_listing_type.Ablock_visible_number}
								</li><li class="hide">
							{/if}
							<div class="categoty-column categories_{$type|replace:'_':''}">
						{/if}
					{/foreach}
					
					{if $smarty.foreach.fCats.total%$box_listing_type.Ablock_columns_number != 0}
						{math assign='rest' equation='(ceil(total/cols)*cols) - total' total=$smarty.foreach.fCats.total cols=$box_listing_type.Ablock_columns_number}
						{section name='rest' loop=$rest|ceil}
							<div></div>
						{/section}			
					{/if}
					</div>
					</li>
				</ul>
				<div class="clear"></div>
			</div>
		</div>
		
		{if $pages_number > 1}
			<div class="slider_bar{if $types|@count > 1} slider_bar_light{/if}">
				<div class="arrow"><div class="prev hide" title="{$lang.show_previous_categories}"></div></div>
				<div class="navigation">
					{section name='slide_page' loop=$pages_number|ceil}
						<a title="{if $block.Key == 'ltcb_listings'}{if $smarty.section.slide_page.first}{$lang.show_map}{else}{$lang.show_states}{/if}{else}{$lang.show_other_categories}{/if}" accesskey="{$smarty.section.slide_page.iteration}" {if $smarty.section.slide_page.first}class="active"{/if} href="javascript:void(0)"><span {if $block.Key == 'ltcb_listings' && $smarty.section.slide_page.first}class="map"{/if}>&nbsp;</span></a>
					{/section}
				</div>
				<div class="arrow"><div class="next" title="{$lang.show_next_categories}"></div></div>
			</div>
			
			{if $box_listing_type.Ablock_scrolling}
				<script type="text/javascript" src="{$smarty.const.RL_LIBS_URL}jquery/jquery.mousewheel.js"></script>
			{/if}
			
			<script type="text/javascript">
			{literal}
			$(document).ready(function(){
				var catSlider = false;
				
				if ( !catSlider )
				{
					$('div.categories').flCatSlider({
						scroll: {/literal}{if $box_listing_type.Ablock_scrolling}true{else}false{/if}{literal}
					});
					catSlider = true;
				}
			});
			{/literal}
			</script>
		{/if}
		
		<script type="text/javascript">
			flynax.moreCategories();

			{if $box_listing_type.Ablock_columns_number > 1}
			{literal}
			$(document).ready(function(){
				var columns = {/literal}{if $box_listing_type.Ablock_columns_number}{$box_listing_type.Ablock_columns_number}{else}3{/if}{literal};
				var key = '{/literal}{$type|replace:'_':''}{literal}';
				var width = $('div.categories_'+key).width();
				var item_width = Math.floor((width - 40) / columns);
				
				$('div.categories_'+key+' div.item').width(item_width);
				$('div.categories_'+key).masonry({
					itemSelector : '.item',
					isRTL: rlLangDir == 'rtl' ? true : false,
					fraudWidth : 20, //Flynax Setting
					columnWidth : function( containerWidth ) {
						return containerWidth / columns;
					}
				});
			});
			{/literal}
			{/if}
		</script>
		
		<script type="text/javascript" src="{$rlTplBase}js/jquery.masonry.js"></script>
	
	{else}
		<div style="padding: 10px 12px;">{$lang.listing_type_no_categories}</div>
	{/if}
	
	{if $types|@count > 1}
		{include file='blocks'|cat:$smarty.const.RL_DS|cat:'fieldset_footer.tpl'}
	{/if}
	
{/foreach}

<!-- categories block end -->