$(document).ready(function() {
    photo_start = 0;
    $('#photos .navigation .next').click(function() {
        requestPhotos(photo_start + 1);
        return false;
    });
    $('#photos .navigation .prev').click(function() {
        requestPhotos(photo_start - 1);
        return false;
    });
});

function requestPhotos(start) {
    $.post('/ajax/photos.php', { start: start }, function(json) {
        if (json.photo_1 && json.photo_2) {
            $('#photo_1').html(json.photo_1);
            $('#photo_2').html(json.photo_2);
            photo_start = start;
            
            //truncate ajaxed captions
            var trunc = 28;
            if($('#photo_1 p').text().length > trunc){
                $('#photo_1 p').html($('#photo_1 p').text().substring(0,trunc) + '&#8230;');
            }
            if($('#photo_2 p').text().length > trunc){
                $('#photo_2 p').html($('#photo_2 p').text().substring(0,trunc) + '&#8230;');
            }
            
        }
    }, 'json');
}