<ul  class="brand-cat-list clearfix">
	{* define the function *} 
	{function name=brandcategories level=0}
		{foreach from=$data item="productCategory" key="pid"} 
			<li  data-level="{$level}" rel="{$level}"  class="level-{$level}">
                                {assign var="prodCatID" value=$productCategory.productCategoryID}
                                {assign var="attrKey" value=$productCategory.productCategoryKey|default:''} 
				{*{if $attrQueryStringArray[$attrKey]|default:'' && in_array($prodCatID,$attrQueryStringArray[$attrKey])}
				{assign var="attrCatChecked" value="checked"} 
				{else}
				{assign var="attrCatChecked" value=""} 
				{/if}*}
                                {*
                                {if $originCatalogID|default:'' neq '' && $originCatalogID!=$prodCatID}
                                    {assign var="readOnlyVar" value="disabled"}
                                {/if}*}
                                {assign var="readOnlyVarCat" value=""}                  
                                {assign var="attrCatChecked" value=""}

                                  {if $catSelKeys|default:''}
                                     {if in_array($attrKey,$catSelKeys)}
                                         {assign var="attrCatChecked" value="checked"} 
                                     {else}
                                          {assign var="readOnlyVarCat" value="disabled"}
                                     {/if}
                                  {else}


                                  {/if}
				{if $level==1} 
                                  {form->checkbox disabled="{$readOnlyVarCat}" refinehead="{$prodCatID}_{$productCategory.productCategoryParent}_{$productCategory['children']|count}" refineval="{$productCategory.productCategoryName}" refinevalparent="{$productCategory.productCategoryParent}" id="searchAttrCatID_{$attrKey}" class="searchAttrCatID parent_{$productCategory.productCategoryParent}"  name="searchAttrCatID[]" value={$attrKey} checked={$attrCatChecked} rel=$prodCatID}
                                        <label disabled="{$readOnlyVar}" class="attributeSearchLabel" id="searchAttrCatLabel_{$prodCatID}" for="searchAttrCatID_{$attrKey}">{$brandName} {$productCategory.productCategoryName}</label>
					{*{html->anchor href="brand/{$brandKey}/{$productCategory.productCategoryID|sef_path:'catalog'}" class="Fsbold" content="{$productCategory.productCategoryName}"}*}
				{else}
                                  {form->checkbox disabled="{$readOnlyVarCat}" refinehead="{$prodCatID}_{$productCategory.productCategoryParent}_{$productCategory['children']|count}" refineval="{$productCategory.productCategoryName}" refinevalparent="{$productCategory.productCategoryParent}" id="searchAttrCatID_{$attrKey}" class="searchAttrCatID child_{$prodCatID}" name="searchAttrCatID[]" value={$attrKey} checked={$attrCatChecked} rel=$prodCatID}
                                        <label disabled="{$readOnlyVar}" class="attributeSearchLabel" id="searchAttrCatLabel_{$prodCatID}" for="searchAttrCatID_{$attrKey}">{$brandName} {$productCategory.productCategoryName}</label>
					 
				{/if}
			{if isset($productCategory['children']) && is_array($productCategory['children']) && !empty($productCategory['children'])}
				{assign var="elementCount" value=$productCategory['children']|count/3}
				{assign var="elementCount" value=$elementCount|ceil}
				{if $elementCount>0}
					{if $level<1}<span class="expand collaps"></span>
					<div class="brand-cat-group clearfix" > 
					{/if}
						{assign var="productCategoryChildren" value=array_chunk($productCategory['children'], 3)}
						{for $counter=0; $counter<$elementCount ; $counter++}
						<ul class="categoryUL_{$productCategory.productCategoryKey}"> 
						{call name=brandcategories data=$productCategoryChildren[$counter] level=$level+1} 
						</ul>
						{/for}
					{if $level<1}
					</div>
						
					{/if}
					
				{else}
					<ul > 
					{call name=brandcategories data=$productCategory['children'] level=$level+1} 
					</ul>
				{/if}
			{else}
				{if (is_array($productCategory)) && (isset($productCategory['menuItemID'])) && (is_numeric($productCategory['menuItemID']))}
				</li>	
				{/if}
			{/if}
		{/foreach}  
	{/function}
	{call brandcategories data=$CategoryMenus} 
</ul>
<script type="text/javascript">
$(document).ready(function(e) {
   $(".collaps").click(function() {
		$(this).toggleClass("expand");
		$(this).next(".brand-cat-group").slideToggle();
	});
});	
</script>


		
