{% if (registry.has('theme_options') == constant('true')) %} 
     {% 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 advanced_id = id %} 

     <div class="advanced-grid advanced-grid-{{ advanced_id }} {{ custom_class }} {% if (disable_on_mobile == 1) %} {{ 'hidden-xs hidden-sm' }}{% endif %}" style="margin-top: {{ margin_top }}px;{% if (force_full_width != 1) %}margin-left: {{ margin_left }}px;margin-right: {{ margin_right }}px;{% endif %}margin-bottom: {{ margin_bottom }}px;">
          {% if (background_image_type == 2) %}<div class="parallax-window" style="{% if (background_color != '') %} {{ 'background-color: ' ~ background_color ~ ';' }} {% endif %} {% if (background_image != '') %} {{ 'background-image: url(image/' ~ background_image ~ ');' }} {% endif %}" data-velocity="-0.4">{% endif %} 
          {% if (background_image_type == 1) %}<div style="{% if (background_color != '') %} {{ 'background-color: ' ~ background_color ~ ';' }} {% endif %} {% if (background_image != '') %} {{ 'background-image: url(image/' ~ background_image ~ ');' }} {% endif %} {{ 'background-position: ' ~ background_image_position ~ ';background-repeat: ' ~ background_image_repeat ~ ';background-attachment: ' ~ background_image_attachment ~ ';' }}">{% endif %} 
          {% if (background_image_type == 0) %}<div style="{% if (background_color != '') %} {{ 'background-color: ' ~ background_color ~ ';' }} {% endif %}">{% endif %} 
                <div class="container">
                    <div style="padding-top: {{ padding_top }}px;padding-left: {{ padding_left }}px;padding-bottom: {{ padding_bottom }}px;padding-right: {{ padding_right }}px;">
                         <div class="row">
                              {% set row = 0 %} 
                              {% for column in columns %} 
                                   
                                   {% if (column['width'] == 'advanced') %}
                                        {% if (column['width_lg'] != 'hidden') %}
                                             {% set row = row+column['width_lg'] %}
                                             {% if (row > 12) %} 
                                                  {{ '</div><div class="row">' }}
                                                  {% set row = column['width_lg'] %} 
                                             {% endif %}
                                        {% endif %}

                                        {% set column_width = 'col-lg-' ~ column['width_lg'] ~ ' col-md-' ~ column['width_md'] ~ ' col-sm-' ~ column['width_sm'] ~ ' col-xs-' ~ column['width_xs'] ~ '' %}
                                        {% if (column['width_lg'] == 'hidden') %} 
                                             {% set column_width = column_width ~ ' hidden-lg' %}
                                        {% endif %}
                                        
                                        {% if (column['width_md'] == 'hidden') %} 
                                             {% set column_width = column_width ~ ' hidden-md' %}
                                        {% endif %}

                                        {% if (column['width_sm'] == 'hidden') %} 
                                             {% set column_width = column_width ~ ' hidden-sm' %}
                                        {% endif %}

                                        {% if (column['width_xs'] == 'hidden') %} 
                                             {% set column_width = column_width ~ ' hidden-xs' %}
                                        {% endif %}
                                   {% else %} 
                                        {% set row = row+column['width'] %}
                                        {% set column_width = 'col-sm-' ~ column['width'] %}
                                        {% if (column['disable_on_mobile'] == '1') %} 
                                             {% set column_width = column_width ~ ' hidden-xs' %}
                                        {% endif %}
                                        {% if (row > 12) %} 
                                             {{ '</div><div class="row">' }} 
                                             {% set row = column['width'] %} 
                                        {% endif %}
                                   {% endif %}
      
                                   <div class="{{ column_width }}">
                                        {% for module in column['modules'] %} 
                                             {% if (module['type'] == 'load_module') %} 
                                                  {{ module['content']['module'] }} 
                                             {% elseif (module['type'] == 'html') %} 
                                                  {{ module['content']['html'] }} 
                                             {% elseif (module['type'] == 'box') %} 
                                                  {% if (position == 'footer_bottom' or position == 'footer' or position == 'footer_top' or position == 'footer_left' or position == 'footer_right' or position == 'customfooter_top' or position == 'customfooter_bottom' or position == 'customfooter') %}
                                                       {{ '<h4>'~module['content']['title']~'</h4>' }}
                                                       {{ '<div class="strip-line"></div>' }}
                                                       {{ '<div class="clearfix" style="clear:both">' ~ module['content']['text'] ~ '</div>' }}
                                                  {% else %} 
                                                       {{ '<div class="box">' }}
                                                            {{ '<div class="box-heading">' }}
                                                                 {{ module['content']['title'] }}
                                                            {{ '</div>' }}
                                                            {{ '<div class="strip-line"></div>' }}
                                                            {{ '<div class="box-content">' }}
                                                                 {{ module['content']['text'] }}
                                                            {{ '</div>' }}
                                                       {{ '</div>' }} 
                                                  {% endif %}   
                                             {% elseif (module['type'] == 'links') %} 
                                                  {% set config = registry.get('config') %}
{% if (position == 'footer_bottom' or position == 'footer' or position == 'footer_top' or position == 'footer_left' or position == 'footer_right' or position == 'customfooter_top' or position == 'customfooter_bottom' or position == 'customfooter') %}
     
     {% if (module['content']['title'] != '') %}
      {{ '<h4>'~module['content']['title']~'</h4>' }}
     {% else %} 
      {{ '<div style="height:13px"></div>' }}
     {% endif %}
     {{ '<div class="strip-line"></div>' }}

     {% if module['content']['limit'] < 1 %} 
          {% set limit = 20 %}
     {% else %}
          {% set limit = module['content']['limit'] %}
     {% endif %} 

     {% set count_columns = (module['content']['links']|length/limit)|round(0, 'ceil') %}
     {% set class = 3 %} 
     
     {% if (count_columns == 1) %} {% set class = 12 %}{% endif %}
     {% if (count_columns == 2) %} {% set class = 6 %}{% endif %}
     {% if (count_columns == 3) %} {% set class = 4 %}{% endif %}
     {% if (count_columns == 4) %} {% set class = 3 %}{% endif %}
     {% if (count_columns == 5) %} {% set class = 25 %}{% endif %}
     {% if (count_columns == 6) %} {% set class = 2 %}{% endif %} 
     
     {{ '<div class="row" style="clear: both">' }}
      {{ '<div class="col-sm-' ~ class ~ '">' }}
      {{ '<ul>' }}
      {% set i = 0 %} 
      
     {% for link in module['content']['links'] %} 
      {% if (limit == i) %}
      {% set i = 0 %}
      {{ '</ul></div><div class="col-sm-' ~ class ~ '"><ul>' }}
      {% endif %}
      
      {% if (link['url'] is iterable) %}
          {% set nowy_link = link['url'] %}
          {% set language_id = config.get( 'config_language_id' ) %}
          {% if (nowy_link[language_id] is defined) %}
               {% set link = link|merge({'url': nowy_link[language_id]}) %}
          {% else %} 
               {% set link = link|merge({'url': ''}) %}
          {% endif %}
      {% endif %} 
      
      {{ '<li><a href="' ~ link['url'] ~ '">' ~ theme_options.html_entity_decode(link['name']) ~ '</a></li>' }}
      {% set i = i + 1 %}
     {% endfor %} 
 {{ '</ul>' }}
 {{ '</div>' }}
 {{ '</div>' }}  
{% else %} 
     
     {{ '<div class="box">' }}
          {{ '<div class="box-heading">' }}
               {{ module['content']['title'] }}
          {{ '</div>' }}
          {{ '<div class="strip-line"></div>' }}
          {{ '<div class="box-content">' }}

               {% if module['content']['limit'] < 1 %} 
                    {% set limit = 20 %}
               {% else %}
                    {% set limit = module['content']['limit'] %}
               {% endif %} 

               {% set count_columns = (module['content']['links']|length/limit)|round(0, 'ceil') %}
               {% set class = 3 %}      

               {% if (count_columns == 1) %} {% set class = 12 %}{% endif %}
               {% if (count_columns == 2) %} {% set class = 6 %}{% endif %}
               {% if (count_columns == 3) %} {% set class = 4 %}{% endif %}
               {% if (count_columns == 4) %} {% set class = 3 %}{% endif %}
               {% if (count_columns == 5) %} {% set class = 25 %}{% endif %}
               {% if (count_columns == 6) %} {% set class = 2 %}{% endif %}
               
               {{ '<div class="row">' }}
                {{ '<div class="col-sm-' ~ class ~ '">' }}
                {{ '<ul>' }}
                {% set i = 0 %}
                {% for link in module['content']['links'] %} 
                     {% if (limit == i) %}
                     {% set i = 0 %}
                     {{ '</ul></div><div class="col-sm-' ~ class ~ '"><ul>' }}
                     {% endif %}
                     
                     {% if (link['url'] is iterable) %}
                         {% set nowy_link = link['url'] %}
                         {% set language_id = config.get( 'config_language_id' ) %}
                         {% if (nowy_link[language_id] is defined) %}
                              {% set link = link|merge({'url': nowy_link[language_id]}) %}
                         {% else %} 
                              {% set link = link|merge({'url': ''}) %}
                         {% endif %}
                     {% endif %} 
                     
                     {{ '<li><a href="' ~ link['url'] ~ '">' ~ link['name'] ~ '</a></li>' }}
                     {% set i = i + 1 %}
                {% endfor %}
                {{ '</ul>' }}
                {{ '</div>' }}
               {{ '</div>' }}
          {{ '</div>' }}
     {{ '</div>' }}
{% endif %}
                                             {% elseif (module['type'] == 'newsletter') %} 
                                                  {% set theme_options = registry.get('theme_options') %}
{% set config = registry.get('config') %} 

<div class="audio-newsletter" id="newsletter{{ id }}">
     <div class="heading">
          <div class="first">{{ module['content']['title'] }}</div>
          <div class="second">{{ module['content']['text'] }}</div>
     </div>
     
     <div class="inputs">
          <input type="text" class="email" placeholder="{{ module['content']['input_placeholder'] }}" />
          <a class="button btn-default subscribe">{{ module['content']['subscribe_text'] }}</a>
     </div>
     
     {% if (theme_options.get( 'rodo_status' ) == '1') %} 
          <div class="newsletter_rodo2">
               <form id="agree_rodo_form2">
                    <input type="checkbox" name="agree_rodo2" value="1" required="required">&nbsp;{{ theme_options.html_entity_decode(theme_options.get( 'rodo_text', config.get( 'config_language_id' ) )) }} 
                    <input type="submit" class="submit hidden" value="Submit">
               </form>
          </div>
     {% endif %} 
</div>

<script type="text/javascript">
$(document).ready(function() {
     function Unsubscribe() {
          $.post('{{ module['content']['unsubscribe_url'] }}', 
               { 
                    email: $('#newsletter{{ id }} .email').val() 
               }, function (e) {
                    $('#newsletter{{ id }} .email').val('');
                    alert(e.message);
               }
          , 'json');
     }
     
     function Subscribe() {
          {% if (theme_options.get( 'rodo_status' ) == '1') %} 
          if($('input[name="agree_rodo2"]').is(':checked')) {
          {% endif %} 
          $.post('{{ module['content']['subscribe_url'] }}', 
               { 
                    email: $('#newsletter{{ id }} .email').val() 
               }, function (e) {
                    if(e.error === 1) {
                         var r = confirm(e.message);
                         if (r == true) {
                             $.post('{{ module['content']['unsubscribe_url'] }}', { 
                              email: $('#newsletter{{ id }} .email').val() 
                             }, function (e) {
                              $('#newsletter{{ id }} .email').val('');
                              alert(e.message);
                             }, 'json');
                         }
                    } else {
                         $('#newsletter{{ id }} .email').val('');
                         alert(e.message);
                    }
               }
          , 'json');
          {% if (theme_options.get( 'rodo_status' ) == '1') %} 
          } else {
               $('#agree_rodo_form2 .submit').click();
          }
          {% endif %} 
     }
     
     $('#newsletter{{ id }} .subscribe').click(Subscribe);
     $('#newsletter{{ id }} .unsubscribe').click(Unsubscribe);
     $('#newsletter{{ id }} .email').keypress(function (e) {
         if (e.which == 13) {
             Subscribe();
         }
     });
});
</script>
                                             {% elseif (module['type'] == 'latest_blogs') %} 
                                                  {% include 'odesk/template/extension/module/advanced_grid/latest_blogs/' ~ module['content']['module_template']|replace({'.tpl': '.twig'}) %} 
                                             {% elseif (module['type'] == 'products') %} 
                                                  {% include 'odesk/template/extension/module/advanced_grid/products/' ~ module['content']['module_template']|replace({'.tpl': '.twig'}) %} 
                                             {% elseif (module['type'] == 'products_tabs') %} 
                                                  {% include 'odesk/template/extension/module/advanced_grid/products_tabs/' ~ module['content']['module_template']|replace({'.tpl': '.twig'}) %} 
                                             {% else %} 
                                                  Unknown error.
                                             {% endif %} 
                                        {% endfor %} 
                                   </div>
                              {% endfor %}
                          </div>
                    </div>
               </div>
          </div>
          
          {% if (background_image_type == 2) %} 
          <script type="text/javascript" src="catalog/view/theme/odesk/js/jquery.scrolly.js"></script>
          <script>
              $(document).ready(function(){
                 $('.advanced-grid-{{ advanced_id }} .parallax-window').scrolly({bgParallax: true});
              });
          </script>
          {% endif %} 
     </div>

     {% if (force_full_width == 1) %} 
     <script type="text/javascript">
          function force_full_width_{{ advanced_id }}() {
               var p = $(".standard-body .full-width .advanced-grid-{{ advanced_id }}");
               
               {% if (page_direction[language_id] != 'RTL') %} 
               if(p.size() > 0) {
                    p.width($('body').width());
                    p.css("left", "0px");
                    var position = p.offset();
                    p.css("left", "-" + position.left + "px");
                    p.find(".container").css("padding-left", position.left);
                    p.find(".container").css("padding-right", position.left);
                    
               }
               {% else %} 
               if(p.size() > 0) {
                    p.width($('body').width());
                    p.css("right", "0px");
                    var position = p.offset();
                    p.css("right", "-" + position.left * -1 + "px");
                    p.find(".container").css("padding-left", position.left * -1);
                    p.find(".container").css("padding-right", position.left * -1);
               }
               {% endif %} 
               
               var s = $(".standard-body .fixed .advanced-grid-{{ advanced_id }}");
               {% if (page_direction[language_id] != 'RTL') %} 
               if(s.size() > 0) {
                    s.width($('.standard-body .fixed .pattern').width());
                    s.css("left", "0px");
                    var position = s.offset();
                    var position2 = $('.standard-body .fixed .pattern').offset();
                    var position3 = position.left-position2.left;
                    s.css("left", "-" + position3 + "px");
                    s.find(".container").css("padding-left", position3);
                    s.find(".container").css("padding-right", position3);
               }
               {% else %} 
               if(s.size() > 0) {
                    s.width($('.standard-body .fixed .pattern').width());
                    s.css("right", "0px");
                    var position = s.offset();
                    var position2 = $('.standard-body .fixed .pattern').offset();
                    var position3 = position.left-position2.left;
                    s.css("right", "-" + position3 * -1 + "px");
                    s.find(".container").css("padding-left", position3 * -1);
                    s.find(".container").css("padding-right", position3 * -1);
               }  
               {% endif %} 
               
               var c = $(".fixed-body .advanced-grid-{{ advanced_id }}");
               {% if (page_direction[language_id] != 'RTL') %} 
               if(c.size() > 0) {
                    c.width($('.fixed-body .main-fixed').width());
                    c.css("left", "0px");
                    var position = c.offset();
                    var position2 = $('.fixed-body .main-fixed').offset();
                    var position3 = position.left-position2.left;
                    c.css("left", "-" + position3 + "px");
                    c.find(".container").css("padding-left", position3);
                    c.find(".container").css("padding-right", position3);
               }
               {% else %} 
               if(c.size() > 0) {
                    c.width($('.fixed-body .main-fixed').width());
                    c.css("right", "0px");
                    var position = c.offset();
                    var position2 = $('.fixed-body .main-fixed').offset();
                    var position3 = position.left-position2.left;
                    c.css("right", "-" + position3 * -1 + "px");
                    c.find(".container").css("padding-left", position3 * -1);
                    c.find(".container").css("padding-right", position3 * -1);
               }
               {% endif %} 
          }
          
          force_full_width_{{ advanced_id }}();
          
          $(window).resize(function() {
               force_full_width_{{ advanced_id }}();
          });
     </script>
     {% endif %}
{% endif %}