function sync_title(idx) {
    var index;
    if (idx===false) {
        index = $('.imgs img').index($('.imgs img:visible'));
    } else {
        index = idx;
    }
    $('.modal .img-title').html($('.imgs img:eq(' + index + ')').attr('alt'));
}

$(document).ready(function() {
    sync_title(0);
    $('.modal .arr').live("click", function () {
        var all = $('.imgs img');
        var current = all.index($('.imgs img:visible'));

        if (current===0) {
            prev = all.length - 1;
        } else {
            prev = current - 1;
        }
        if (current==all.length - 1) {
            next = 0;
        } else {
            next = current + 1;
        }
        $('.imgs img:eq(' + current + ')').hide();
        if ($(this).hasClass('arr-prev')) {
            $('.modal .imgs img:eq(' + prev + ')').show();
        }
        if ($(this).hasClass('arr-next')) {
            $('.imgs img:eq(' + next + ')').show();
        }
        sync_title(false);
        return false;
    });
});

