var otable;

jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
	var _that = this;
	this.each( function ( i ) {
		$.fn.dataTableExt.iApiIndex = i;
		var	iDelay = (iDelay && (/^[0-9]+$/.test(iDelay)) ? iDelay : 250),
			$this = this, 
			oTimerId = null, 
			sPreviousSearch = null,
			anControl = $( 'input', _that.fnSettings().aanFeatures.f );
		
			anControl.unbind( 'keyup' ).bind( 'keyup', function() {
			var $$this = $this;

			if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
				window.clearTimeout(oTimerId);
				sPreviousSearch = anControl.val();	
				oTimerId = window.setTimeout(function() {
					$.fn.dataTableExt.iApiIndex = i;
					_that.fnFilter( anControl.val() );
				}, iDelay);
			}
		});
		
		return this;
	} );
	return this;
}

/* Example call */
$(document).ready(function() {
	$('.dataTable').dataTable().fnSetFilteringDelay();
} );


$(document).ready(function ()
  {
  otable = $('table#archive_table').dataTable({
	'bJQueryUI': true,
	'sPaginationType': 'full_numbers',
	'bSortClasses': false,
	"aaSorting": [[1,'desc']],
	'sDom': '<"H"<"float_right"f>>t<"F"i<"dataTable_paginate_float_right"p>>',
	'aoColumns':    [
			{ 'sWidth': '50px' },
			{ 'sWidth': '80px' },
			null,
			{ 'sWidth': '100px' }
			],
	'iDisplayLength': 50,
	'bServerSide': true,
	'sAjaxSource': 'archive.pl',
        'fnDrawCallback': function ( oSettings ) 
	  {
	  $('table#archive_table tbody tr').each(function () {
            if (/auction sale/i.test($(this).children('td:eq(3)').html())) { $(this).addClass('auction_sale'); }
	    else if (/post-auction negotiated sale/i.test($(this).children('td:eq(3)').html())) { $(this).addClass('negotiated'); }
	    else if (/in negotiation/i.test($(this).children('td:eq(3)').html())) { $(this).addClass('in_negotiation'); }
            });
	  },
	'fnInitComplete': function ( oSettings )
	  {
 	  $('div#archive_table_filter').prepend("<div class='help tooltip small float_left' content='Searching Sales History'></div>");
	  $('div.dataTables_filter#archive_table_filter').width('271px');
	  initialize_help_icons();
	  }
        }).fnSetFilteringDelay(1000);;
  });
