I think next() is for finding the next element in the DOM tree not the next element in a collection.
Perhaps use each() on the $('.photo') collection. But then you'be be finding the next element in the collection and I don't think we can assume the collection is in the same order as the DOM tree.
This works though: x = $('#2.photo').next().attr('id');
BTW I think your id's should start with a letter. It works for me in Chrome but I think it may not be correct to start with a number?