var SCROLL_TIMEOUT = 10;
function next_photo(data) {
  comment=data[0].comment.comment;
  photo=data[0].object.photo;
  img_src = "/system/pa/photos/square/"+photo.id+"/"+photo.photo_file_name;
  $('#votes').append('<div class="vote" style="opacity:0;height:0" id="vote-'+comment.id+'"><a href="/gallery/photos/'+photo.id+'"><img src="'+img_src+'"/></a><p><span class="l">&ldquo;</span>'+comment.body+'<span class="r">&rdquo;</span></p></div>');
  $('#votes .vote:last').animate({opacity:1, height:"80px"}, 2000);
  $('#votes .vote:first').animate({opacity:0, height:0}, 2000, function() { $(this).remove(); });
  setTimeout("scroll_photo()", SCROLL_TIMEOUT*1000);
}
function scroll_photo() {
  last_id = $('#votes .vote:last').attr('id').substr(5);
  $.getJSON("/gallery/comments.json?limit=1&before="+last_id,
    function(data) {
      if (data.length > 0) {
        next_photo(data);
      }/* else {
        $.getJSON("/gallery/comments.json?limit=1", function(data) { next_photo(data); });
      }*/
    });
}
$(document).ready(function() {
  setTimeout("scroll_photo()", SCROLL_TIMEOUT*1000);
});

