<script>
    var onUserCard = false;
    var onImage = false;
    $(document).ready(function(){
        $("#relateProject,.relatePInfo").mouseover(function(){
            $(".relatePInfo").css("display","block");
        })
        $("#relateProject,.relatePInfo").mouseout(function(){
            $(".relatePInfo").css("display","none");
        })
        $(".homepagePostPortrait").mouseover(function(){
            onImage = true;
            $(this).children(".userCard").css("display","block");
        })
        $(".homepagePostPortrait").mouseout(function(){
            var cur = $(this);
            onImage = false;
            setTimeout(function(){
                if (onUserCard == false && onImage == false) {
                    $(cur).children(".userCard").css("display", "none");
                }
            }, 500);
        })
        $(".userCard").mouseover(function(){
            onUserCard = true;
            $(this).css("display","block");
        })
        $(".userCard").mouseout(function(){
            onUserCard = false;
            $(this).css("display","none");
        })
        $(".coursesLineGrey").mouseover(function(){
            $(this).css("color","#ffffff");
        })
        $(".coursesLineGrey").mouseout(function(){
            $(this).css("color","#808080");
        })
        $(".homepagePostSetting,.coursesLineGrey").mouseover(function(){
            $(this).prev().css("color","#ffffff");
            $(this).css("z-index", "9999");
        })
        $(".homepagePostSetting").mouseout(function(){
            $(this).prev().css("color","#808080");
            $(this).css("z-index", "1");
        })

        //二级菜单滑动时箭头方向控制
        $(".homepageLeftMenuMoreIcon").toggle(function(){
            $(this).css("background","url(/images/homepage_icon.png) 100px -624px no-repeat");
        },function(){
            $(this).css("background","url(/images/homepage_icon.png) -74px -240px no-repeat");
        });
    })
</script>

<% organization.org_subfields.order("priority").each do |field| %>
    <% if is_default_field?(field) %>
        <% case field.name %>
        <% when 'activity' %>
            <div class="homepageLeftMenuBlock" style="display:<%= field.hide == 0 ? 'block':'none' %>;" id="org_subfield_<%= field.id %>">
              <%= link_to "动态",organization_path(organization), :class => "homepageMenuText" %>
            </div>
        <% when 'course' %>
            <div style="display:<%= field.hide == 0 ? 'block':'none' %>;" id="org_subfield_<%= field.id %>">
              <div class="homepageLeftMenuBlock">
                <a href="javascript:void(0);" class="homepageMenuText" onclick="$('#homepageLeftMenuCourses').slideToggle();">课程</a>
                <% if User.current.logged? and User.current.admin_of_org?(organization) %>
                    <%=link_to "", join_course_menu_organization_path(organization),:remote => true, :method => "post", :class => "homepageMenuSetting fr", :title => "关联课程"%>
                <% end %>
              </div>
              <div class="homepageLeftMenuCourses" id="homepageLeftMenuCourses" style="display:<%= organization.courses.count == 0 ?'none':'' %>">
                <ul >
                  <%= render :partial => 'layouts/org_courses',:locals=>{:courses=>organization.courses.where("is_delete=0").reorder('created_at').uniq.limit(5),:org_id=>organization.id,:page=>1}%>
                </ul>
              </div>
            </div>
        <% when 'project' %>
            <div style="display:<%= field.hide == 0 ? 'block':'none' %>;" id="org_subfield_<%= field.id %>">
              <div class="homepageLeftMenuBlock">
                <a href="javascript:void(0);" class="homepageMenuText" onclick="$('#homepageLeftMenuProjects').slideToggle();">项目</a>
                <% if User.current.logged? and User.current.admin_of_org?(organization) %>
                    <%=link_to "", join_project_menu_organization_path(organization),:remote => true, :method => "post", :class => "homepageMenuSetting fr", :title => "关联项目"%>
                <% end %>
              </div>
              <div class="homepageLeftMenuCourses" id="homepageLeftMenuProjects" style="display:<%= organization.projects.count == 0?'none':'' %>">
                <ul>
                  <%= render :partial => 'layouts/org_projects',:locals=>{:projects=>organization.projects.where("status=1").reorder('created_at').uniq.limit(5),:org_id=>organization.id,:page=>1}%>
                </ul>
              </div>
            </div>
        <% end %>
    <% else %>
        <div style="display:<%= field.hide == 0?'block':'none' %>;" id="org_subfield_<%= field.id %>">
          <% if field.field_type == "Post" || field.field_type == "Complex" || field.field_type == "Compstu" || field.field_type == "Comptec" %> <!--讨论帖子-->
              <div class="homepageLeftMenuBlock">
                <!--<a href="javascript:void(0);" class="homepageMenuText" onclick="$('#homepageLeftMenuProjects').slideToggle();">项目</a>-->
                <% if !field.subfield_subdomain_dir.nil? %> <!--讨论帖子-->
                    <% if !request.local? and Secdomain.where("sub_type=2 and pid=?", organization.id).count > 0 and Secdomain.where("sub_type=2 and pid=?", organization.id).map(&:subname).include?(request.subdomain) %>
                        <%= link_to "#{field.name}", show_subfield_without_id_path(:sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %>
                    <% else %>
                        <%= link_to "#{field.name}", show_org_subfield_organization_path(:id => organization.id, :sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %>
                    <% end %>
                <% else %>
                    <% if field.field_type == "Comptec" %>
                        <%= link_to "#{field.name}", teachers_organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %>
                    <% else %>
                        <%= link_to "#{field.name}", organization_path(organization, :org_subfield_id => field.id), :class => "homepageMenuText homepageMenuControl hidden", :onclick => "$('#homepageLeftMenuPost').slideToggle();" %>
                    <% end %>
                <% end %>
                <% if User.current.logged? and User.current.admin_of_org?(organization) && field.field_type != "Comptec"  %>
                    <%=link_to "", new_organization_org_document_comment_path(organization, :field_id => field.id), :method => "get", :class => "homepageMenuSetting fr", :title => "发布帖子" %>
                <% end %>
              </div>
              <div class="<%= (field.sub_domains.count == 0) ? 'homepageLeftMenuCourses':'homepageLeftMenuCourses borderBottomNone' %>" id="PostDomain_<%= field.id %>" style="display:none;">
                <ul>
                  <%= render :partial => 'organizations/org_subdomain',:locals=>{:subdomains => field.sub_domains.reorder('priority').uniq.limit(5), :org_subfield_id => field.id} %>
                </ul>
              </div>

              <% unless (field.sub_domains.count == 0 || !if_hidden_subdomain(field)) %>
                  <li class="homepageLeftMenuMore" id="sub_domain_jiantou_<%= field %>">
                    <a href="javascript:void(0);" class="homepageLeftMenuMoreIcon" onclick="$('#PostDomain_<%= field.id %>').slideToggle();" style="border-bottom: 1px solid #ddd;"></a>
                  </li>
              <% end %>
          <% else %>
              <div class="homepageLeftMenuBlock">
                  <% if !field.subfield_subdomain_dir.nil? %>
                      <% if !request.local? and Secdomain.where("sub_type=2 and pid=?", organization.id).count > 0 and Secdomain.where("sub_type=2 and pid=?", organization.id).map(&:subname).include?(request.subdomain) %>
                          <%= link_to "#{field.name}", show_subfield_without_id_path(:sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText homepageMenuControl hidden" %>
                      <% else %>
                          <%= link_to "#{field.name}", show_org_subfield_organization_path(:id => organization.id, :sub_dir_name => field.subfield_subdomain_dir.name), :class => "homepageMenuText homepageMenuControl hidden" %>
                      <% end %>
                  <% else %>
                      <%= link_to "#{field.name}", org_subfield_files_path(field), :class => "homepageMenuText homepageMenuControl hidden" %>
                  <% end %>
                  <% if User.current.member_of_org?organization %>
                      <%= link_to "", subfield_upload_file_org_subfield_files_path(field.id, :in_org => 1),:method => "post", :remote => true, :class => "homepageMenuSetting fr", :title => "上传资源" %>
                      <!--<a class="homepageMenuSetting fr" title="上传资源" href="javascript:void(0);" onclick="org_subfield_files_upload(<%#= field.id %>);"> </a>-->
                  <% end %>
                  <!--<a href="javascript:void(0);" class="homepageMenuText"><%#= field.name %></a>-->
              </div>
          <% end %>
        </div>
        <div class="homepageLeftMenuCourses" id="homepageLeftMenuField_<%= field.id %>" style="display:none;">
        </div>
    <% end %>
<% end %>