-if !@new_site
  =raw"</div>"
  .search_form
    %h1 Rechercher sur le site
    = form_tag search_path, method: :get do |f|
      %p
        = text_field_tag :q, params[:q], :class => "search_input"
        = submit_tag "Rechercher", name: nil, :class => "search_send"

  =raw "<div class='main_container'>"

  #general_search_results
    - if @new_site
      -menu_ok = 2 
    -else
      -menu_ok = 1
    -@count = 0
    -@all.each do |record|
      =#debug record

      =#render :partial => "public/menu_items/menu_item_search", :object => record.menu_item, :as => :menu_item
  
      -if true
        -if record.class.name == "Page"
          -if record.menu_item
            -if record.menu_item.menu_id == menu_ok
          
            
              =render :partial => "public/menu_items/menu_item_search", :object => record.menu_item, :as => :menu_item
          
            
  
        -elsif record.class.name == "PressRelease"
          =render :partial => "public/press_releases/press_release_search", :object => record, :as => :press_release
        
        
  
        -elsif record.class.name == "Article"
          =render :partial => "public/articles/article_search", :object => record, :as => :article
        
        
  
        -elsif record.class.name == "VideoFile"
          =render :partial => "public/video_files/video_file_search", :object => record, :as => :video_file
        
     
        -else
          =#debug record.class.name
  %p
    Nombre de résultats : 
    = @count

  :scss
    #general_search_results{
    
      .image{
        width:150px !important;
        height:150px !important;
      }
      .description{
        margin-left:150px;
      }
    }
  
    @media screen and (max-width:600px) {
      #general_search_results{
    
        .image{
          width:100% !important;
          height:150px !important;
          float:none;
          display:block;
          margin:auto;
        }
        .description{
          margin-left:0px;
          margin-bottom:50px;
        }
      }
    }

-else
  =render :partial => "new_top"
  
  -if params[:document] != "magazine-noe"
    .new_search_bar.search_form
    
      = form_tag search_path, method: :get do |f|
        .inner
          .input_wrapper{:class => ("doc" if @doc)}
            = text_field_tag :q, params[:q], :class => "search_input"
            -if @doc
              =hidden_field_tag :doc, @doc
              =hidden_field_tag :media, params[:media]
              =hidden_field_tag :press, params[:press]
            
              -if params[:press].to_s == ""
                -if params[:media].to_s == ""
                  -options = [["Document",""] ]
                  -options << [qit("Communiqués de presse"), "presse"] if !params[:doc]
                  -options << [qit("Fiches sentiences"), "sentience"] if params[:doc]
                  -options << [qit("Vidéos"), "video"] if !params[:doc]
                  -DataFileCategory.all.each do |dfc|
                    -if dfc.id != 8
                      -options << [qit(dfc.name), dfc.name.to_slug]
              
                -else
                  -options = [[qit("Vidéos"), "video"] ]
                .select_wrapper=select_tag :document, options_for_select(options, params[:document])
              
                -options = [[qit("Animal"),""]]
            
                -Animal.order(:name).all.each do |animal|
                  -options << [animal.name, animal.id]
            
                .select_wrapper=select_tag :animal, options_for_select(options, params[:animal])
            
            
                -options = [[qit("Combat"),""]]
            
                -Category.order(:name).all.each do |animal|
                  -if animal.category_categoryables.count > 0
                    -options << [qit(animal.name), animal.id]
            
                .select_wrapper=select_tag :category, options_for_select(options, params[:category])
              
              -else
                =#hidden_field_tag :document, "sentience"
            
              
            
            
            
            
            
            
            
            =# submit_tag "Rechercher", name: nil, :class => "search_send"
            =link_to ic(:search), "#", :onclick => "$(this).closest('form').submit();return false;", :class => "submit_link"


  #general_search_results
    
    #result_count
    - if @new_site
      -menu_ok = 2 
    -else
      -menu_ok = 1
    -@count = 0
    
    
    -i_page=0
    -nb_page = 0
    
    
    .search_page
      -@all.each do |record|
        -count_before = @count
        =#debug record

        =#render :partial => "public/menu_items/menu_item_search", :object => record.menu_item, :as => :menu_item

        -if true
          -if record.class.name == "Page"
            -if record.menu_item
              -if record.menu_item.menu_id == menu_ok
        
          
                =render :partial => "public/menu_items/menu_item_search", :object => record.menu_item, :as => :menu_item
        
          

          -elsif record.class.name == "PressRelease"
            =render :partial => "public/press_releases/press_release_search", :object => record, :as => :press_release
      
      

          -elsif record.class.name == "Article"
            =render :partial => "public/articles/article_search", :object => record, :as => :article
      
      

          -elsif record.class.name == "VideoFile"
            =render :partial => "public/video_files/video_file_search", :object => record, :as => :video_file
        
          -elsif record.class.name == "DataFile"
            =render :partial => "public/data_files/data_file_search", :object => record, :as => :data_file
        
   
          -else
            =#debug record.class.name
          
        -count_after = @count
        -i_page = i_page +( count_after - count_before)
        -if i_page == 4
          -i_page = 0
          -nb_page = nb_page + 1
          =raw "<div class='cta'><a href='#' onclick=\"$(this).closest('.cta').hide();$('#search_page_#{nb_page}').show();return false;\" class='btn'>En voir plus ></a></div></div><div id='search_page_#{nb_page}' class='search_page' style='display:none;'>"
          
      
      
  .bottom_space
  .results{:style => "display:none;"}
    
    -if @count == 0 and params[:q] and params[:q] != ""
      =qit "Aucun résultats pour la recherche"
      «
      =params[:q]
      »
    -elsif @count == 0
      =qit "Aucun résultats"
    -elsif @count == 1 and params[:q] and params[:q] != ""
      =qit "Un résultat pour la recherche"
      «
      =params[:q]
      »
    -elsif params[:q] and params[:q] != ""
      = @count
      =qit "résultats pour la recherche"
      «
      =params[:q]
      »
  :coffeescript
    $("#result_count").html($(".results").html())

