var _scrollable_art;
var _art_views;

$(document).ready(function() {
    _art_views = $('#art-views');
    _scrollable_art = $('#scrollable-art').scrollable({
	items: '.items',
	horizontal: true,
	size: 5
    });

    var items = $('#scrollable-art .items img');
    items.click(scrollable_clicked);

    // Select a random work
    var randIdx = Math.floor(Math.random()*items.length);
    $(items.get(randIdx)).click();
});

function scrollable_clicked() {
    var activeIndex = _scrollable_art.data('scrollable').activeIndex;
    var artViewer = $('#art-viewer');

    artViewer.animate({marginTop: '100px', opacity: 0.0}, 'normal', function() {
	artViewer.empty();
	artViewer.html(_art_views.children().eq(activeIndex).clone());
	tb_init('#art-viewer a.thickbox');

	artViewer.css({marginTop: '-100px'});
	artViewer.animate({marginTop: '0px', opacity: 1.0}, 'normal');
    });
}
