<div class="navHomepage">
  <div class="navHomepageLogo fl">
    <%=link_to image_tag("../images/nav_logo.png",width:"51px", height: "45px",class: "mt3"), user_activities_path(User.current.id)%>
  </div>
  <div class="fl">
    <ul>
      <li class="navHomepageMenu fl">
        <%= link_to "首页",user_activities_path(User.current), :class => "c_white f16 db p10", :title => "回到个人首页"%>
      </li>
      <li class="navHomepageMenu fl">
        <%= link_to "资源库", user_resource_user_path(User.current, :type => 6), :class => "c_white f16 db p10" %>
      </li>
      <% if User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)%>
      <li class="navHomepageMenu fl">
            <%= link_to "题库",  user_homeworks_user_path(User.current), :class => "c_white f16 db p10"%>
      </li>
      <% else %>
          <li class="navHomepageMenu fl">
            <%= link_to "我的作业",  student_homeworks_user_path(User.current), :class => "c_white f16 db p10"%>
          </li>
      <% end %>
      <li class="navHomepageMenu fl mr30">
        <%= link_to "帮助中心", "https://#{Setting.host_name}/forums/1/memos/1168", :class =>"c_white f16 db p10" %>
      </li>
    </ul>
  </div>
  <script>
      $(function(){
          $("#navHomepageSearchInput").keypress(function(e){
              var name = $.trim($('#navHomepageSearchInput').val());
              if (e.keyCode == '13' && name != "" &&  name.length != 0) {
                  //$('#type').val($('input[type=radio]:checked').val());
                  $(this).parent().submit();
              }
          })
      });

      function search_in_header(obj){
          var name = $.trim($('#navHomepageSearchInput').val());
          if (name != "" &&  name.length != 0) {
              //$('#type').val($('input[type=radio]:checked').val());
              obj.parent().submit();
          }
      }
  </script>
  <div class="fl" id="navHomepageSearch">
    <!--<form class="navHomepageSearchBox">-->
    <% name = name%>

    <%= form_tag({controller: :welcome, action: :search },:class=>'navHomepageSearchBox', method: :get) do %>
      <input type="text" name="q" value="<%= name.nil? ? "" : name%>" id="navHomepageSearchInput" class="navHomepageSearchInput" placeholder="请输入关键词搜索公开的课程、项目、用户、资源以及帖子"/>
      <input type="hidden" name="search_type" id="type" value="all"/>
      <input type="text" style="display: none;"/>
      <a href="javascript:void(0);" class="homepageSearchIcon" onclick="search_in_header($(this));"></a>
    <% end %>
  </div>

  <div class="navHomepageProfile" id="navHomepageProfile">
    <ul>
      <li class="homepageProfileMenuIcon" id="homepageProfileMenuIcon">
        <%= link_to "<div class='mt5 mb8' id='user_avatar'>#{image_tag(url_to_avatar(User.current),:width =>"40",:height => "40",:class => "portraitRadius",:alt=>"头像", :id => "nh_user_logo")}</div>".html_safe,user_activities_path(User.current.id)%>
        <ul class="topnav_login_list none" id="topnav_login_list">
          <li>
            <%= link_to "修改资料", my_account_path, :class => "menuGrey"%>
          </li>
          <li>
            <%= link_to "我的组织",  user_organizations_user_path(:id => User.current.id), :class => "menuGrey"%>
          </li>
          <li>
            <%= link_to "新建组织", new_organization_path, :class => "menuGrey"%>
          </li>
          <!--<li><a href="javascript:void(0);" class="menuGrey">账号设置</a> </li>-->
          <li>
            <%= link_to "退出",logout_url_without_domain,:class => "menuGrey",:method => "post"%>
          </li>
        </ul>
      </li>
    </ul>
  </div>

  <div class="navHomepageNews">
    <%= link_to "", user_message_path(User.current), :class => "homepageNewsIcon", :target =>"_Blank", :title => "您的所有消息" %>
    <% if User.current.count_new_message.to_i >0 %>
        <div ><%= link_to User.current.count_new_message , user_message_path(User.current), :class => "newsActive", :target =>"_Blank" %></div>
    <% end %>
      <%#= link_to User.current.count_new_message, user_message_path(User.current), :class => "homepageNewsIcon" %>
  </div>
</div>

<script type="text/javascript">
    //搜索相关
    $("#navHomepageSearch").mouseover(function(){
        $("#navHomepageSearchType").show();
    }).mouseout(function(){
        $("#navHomepageSearchType").hide();
    });

    $("#navHomepageProfile").mouseenter(function(){
        $("#homepageProfileMenuIcon").addClass("homepageProfileMenuIconhover");
        $("#topnav_login_list").show();
    });
    $("#navHomepageProfile").mouseleave(function(){
        $("#homepageProfileMenuIcon").removeClass("homepageProfileMenuIconhover");
        $("#topnav_login_list").hide();
    });

    function signout(){
        $.post(
                '<%= signout_path%>',
                {}
        );
    }
</script>
