
  $(document).ready(function () {

    // Generate a file input element
    $('#fileUpload a').click(function () {
      $(this).before('<input type="file" name="fileUpload[]" />');
    }).click();


    // Enliven delete links
    $('table.authenticated thead tr').append('<th>Delete?</th>');

    $('table.authenticated tbody tr').each(function() {
      $(this).append('<td class="deleteLink"><img src="/images/icons/cross.png" alt="delete" title="delete" /></td>');
    });

    $('table.authenticated tbody tr td.deleteLink').click(function(e) {

      if (confirm("Are you sure?")) {

        img      = $(this).children('img');
        row      = $(this).parent();
        file = row.children('td.name').children('a').attr('href');

        img.attr('src', '/images/loaders/circle.gif');
        img.attr('alt', 'loading...');

        $.ajax({
          type:     'POST',
          url:      'delete',
          data:     {file: file},
          success:  function() {
            row.remove();
          },
          error:    function() {
            img.attr('src', '/images/icons/error.png');
            img.attr('alt', 'error');
            img.attr('title', 'error');
          }
        });

      } // endif;

    });

  });

