{{ header }} 
{% set theme_options = registry.get('theme_options') %}
{% set config = registry.get('config') %}
{% set page_direction = theme_options.get( 'page_direction' ) %} 
{% set language_id = config.get( 'config_language_id' ) %} 
{% set background_status = constant('false') %}
{% include 'fastor/template/new_elements/wrapper_top.twig' %}

<div id="mfilter-content-container">
  <label class="control-label" for="input-search"><b>{{ entry_search }}</b></label>
  <div class="row" id="content-search" style="padding-top: 7px">
    <div class="col-sm-4">
      <input type="text" name="search" value="{{ search }}" placeholder="{{ text_keyword }}" id="input-search" class="form-control" />
    </div>
    <div class="col-sm-3">
      <select name="category_id" class="form-control">
        <option value="0">{{ text_category }}</option>
        {% for category_1 in categories %} 
        {% if (category_1['category_id'] == category_id) %} 
        <option value="{{ category_1['category_id'] }}" selected="selected">{{ category_1['name'] }}</option>
        {% else %} 
        <option value="{{ category_1['category_id'] }}">{{ category_1['name'] }}</option>
        {% endif %} 
        {% for category_2 in category_1['children'] %} 
        {% if (category_2['category_id'] == category_id) %} 
        <option value="{{ category_2['category_id'] }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2['name'] }}</option>
        {% else %} 
        <option value="{{ category_2['category_id'] }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2['name'] }}</option>
        {% endif %} 
        {% for category_3 in category_2['children'] %} 
        {% if (category_3['category_id'] == category_id) %} 
        <option value="{{ category_3['category_id'] }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3['name'] }}</option>
        {% else %} 
        <option value="{{ category_3['category_id'] }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3['name'] }}</option>
        {% endif %} 
        {% endfor %} 
        {% endfor %} 
        {% endfor %} 
      </select>
    </div>
    <div class="col-sm-3" style="padding-top: 7px">
      <label class="checkbox-inline">
        {% if (sub_category) %} 
        <input type="checkbox" name="sub_category" value="1" checked="checked" />
        {% else %} 
        <input type="checkbox" name="sub_category" value="1" />
        {% endif %} 
        {{ text_sub_category }}</label>
    </div>
  </div>
  <p>
    <label class="checkbox-inline">
      {% if (description) %} 
      <input type="checkbox" name="description" value="1" id="description" checked="checked" />
      {% else %} 
      <input type="checkbox" name="description" value="1" id="description" />
      {% endif %} 
      {{ entry_description }}</label>
  </p>
  <input type="button" value="{{ button_search }}" id="button-search" class="btn btn-primary" style="margin-top: 10px" />
  <h2 style="padding-top: 40px">{{ text_search }}</h2>
  
  {% if (products) %} 
  {% set currently = theme_options.getCurrently() %}
  <!-- Filter -->
  <div class="product-filter clearfix">
    <div class="options">
      <div class="product-compare"><a href="{{ compare }}" id="compare-total">{{ text_compare }}</a></div>
      
      <div class="button-group display" data-toggle="buttons-radio">
        <button id="grid" {% if (currently == 'grid') %} {{ 'class="active"' }} {% endif %} rel="tooltip" title="Grid" onclick="display('grid');"><i class="fa fa-th-large"></i></button>
        <button id="list" {% if (currently != 'grid') %} {{ 'class="active"' }} {% endif %} rel="tooltip" title="List" onclick="display('list');"><i class="fa fa-th-list"></i></button>
      </div>
    </div>
    
    <div class="list-options">
      <div class="sort">
        <select onchange="location = this.value;">
          {% for sorts in sorts %} 
          {% if (sorts['value'] == sort ~ '-' ~ order) %} 
          <option value="{{ sorts['href'] }}" selected="selected">{{ sorts['text'] }}</option>
          {% else %} 
          <option value="{{ sorts['href'] }}">{{ sorts['text'] }}</option>
          {% endif %} 
          {% endfor %} 
        </select>
      </div>
      
      <div class="limit">
        <select onchange="location = this.value;">
          {% for limits in limits %} 
          {% if (limits['value'] == limit) %} 
          <option value="{{ limits['href'] }}" selected="selected">{{ limits['text'] }}</option>
          {% else %} 
          <option value="{{ limits['href'] }}">{{ limits['text'] }}</option>
          {% endif %} 
          {% endfor %} 
        </select>
      </div>
    </div>
  </div>
  
  {% if (currently != 'grid') %} 
  <!-- Products list -->
  <div class="product-list active">
    {% for product in products %} 
    <!-- Product -->
    <div>
      <div class="row">
        <div class="image col-sm-3">
          {% if (product['special'] and theme_options.get( 'display_text_sale' ) != '0') %} 
            {% set text_sale = 'Sale' %}
          {% if (theme_options.get( 'sale_text', config.get( 'config_language_id' ) ) != '') %}
            {% set text_sale = theme_options.get( 'sale_text', config.get( 'config_language_id' ) ) %}
          {% endif %} 
            {% if (theme_options.get( 'type_sale' ) == '1') %} 
            {% set product_detail = theme_options.getDataProduct( product['product_id'] ) %}
          {% set roznica_ceny = product_detail['price']-product_detail['special'] %}
          {% set procent = roznica_ceny*100/product_detail['price'] %} 
            <div class="sale">-{{ procent|round }}%</div>
            {% else %} 
            <div class="sale">{{ text_sale }}</div>
            {% endif %} 
          {% elseif (theme_options.get( 'display_text_new' ) != '0' and theme_options.isLatestProduct( product['product_id'] )) %} 
             <div class="new">{% if (theme_options.get( 'new_text', config.get( 'config_language_id' ) ) != '') %} {{ theme_options.get( 'new_text', config.get( 'config_language_id' ) ) }} {% else %} {{ 'New' }} {% endif %}</div>
          {% endif %} 
          
          {% if (product['thumb']) %} 
            {% if (theme_options.get( 'lazy_loading_images' ) != '0') %} 
            <a href="{{ product['href'] }}"><img src="image/catalog/blank.gif" data-echo="{{ product['thumb'] }}" alt="{{ product['name'] }}" /></a>
            {% else %} 
            <a href="{{ product['href'] }}"><img src="{{ product['thumb'] }}" alt="{{ product['name'] }}" /></a>
            {% endif %} 
          {% else %} 
          <a href="{{ product['href'] }}"><img src="image/no_image.jpg" alt="{{ product['name'] }}" /></a>
          {% endif %} 
          
          {% if (theme_options.get( 'display_specials_countdown' ) == '1' and product['special']) %} {% set countdown = random(5000)*random(500000) %} 
         {% set product_detail = theme_options.getDataProduct( product['product_id'] ) %}
         {% set date_end = product_detail['date_end'] %}
         {% if (date_end != '0000-00-00' and date_end) %} 
                  <script>
                  $(function () {
                    var austDay = new Date();
                    austDay = new Date({{ theme_options.date("Y", theme_options.strtotime(date_end)) }}, {{ theme_options.date("m", theme_options.strtotime(date_end)) }} - 1, {{ theme_options.date("d", theme_options.strtotime(date_end)) }});
                    $('#countdown{{ countdown }}').countdown({until: austDay});
                  });
                  </script>
                  <div id="countdown{{ countdown }}" class="clearfix"></div>
                 {% endif %} 
          {% endif %} 
        </div>
        
        <div class="name-actions col-sm-4">
             <div class="name"><a href="{{ product['href'] }}">{{ product['name'] }}</a></div>
             {% if (theme_options.get( 'product_list_type' ) == '4') %} 
             {% set product_detail = theme_options.getDataProduct( product['product_id'] ) %} 
             <div class="brand">{{ product_detail['manufacturer'] }}</div>
             {% endif %} 
             
             {% if (product['price']) %} 
          <div class="price">
            {% if (not product['special']) %} 
            {{ product['price'] }} 
            {% else %} 
            <span class="price-old">{{ product['price'] }}</span> <span class="price-new">{{ product['special'] }}</span>
            {% endif %} 
          </div>
          {% endif %} 
          
          <ul>
               {% if (theme_options.get( 'display_add_to_cart' ) != '0') %} 
                    {% set enquiry = constant('false') %} {% if (config.get( 'product_blocks_module' ) != '') %} {% set enquiry = theme_options.productIsEnquiry(product['product_id']) %} {% endif %}
         {% if (enquiry is iterable) %} 
                    <li><a href="javascript:openPopup('{{ enquiry['popup_module'] }}', '{{ product['product_id'] }}')" data-toggle="tooltip" data-original-title="{{ enquiry['block_name'] }}"><i class="fa fa-question"></i></a></li>
                    {% else %} 
                    <li><a onclick="cart.add('{{ product['product_id'] }}');" data-toggle="tooltip" data-original-title="{{ button_cart }}"><i class="fa fa-shopping-cart"></i></a></li>
                    {% endif %} 
               {% endif %} 
               
               {% if (theme_options.get( 'quick_view' ) == 1) %} 
               <li class="quickview"><a href="index.php?route=product/quickview&amp;product_id={{ product['product_id'] }}" data-toggle="tooltip" data-original-title="{% if (theme_options.get( 'quickview_text', config.get( 'config_language_id' ) ) != '') %} {{ theme_options.html_entity_decode(theme_options.get( 'quickview_text', config.get( 'config_language_id' ) )) }} {% else %} {{ 'Quickview' }} {% endif %}"><i class="fa fa-search"></i></a></li>
               {% endif %} 
          
            {% if (theme_options.get( 'display_add_to_compare' ) != '0') %} 
            <li><a onclick="compare.add('{{ product['product_id'] }}');" data-toggle="tooltip" data-original-title="{% if (theme_options.get( 'add_to_compare_text', config.get( 'config_language_id' ) ) != '') %} {{ theme_options.get( 'add_to_compare_text', config.get( 'config_language_id' ) ) }} {% else %} {{ 'Add to compare' }} {% endif %}"><i class="fa fa-exchange"></i></a></li>
            {% endif %} 
            
            {% if (theme_options.get( 'display_add_to_wishlist' ) != '0') %} 
            <li><a onclick="wishlist.add('{{ product['product_id'] }}');" data-toggle="tooltip" data-original-title="{% if (theme_options.get( 'add_to_wishlist_text', config.get( 'config_language_id' ) ) != '') %} {{ theme_options.get( 'add_to_wishlist_text', config.get( 'config_language_id' ) ) }} {% else %} {{ 'Add to wishlist' }} {% endif %}"><i class="fa fa-heart"></i></a></li>
            {% endif %} 
          </ul>
        </div>
        
        <div class="desc col-sm-5">
          <div class="description">{{ product['description'] }}</div>
        </div>
      </div>
    </div>
    {% endfor %} 
  </div>
  {% endif %} 
  
  {% if (currently == 'grid') %} 
  <!-- Products grid -->
  
 {% set class = 3 %} 
 {% set row = 4 %} 
 
 {% if (theme_options.get( 'product_per_pow' ) == 6) %} {% set class = 2 %} {% endif %}
 {% if (theme_options.get( 'product_per_pow' ) == 5) %} {% set class = 25 %} {% endif %}
 {% if (theme_options.get( 'product_per_pow' ) == 3) %} {% set class = 4 %} {% endif %}
 
 {% if (theme_options.get( 'product_per_pow' ) > 1) %} {% set row = theme_options.get( 'product_per_pow' ) %} {% endif %} 
 
  <div class="product-grid active">
    <div class="row">
        {% set row_fluid = 0 %} {% for product in products %} {% set row_fluid = row_fluid + 1 %} 
          {% set r=row_fluid-(row_fluid/row)|round(0, 'floor')*row %} {% if (row_fluid>row and r == 1) %} {{ '</div><div class="row">' }} {% endif %} 
          <div class="col-sm-{{ class }} col-xs-6">
              {% include 'fastor/template/new_elements/product.twig' %} 
          </div>
        {% endfor %} 
    </div>
  </div>
  {% endif %} 
  
  <div class="row pagination-results">
    <div class="col-sm-6 text-left">{{ pagination }}</div>
    <div class="col-sm-6 text-right">{{ results }}</div>
  </div>
  {% else %} 
  <p style="padding-bottom: 10px;padding-top: 10px">{{ text_empty }}</p>
  {% endif %} 
</div>
<script type="text/javascript"><!--
$('#content-search input[name=\'search\']').keydown(function(e) {
  if (e.keyCode == 13) {
    $('#button-search').trigger('click');
  }
});

$('select[name=\'category_id\']').bind('change', function() {
  if (this.value == '0') {
    $('input[name=\'sub_category\']').attr('disabled', 'disabled');
    $('input[name=\'sub_category\']').removeAttr('checked');
  } else {
    $('input[name=\'sub_category\']').removeAttr('disabled');
  }
});

$('select[name=\'category_id\']').trigger('change');

$('#button-search').bind('click', function() {
  url = 'index.php?route=product/search';
  
  var search = $('#content-search input[name=\'search\']').attr('value');
  
  if (search) {
    url += '&search=' + encodeURIComponent(search);
  }

  var category_id = $('#content select[name=\'category_id\']').attr('value');
  
  if (category_id > 0) {
    url += '&category_id=' + encodeURIComponent(category_id);
  }
  
  var sub_category = $('#content input[name=\'sub_category\']:checked').attr('value');
  
  if (sub_category) {
    url += '&sub_category=true';
  }
    
  var filter_description = $('#content input[name=\'description\']:checked').attr('value');
  
  if (filter_description) {
    url += '&description=true';
  }

  location = url;
});

function setCookie(key, value) {
    var expires = new Date();
    expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
    document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}

function display(view) {
  if (view == 'list') {
    setCookie('display','list');
    location.reload();
  } else {
    setCookie('display','grid');
    location.reload();
  }
}
//--></script> 

{% include 'fastor/template/new_elements/wrapper_bottom.twig' %}
{{ footer }}