jQuery.fn.textdropdown = function() {
    with ($(this)) {
        with (next('ul:first')) {
            find('li').click(function() {
                $(this).parent().prev('.textdropdown-outer').find('input:first').attr('value', $(this).html());
                $(this).parent().hide();
            });
            hide();
        }

        keypress(function() {
            switch (e.keyCode) {
                // User pressed "up" arrow     
                case 38:

                    break;
                // User pressed "down" arrow     
                case 40:
                    $(this).parent().next('ul:first').show();
                    break;
                // User pressed "enter"     
                case 13:
                    if (currentUrl != '') {
                        window.location = currentUrl;
                    }
                    break;
                default:
                    $(this).parent().next('ul:first').hide();
                    break;
            }

        });

        change(function() {
            $(this).parent().next('ul:first').hide();
        });

        wrap('<div class="textdropdown-outer" style="width: ' + width() + 'px; height: ' + (height() + 5) + 'px"></div>');
        var btn = parent().append('<div class="textdropdown-btn">&nbsp;</div>').find('.textdropdown-btn');
        width(width() - btn.width() - 5);
        css("border", "0");

        btn.click(function() {
            var p = parent();
            var o = p.offset();

            with (p.next('ul:first')) {
                css('position', 'absolute');
                css('width', p.width() - 30);
                if (jQuery.browser.msie) {
                    css('left', p.position().left);
                    css('top', p.position().top + p.height() + 1);
                }
                else {
                    css('left', o.left);
                    css('top', o.top + p.height() + 1);
                }
                toggle();
            }
        });
    }
}
