gallery = function(msId) {
var jebeniMsId = msId;
var current = 1;
var total = $('.entry' + jebeniMsId).length;
$('.entry' + jebeniMsId).hide();
$('#pic'+jebeniMsId+'_1').fadeIn('slow');
$('#imageNumber'+jebeniMsId).html('1 / ' + total );
setHeight(1)


$('img.first').click(function(){
var prev  = 1;
if (current != 1) {
$('#pic' + jebeniMsId + '_' + current).fadeOut('slow');
setHeight(prev)
$('#pic' + jebeniMsId + '_' + prev).fadeIn('slow');
current = 1;
$('#imageNumber'+ jebeniMsId ).html(current + ' / ' + total)
}
return false;
});


$('img.previous').click(function(){
var prev  = current - 1;
if (prev < 1) prev = 1;
if (current != 1) {
$('#pic' + jebeniMsId + '_' + current).fadeOut('slow');
$('#pic' + jebeniMsId + '_' + prev).fadeIn('slow');
current = prev;
setHeight(current)
$('#imageNumber'+jebeniMsId).html(current + ' / ' + total)
}
return false;
});

$('img.next').click(function(){
var next = current + 1;
if (next > total) next = total;
if (current != total) {
$('#pic' + jebeniMsId + '_' + current).fadeOut('slow');
$('#pic' + jebeniMsId + '_'  + next).fadeIn('slow');
current = next;
setHeight(current)
$('#imageNumber'+jebeniMsId).html(current + ' / ' + total)
}
return false;
});

$('img.last').click(function(){
var next  = total;
if (current != total) {
$('#pic' + jebeniMsId + '_' + current).fadeOut('slow');
$('#pic' + jebeniMsId + '_' + next).fadeIn('slow');
current = total;
setHeight(current)
$('#imageNumber' + jebeniMsId).html(current + ' / ' + total)
}
return false;
});

function setHeight(current) {
var entryHeight = $('#pic' + current).outerHeight() + 0;
$('#slideshow' + jebeniMsId).animate({ height: entryHeight + 'px'}, 500 );
}

}
