﻿
mt.search = {};
mt.search.SearchControl = function () {
    // Call the SearchControl base "constructor" as opposed to the CustomSearchControl constructor
    // in order to avoid the custom search control's addition of a default searcher based on 'arguments'
    google.search.SearchControl.apply(this, arguments);
    this._searcherCount = 0;
    this._searchersByIndex = [];
    this._searchersByKey = {};
    this._searcherIndices = {};
    this.getSearcher = function (id_key) { return this._searchersByIndex[id_key] || this._searchersByKey[id_key]; };
    this.getSearcherIndex = function (key) { return this._searcherIndices[key]; };
    this.getKey = function (searcher) { return (searcher.mt_tag_key) ? searcher.mt_tag_key : 'w'; };

    this.addSearcher = function (searcher, key, opt_options) {
        google.search.SearchControl.prototype.addSearcher.apply(this, [searcher, opt_options]);
        if (key) {
            this._searchersByIndex[this._searcherCount] = searcher;
            this._searchersByKey[key] = searcher;
            this._searcherIndices[key] = this._searcherCount;
            searcher.mt_tag_key = key;
        }
        this._searcherCount++;
    };
};

if (window['google']) {
    // Use the CustomSearchControl as the prototype; this enables the custom search's styles
    mt.search.SearchControl.prototype = new google.search.CustomSearchControl();
} else {
    throw Error('Google AJAX Search API required; not yet loaded.  http://www.google.com/jsapi');
}


