                       clearTimers: {
                            value: function () {
                                clearTimeout(openTimerID);
                                clearTimeout(closeTimerID);
                            }
                        },
                        open: {
                            value: function () {
                                viewModel.clearTimers();
                                if (viewModel.isOpen()) {
                                    return;
                                }

                                viewModel.isOpen(true);
                            }
                        },
                        close: {
                            value: function () {
                                viewModel.clearTimers();
                                if (!viewModel.isOpen()) {
                                    return;
                                }

                                // Reset active index
                                viewModel.activeIndex(-1);
                                viewModel.activeSuggestion = "";
                                viewModel.isOpen(false);
                            }
                        },
                        left: {
                            value: ko.observable(0)
                        },
                        top: {
                            value: ko.observable(0)
                        },
                        GhostText: {
                            value: ""
                        },
                        activeSuggestion: {
                            value: "",
                            writable: true
                        },
                        activeIndex: {
                            value: ko.observable(-1)
                        },
                        setScrollToView: {
                            value: ko.observable(false)
                        },
                        hasItems: {
                            value: function () {
                                if (viewModel.items() != null) {
                                    if (viewModel.items().length > 0) {
                                        return true;
                                    }
                                }

                                return false;
                            }
                        },
                        AnySuggestionsShown: {
                            value: function () {
                                return (viewModel.hasItems() && viewModel.isOpen());
                            }
                        },
                        GhostingFunction: {
                            value: function () {
                                var currentIndex = viewModel.activeIndex(),
                                    activeSuggestion,
                                    suggestions,
                                    ghostSpan,
                                    inFocusText,
                                    ghostText;
                                if (viewModel.isOpen() && currentIndex > -1) {

                                    suggestions = viewModel.items();
                                    if (suggestions != null && suggestions.length > 0 &&
                                        currentIndex < suggestions.length) {
                                        activeSuggestion = suggestions[currentIndex].Str;
                                        ghostSpan = $("span.ghostedText");

                                        if (ghostSpan.length > 0) {
                                            inFocusText = ghostSpan.prev().text();
                                            ghostText = activeSuggestion;

                                            if (ghostText.toLowerCase()
                                                .indexOf(activeSuggestion.toLowerCase()) === 0) {
                                                ghostText = ghostText.substr(inFocusText.length);
                                            }

                                            ghostSpan.text(ghostText);
                                        }
                                    }
                                }
                            }
                        },
                        RemoveGhost: {
                            value: function () {
                                var ghostSpan = $("span.ghostedText");

                                if (ghostSpan.size() > 0) {
                                    ghostSpan.remove();
                                }
                            }
                        },
                        maxIndex: {
                            value: function () {
                                var suggestions = viewModel.items();
                                if (suggestions != null) {
                                    return suggestions.length - 1;
                                }
                                return -1;
                            }
                        },
                        openMe: {
                            value: function () {
                                if (!viewModel.isOpen()) {
                                    viewModel.open();
                                }
                            }
                        },
                        closeMe: {
                            value: function () {
                                if (viewModel.isOpen()) {
                                    viewModel.close();
                                    viewModel.RemoveGhost();
                                }
                            }
                        },
                        ToolTipText: {
                            value: ko.observable("")
                        },
                        ShowTooltipOn: {
                            value: ko.observable(false)
                        },
                        EnableUpDown: {
                            value: ko.observable(true)
                        },
                        IncrementIndex: {
                            value: function () {
                                if (viewModel.EnableUpDown()) {
                                    if (viewModel.isOpen()) {
                                        var val = viewModel.activeIndex();
                                        if (val < viewModel.maxIndex()) {
                                            val++;
                                            viewModel.activeIndex(val);
                                        }
                                    }
                                }
                            }
                        },
                        DecrementIndex: {
                            value: function () {
                                if (viewModel.EnableUpDown()) {
                                    if (viewModel.isOpen()) {
                                        var val = viewModel.activeIndex();
                                        if (val > 0) {
                                            val--;
                                            viewModel.activeIndex(val);
                                        }
                                    }
                                }
                            }
                        },
                        updateViewModelFromNotification: {
                            value: function (vm) {

                                viewModel.items = vm.items;
                                if (vm.items().length > 0) {

                                    var defaultSuggestionIndex = vm.initialIndex();
                                    if (defaultSuggestionIndex != null && defaultSuggestionIndex > -1) {
                                        // Preset the active index
                                        viewModel.activeIndex(defaultSuggestionIndex);
                                        viewModel.setScrollToView(true);
                                    } else if (viewModel.activeSuggestion.length > 0) {
                                        viewModel.items().some(function(item, index) {
                                            if (item.Str === viewModel.activeSuggestion) {
                                                viewModel.activeIndex(index);
                                                item.HoverObservable(true);
                                                viewModel.setScrollToView(true);
                                                return true;
                                            }

                                            return false;
                                        });
                                    }
                                    
                                    viewModel.openMe();
                                }
                            }
                        },
                        positionSet: {
                            value: function () {
                                if (viewModel.hasItems()) {
                                    return viewModel.isOpen();
                                }
                                return false;
                            }
                        },
                        ShowTooltip: {
                            value: function () {
                                if (viewModel.isOpen() && viewModel.activeIndex() > -1) {
                                    if (viewModel.ShowTooltipOn() === true) {
                                        var suggestions = viewModel.items(),
                                            obj;
                                        if (suggestions != null) {
                                            obj = suggestions[viewModel.activeIndex()];
                                            if (obj != null && obj.ToolTip.length > 0) {
                                                viewModel.ToolTipText(obj.ToolTip);
                                                return true;
                                            }
                                        }
                                    }
                                }
                                return false;
                            }
                        },
                        dispose: {
                            value: function () {
                                viewModel.activeIndexSubscription.dispose();
                                proxy.removeNotification(viewModel.notification);
                            }
                        }
                    };

                Object.defineProperties(viewModel, props);

                //watch on the active index to trigger re-render of text and try to cache current settings
                viewModel.activeIndexSubscription = viewModel.activeIndex.subscribe(function (value) {
                    var currentIndex = value,
                        suggestions;
                    if (viewModel.EnableUpDown() && viewModel.isOpen()) {
                        viewModel.setScrollToView(true);
                    }
                    if (currentIndex > -1) {
                        suggestions = viewModel.items();
                        if (suggestions != null && suggestions.length > 0 &&
                            suggestions.length >= currentIndex) {

                            if (currentIndex <= viewModel.maxIndex()) {
                                suggestions.forEach(function (token, index) {
                                    if (index === currentIndex) {
                                        token.HoverObservable(true);
                                    } else {
                                        token.HoverObservable(false);
                                    }
                                });
                            }

                            viewModel.activeSuggestion = suggestions[currentIndex].Str;
                        }

                        viewModel.GhostingFunction();
                    }

                });

                proxy.addNotification(viewModel.notification, function (data) {
                    if (data != null) {
                        presenter.updateViewModel(data, viewModel, viewModel.updateViewModelFromNotification);
                    }
                });
            }
        };
    });