$(document).ready(function() {
    $('.random-other-image').live('click', function() {
        var url = $('#param_load_main_url').val() + '?id=' + $(this).attr('horse_id');
        $('#random_horses_list li').removeClass('random-other-selected');
        $(this).parent().addClass('random-other-selected');
        $('#random_main').fadeOut().load(url, function() { $('#random_main').fadeIn(); });
    });
    
    $.get(
        $('#param_random_url').val(),
        {},
        function(data) {
          $.each(data, function(i,item){
            var filename = $('#param_thumbs_url').val()+item.filename;
            if (!item.filename) {
                filename = $('#param_no_preview').val();
            }
            $('<li></li>').html(
                $("<img/>").attr("src", filename).attr('horse_id', item.id).addClass('random-other-image')
            )
            .appendTo("#random_horses_list");
          });

          $('#random_horses_list img:first').click();
        },
        'json'
    );

/*
    $('.random-horse-main-image img').live('mousemove', function() {
        $('#random-image-name').slideDown();
    });

    $('.random-horse-main-image img').live('mouseout', function() {
        $('#random-image-name').slideUp();
    });
*/
    $('#view_horse_details').live('click', function() {
        location.href = $('#horse_details_url').val() + '/id/'+$('#horse_random_id').val();
    });
});
