
$(document).ready(function(){

function my_search()
{
var string_search = $('#search_input').val();

if (string_search.toString().length < 1)
{
$('#pet_choices').fadeOut(500);

$('#pet_choices > ul').hide();

$('#pet_choices > ul > li').hide();

}
else
{
start_search();
}

}

$('#search_input').change(function()
{
my_search();
});

$('#search_input').focus(function()
{
my_search();
});


$('#search_input').keypress(function()
{
my_search();
});


$('#search_input').click(function()
{
my_search();
});

$('#search_input').keydown(function()
{
my_search();
});

$('#search_input').keyup(function()
{
my_search();
});

$('#pet_choices').mouseover(function()
{

$('#pet_choices > ul > li').mouseover(function()
{
$(this).css("background-color","#ffb");
});     

$('#pet_choices > ul > li').mouseout(function()
{
$(this).css("background-color","#fff");
});

});

$('#search_input').blur(function()
{
$('#pet_choices').fadeOut(500);

});

$('#pet_choices > ul > li').click(function()
{
var text = $(this).text();
$('#search_input').val(text);
});

});


function start_search()
{
$('#pet_choices').css("display","block");

// ---- Форма -----
  var options = { 
    // элемент, который будет обновлен по ответу сервера 
  	target: '#pet_choices',
  	url: '../search/search_ajax.php',
    beforeSubmit: showRequest, // функция, вызываемая перед передачей 
    success: showResponse, // функция, вызываемая при получении ответа
    timeout: 1000 // тайм-аут
  };
  // привязываем событие submit к форме
    $('#search_form').ajaxSubmit(options); 
// вызов перед передачей данных
function showRequest(formData, jqForm, options){ 
    var queryString = $.param(formData); 
    return true; 
} 
// вызов после получения ответа 
function showResponse(responseText, statusText){}


$('#pet_choices > ul > li').click(function()
{
var text = $(this).text();
$('#search_input').val(text);
});

$('#indicator img').attr("src","../files_images/images_gif/indicator.gif");


setTimeout("ajax_img();",2000);

}

function ajax_img()
{
$('#indicator img').attr("src","");
}

$('#pet_choices > ul > li').click(function()
{
var text = $(this).text();
$('#search_input').val(text);
});
