// create ajax request object helper
var ajaxWiz = new AjaxReq('');


// extend base page object
PageBaseObj.implement({

    initialize: function()
    {
        this.searchBox = 0;
        
        // create function to be run when DOM has loaded
        var loadFunc = function()
        {
            this.searchBox = new TextboxList('searchBox', {unique: true, plugins: {autocomplete: {onlyFromValues: true, placeholder: "Start typing a tag, and then select the tag from this list"}}});
            this.searchBoxAC = this.searchBox.plugins['autocomplete'];
            //console.log(this.searchBox.plugins);
            //this.searchBoxAC.setValues([[31, 'Bit Plain Text', 'Bit html', 'Suggestion item html']]);
            ajaxWiz.send("get_all_tags_and_ids", "", this._addTags); 
        
        };
        
        // add funtion as domready event handler        
        window.addEvent('domready', loadFunc.bind(this));
    
    
    },
    
    _addTags: function(j)
    {
        // convert string to hopefully array
        j = JSON.decode(j);
    
        if(j == null)
        {
            alert("An error has occurred");
            return false;
        }
        for(var i = 0, l = j.length; i < l; i++)
            j[i] = [j[i][0], j[i][1], j[i][1], j[i][1]];
            
        Page.searchBoxAC.setValues(j);

    }
    
});

// create page object
var Page = new PageBaseObj();