(function($){
    $.fn.autocompleteSimple = function() {

    var timeout = false;
    var wait = 300;

    return $(this).each(function() {

        var $select = $(this);
        var $input = $('<input type="text" class="select_menu2" style="width:96%; margin-bottom:5px;"/>').
        insertBefore($select).val('Введите название и выберите из списка').focus(function() {
                $(this).val('').unbind('focus');
        });

        var $temp = $('<div id="temp"></div>').appendTo($('body')).hide();
        var $options = $select.find('option');
        var possibilities = {};
        var options_array = [];
        var matching_options = [];

        $options.each(function() {
            var $option = $(this);
            var text = $option.text();
            possibilities[text] = $option;
        });

        $input.bind('keyup',function() {
            if (!timeout)
            {
                setTimeout(function()
                {
                    timeout = true;
                    var val = $input.val();

                    if (val.match(/.{2,}/))
                    {
                        $options.appendTo($temp);
                        $.each(possibilities,function(text,$matching_option)
                        {
                            if (text.toLowerCase().match(val.toLowerCase()))
                            {
                                $matching_option.appendTo($select);
                            }
                        })
                    }
                    else
                    {
                        $select.empty();
                        $options.appendTo($select);
                    }
                    // ie is dumb
                    
                    /*$select.find('option').unbind('click').click(function() {
                        window.location.href = $(this).parent().parent().attr('action') + '&link_id=' + $(this).val();
                    });
                    */
                    
                    timeout = false;
                }, 500);
            }
        });

    });
};

})(jQuery);
