// Entry listings (torrents, discussions, videos, and resources)

// View: entries/index.haml

jQuery(function($) {
    // Apply gradient over end of entry list tag elements
    //$('.entry_list div.tags_container').prepend('<span class="gradient"></span>');

    // Bulk selection on Torrent & Discussion pages
    $('#select_toggle').live('click', function(e){
        $("INPUT[name='entry_ids']").attr('checked', this.checked);
    });

    $(".entry_list INPUT[name='entry_ids']").live('click', function(e) {
        e.target.attr('checked', this.checked);
        return false;
    });

    // Bulk deletion on Torrent & Discussion pages
    $('a.delete_selected').live('click', function(e){
        var entry_ids = [];
        $.each($("INPUT[name='entry_ids']"), function(i, n){
            if (this.checked) entry_ids.push(this.value);
        });
        
        if (entry_ids.length > 0) {
            if (confirm("Are you sure you want to delete the selected entries?")) {
                $.post(this.href, {"entry_ids[]":  entry_ids}, function(data){
                    window.location.reload();
                });
            }
        }
        return false;
    });
});


$(function(){
    $("tr[unread]").eachAsync({
        loop: function() {
            var row = $(this);
            var link = row.find("a.row_link");
            var url = link.attr('href');
            link.attr('href', url + row.attr('unread'));
        }
    });
});

