jQuery(function($) {
  function enhance_anchor() {
    $("#news-list td a").each( function() {
      var a = $(this);
      attach_hover( a );
      if ( $.browser.msie ) {
        a.width( a.parent().width() - 8 );
        a.height( a.parent().height() - 16 );
      } else {
        a.width( a.parent().width() );
        a.height( a.parent().height() );
      }
    });
  }

  function enhance_table( table ) {
    table.dataTable({
      'bPaginate':  false,
      'bSort':      false,
      'bAutoWidth': false,
      'bJQueryUI':  true,
      'aaSorting':  [],
      'sDom': '<"dataTables_block"fi>rt',
      'oLanguage': {
        'sUrl': '../dtables/dataTables.ja_JP.txt'
      }
    });
  }

  function start_filter( table ) {
    jQuery.each( location.search.substr( 1 ).split( /&/ ), function( i, e ) {
      if ( e.match( /^q=(.+)$/ ) ) {
        var text = RegExp.$1;
        text     = decodeURIComponent(text);
        $('#news-list_filter input').attr( 'value', text );
        table.fnFilter( text );
        return false;
      }
    });
  }

  var table = $("#news-list");
  enhance_table( table );
  setTimeout( function() {
    start_filter( table );
    enhance_anchor();
    $('#news-list_filter input').first().focus();
  }, 100 );
});
