ups the instruction is:
im.wrap("<a href='" + im.attr("src") + "' rel='lightbox[uniqueID|filename]' />");
Complete code:
p = $('<div>');
p.addClass('panel');
im = $('<img />');
im.attr('src',j_frames.eq(i).find('img').eq(0).attr('src')).appendTo(p);
im.wrap("<a href='" + im.attr("src") + "' rel='lightbox[uniqueID|filename]' />");
p.prependTo(j_gallery);
j_frames.eq(i).find('.panel-overlay').remove().appendTo(p);