function SearchEngineManager() {
    this.activeNavTab = null;
}

SearchEngineManager.prototype = {
defaultsList_: null,

/**
 * List for other search engine options.
 * @private
 */
othersList_: null,

pending_show_dlg_ : false,
/**
 * List for extension keywords.
 * @private
extensionList_ : null,

/** inheritDoc */
initialize: function(jq) {
  this.$ = jq;
},

/**
 * Sets up the given list as a search engine list
 * @param {List} list The list to set up.
 * @private
 */
setUpList_: function(list) {
 // options.search_engines.SearchEngineList.decorate(list);
 // list.autoExpands = true;
},

showSearchEngineMgrDlg_ : function(){
    if(!this.defaultsList_){
        chrome.send("fetchSearchEngine");
        this.pending_show_dlg_ = true;
        return;
    }

    /*
    canBeDefault: "1"
    canBeEdited: "1"
    canBeRemoved: "1"
    displayName: "Google"
    iconURL: "http://www.google.com/favicon.ico"
    keyword: "google.com"
    modelIndex: "0"
    name: "Google"
    url: "{google:baseURL}search?q=%s&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}ie={inputEncoding}"
    urlLocked: true
    */


    var node = $("#search_engine_mgr_dlg").tmpl({
        items : this.defaultsList_
    });
    $.tmpl.complete();

    for(var i=0;i<this.defaultsList_.length; i++){
        var item = this.defaultsList_[i];
        if((typeof item.default) && item.default == "1"){
         $("#se"+item.modelIndex,node).addClass("default-engine");
        }
    }


    $(".engine-mgr-close",node).click(function(){
      $("#search_engine_mgr").remove();
    });

    $(".set-default", node).click(function(){
        var engineItem = $(this).parent().parent();
        var modeIndex = $(engineItem).attr("iid");
        $(".search-listitem").removeClass("default-engine");
        $(engineItem).addClass("default-engine");
        chrome.send('managerSetDefaultSearchEngine', [String(modeIndex)]);
        Preferences.getInstance().setBooleanPref("default_search_provider.userChanged", true, true);
    });

    $(".del-cur-engine-item",node).click(function(){
        var modeIndex = $(this).parent().attr("iid");
        chrome.send('removeSearchEngine', [String(modeIndex)]);
        $(this).parent().remove();
    });

    $("body").append(node);
},

/**
 * Updates the search engine list with the given entries.
 * @private
 * @param {Array} defaultEngines List of possible default search engines.
 * @param {Array} otherEngines List of other search engines.
 * @param {Array} keywords List of keywords from extensions.
 */
updateSearchEngineList_: function(defaultEngines, otherEngines, keywords) {
    this.defaultsList_ = defaultEngines;
    this.othersList_ = otherEngines;
    if(this.pending_show_dlg_){
        this.pending_show_dlg_ = false;
        this.showSearchEngineMgrDlg_();
    }
}
};

SearchEngineManager.updateSearchEngineList = function(defaultEngines,
                                                    otherEngines,
                                                    keywords) {
  SearchEngineManager.getInstance().updateSearchEngineList_(defaultEngines, otherEngines, keywords);
};

SearchEngineManager.validityCheckCallback = function(validity, modelIndex) {
};


