var Controller = Class.create({
    initialize: function(params) {
        this.params = params;
        this.is_busy = false;
        this.ajax_params = $H();
        this.name = this.params.name;
        this.first_update = true;
    },
    
    addParams: function(params) {
        this.ajax_params.update(params);
        return this;
    },
    
    setParams: function(params) {
        this.ajax_params = $H(params);
        return this;
    },
    
    update: function() {
        if (typeof(this.params.container) == 'string') {
            this.params.container = $(this.params.container);
        }
        if (!this.params.container) return;
        if (this.is_busy) return;
        this.is_busy = true;
        this.params.container.update('<div class="loader">&nbsp;</div>');
        request(this.params.url, this.ajax_params, this._onUpdate.bind(this));
    },    
    
    clear: function() {
        this.params.container.update('');  
    },
    
    _onUpdate: function(transport) {
        this.params.container.update(transport.responseText); 
        this.prepareHTML();
        
        if (this.first_update) {
            notify(this, 'start');
            this.first_update = false;
        }
 
        if (this.params.prepare) {
            this.params.prepare();
        }
 
        this.is_busy = false;
    },
    
    prepareHTML: function() {
        
    }
})
