$(document).ready(function(){

	$('.hidden').hide();
	$('.visible').show();
	$('#mosaic').find('li:first').addClass('active');
	var first_id =  $('#mosaic').find('li:first').attr('id');
	refresh_billboard($("#"+first_id+" .mosaic-ref"));

    $('.mosaic-ref').click(function() {
        refresh_billboard(this);
        return false;
    });

});

function refresh_billboard(object) {

    var prev_active_id = $('#mosaic .active').children("a").attr("href");
    var prev_object_id = $('#viewer #entry-' + prev_active_id).children("iframe");
    if (prev_object_id){
        prev_object_id.attr("src","/blank/");
    }

    var id = $(object).attr("href");

    var next_object_url = $('#viewer #entry-'+id).children("input");
    var next_object_id = $('#viewer #entry-'+id).children("iframe");

    if (next_object_id)
    {
        next_object_id.attr("src",next_object_url.attr("value"));
    }

	$('#mosaic .active').removeClass('active');
	$('#td-'+id).addClass('active');
	$('#viewer .visible').removeClass('visible').addClass('hidden').hide();
	$('#profile .visible').removeClass('visible').addClass('hidden').hide();


    if ($('#ranking-span-'+id).length){
        $('#ranking-span-'+id).show();
    }
	$('#entry-'+id).removeClass('hidden').addClass('visible').show();
	$('#profile-'+id).removeClass('hidden').addClass('visible').show();
}