Попробуйте так.
var imglink = $(this).attr('href');
var previmglink =$(this).prev('a');
var nextimglink =$(this).next('a');
$('.modal_content').html('<a href="#" class="prev">Дальше</a> <img src=""> <a href="#" class="next">Дальше</a>');
$('.modal_content img').attr('src',imglink);
$('.prev').click(function(){
$('.modal_content img').attr('src',previmglink.attr('href'));
nextimglink = previmglink.next('a');
previmglink = previmglink.prev('a');
});
$('.next').click(function(){
$('.modal_content img').attr('src',nextimglink.attr('href'));
previmglink = nextimglink.prev('a');
nextimglink = nextimglink.next('a');
});