/*
 * Following constants/variables should be in sync with similar
 * constants/variables in /app/presenters/BasePresenter.php.
 */

var PROFILE_COUNT = 3;
var PROFILE_WIDTH = 275;

var profileIds = [
  "tomas-hampl",
  "ondrej-cervinka",
  "stepan-krecek"
]

$(document).ready(function(){
  $("a.ajax").live("click", function (event) {
    event.preventDefault();
    $.get(this.href);
  });

  $("#header-next-button").click(function() {
    $("#profiles .profile").each(function() {
      var left = $(this).position().left;
      if (left < 0) {
        $(this).css("left", left + PROFILE_COUNT * PROFILE_WIDTH + "px");
      }
    }).animate({ left: "-=" + PROFILE_WIDTH + "px" });

    $("#portrait-" + profileIds[currentProfileIndex]).fadeOut("slow");

    currentProfileIndex = (currentProfileIndex + 1) % PROFILE_COUNT;

    $("#portrait-" + profileIds[currentProfileIndex]).fadeIn("slow");

    $("#header-more-button").attr(
      "href",
      "/nasi-lide/" + profileIds[currentProfileIndex] + "/"
    );

    return false;
  });

  $("#header-prev-button").click(function() {
    $("#profiles .profile").each(function() {
      var left = $(this).position().left;
      if (left > 0) {
        $(this).css("left", left - PROFILE_COUNT * PROFILE_WIDTH + "px");
      }
    }).animate({ left: "+=" + PROFILE_WIDTH + "px" });

    $("#portrait-" + profileIds[currentProfileIndex]).fadeOut("slow");

    currentProfileIndex -= 1;
    /*
     * Note: The "%" operator has bad semantics in this case (e.g. -1 % 4 ===
     * -1, not 3), so we must wrap manually
     */
    if (currentProfileIndex < 0) {
      currentProfileIndex += PROFILE_COUNT;
    }

    $("#portrait-" + profileIds[currentProfileIndex]).fadeIn("slow");

    $("#header-more-button").attr(
      "href",
      "/nasi-lide/" + profileIds[currentProfileIndex] + "/"
    );

    return false;
  });
});

/* Článek */

$(document).ready(function(){
  $("#add-comment-form #frm-check").val(42).closest("tr").hide();
  $("#send-question-form #frm-check").val(42).closest("tr").hide();
});

