$(document).ready(function(){
  update_switcher_style();
  $('.switcher span.prev').click(function() {
    if ($(".feature-comments ul li.selected").index() != 0) {
      var origin_index = $(".feature-comments ul li.selected").index();
      $(".feature-comments ul li.selected").prev().removeClass("hidden").addClass("selected");
      $(".feature-comments ul li").eq(origin_index).removeClass("selected").addClass("hidden");
      update_switcher_style();
    }
  });
  $('.switcher span.next').click(function() {
    if (($(".feature-comments ul li.selected").index() + 1) != $(".feature-comments ul li").length) {
      var origin_index = $(".feature-comments ul li.selected").index();
      $(".feature-comments ul li.selected").next().removeClass("hidden").addClass("selected");
      $(".feature-comments ul li").eq(origin_index).removeClass("selected").addClass("hidden");
      update_switcher_style();
    }
  });
});

function update_switcher_style() {
  var current_index = $(".feature-comments ul li.selected").index();
  if (current_index == 0) {
    $(".switcher .prev").css("background-position", "0 0");
  }
  if (current_index != 0) {
    $(".switcher .prev").css("background-position", "0 -9px");
  }
  if ((current_index + 1) != $(".feature-comments ul li").length) {
    $(".switcher .next").css("background-position", "0 -9px");
  }
  if ((current_index + 1) == $(".feature-comments ul li").length) {
    $(".switcher .next").css("background-position", "0 0");
  }
}
