/**
* FWR javascript for auto search functionality.
*/
  $( document ).ready( init_auto_search );
  
 $(document).ready(function() {
   init_auto_search();
   $( "#auto_search_input" ).css( { opacity: .4 } );
 });


  function init_auto_search() {
    var timer;
    document.getElementById( "auto_search_input" ).onkeypress = function() {
      clearTimeout( timer );
      timer = setTimeout( "fwr_auto_search()", 1000 );
    }
  }
  
  function fwr_auto_search() {
    var current_input = '';
    current_input = $( '#auto_search_input' ).val();
    if ( ( current_input.toString().length < 3 ) ) {
      $( '#fwr_auto_search_loading' ).hide();
      $( "#search_container" ).html( '' );
      $( "#search_container" ).hide();
      return;
    }
    $( '#fwr_auto_search_loading' ).show();
    $.post( "includes/modules/fwr_auto_search/fwr_auto_search.php", { 'action': 'search_input', 'keywords': $( '#auto_search_input' ).val() },
      function( data ) {
        if ( data.html == 'false' ) {
          $( '#fwr_auto_search_loading' ).hide();
          $( "#search_container" ).html( '' );
          $( "#search_container" ).hide();
          return false;
        } else {
          $( "#search_container" ).html( data.html );
          $( "#search_container" ).fadeIn( 'slow' );
          $( '#fwr_auto_search_loading' ).hide();
        }
      }, "json"
    );
  }
