<div id="view">
  <div style="float: left;" id="categoryHeader">

  </div>
  <a href="home"><i class="fa fa-reply themeBlue" aria-hidden="true" style="padding: 0 0.5em; font-size: 24pt; cursor: pointer; margin-top: -5px;"></i></a>
  <a href="" id="postThreadButton">
  <div style="float: right;" id="postThreadCaption">
    <i class="fa fa-plus" aria-hidden="true"></i>
    Post
  </div>
  </a>
  <div style="clear: both;"></div>
  <hr class="simple"/>
  <div id="categoryContainer">
  </div>
  <hr/>
</div>

<script>



$('#postThreadButton').attr("href", "postthread?id=" + parseGet("id"));

$( document ).on("actionEventLoad", function() {

$.getJSON("_categorythreads?id=" + parseGet("id"), function(response) {

  var result = "";

  if (response.errorCode != null)
  {
    if (response.errorCode == 1)
      $('#categoryHeader').append('Permission Denied');
    else if (response.errorCode == 13)
    {
      $('#categoryHeader').html("Invalid Category");
      $('#postThreadButton').hide();
    }
    return;
  }

  if (response.length == 0)
  {
      $('#categoryHeader').append('No Posts');
      return;
  }

  $.each(response, function(i, thread) {
    result +=
      "<div class=\"categoryThread table\"> \
        <i class=\"fa fa-circle-o themeBlue tableCell\" aria-hidden=\"true\"></i> \
        <div class=\"threadTitle tableCell\"><a href=\"thread?id=" + thread["id"] + "\">" + decodeURIComponent(thread["title"]) + "</a><span class=\"threadAuthor tableCell\"><a href=\"user?id=" + thread["author"].id + "\">" + thread["author"].username + "</a></span></div> \
        <div class=\"threadTime tableCell\">Last response " + checkJustNow(thread["lastModificationString"]) + "</div> \
        <div class=\"threadReplyCount tableCell\"><div class=\"threadReplyBG\">"+ thread.replies +"</div></div> \
        <div class=\"threadActions tableCell\" style='vertical-align: middle; " +  shouldHideAction(thread.author) +"'><i postid='"+ thread.id + "' class=\"fa fa-times actionHover actionDelete\" aria-hidden=\"true\"></i></div>\
      </div>";
  });

  $('#categoryHeader').html(response[0]["threadCategory"].title);
  $('#categoryContainer').append(result);
});
});

$('#content').on('click', '.actionDelete', function(e) {
  $.getJSON("_editthread",
  {
    id : $(this).attr("postid"),
    delete : true
  },
  function(response) {
      if (response.success)
        window.location.replace(response.destination);
  });
});
</script>


<!--
<div id="categoryContainer">
  <div class="categoryThread table">
    <i class="fa fa-circle-o themeBlue tableCell" aria-hidden="true"></i>
    <div class="threadTitle tableCell"><a href="#">This is the particular thread title</a><span class="threadAuthor tableCell"><a href="#">Example Author</a></span></div>
    <div class="threadTime tableCell">5 minutes ago</div>
    <div class="threadReplyCount tableCell"><div class="threadReplyBG">0</div></div>
  </div>-->