
// DMODS_LIVE object
var DMODS_LIVE = {
    dom : new Array(),
    userid : 0,
    
    init : function(userid) {
        this.userid = userid;
    },
    
    update_status : function(status) {
        this.send_request({
            action : 'update_status',
            params : '&status=' + PHP.trim(status)  
        });
        
        this.dom['dmods_status'] = $('#dmods_status');
        this.dom['dmods_status'].val('');
        this.dom['dmods_status'].blur();        
    },
    
    refresh_stream : function() {
        if (THIS_SCRIPT == 'stream') {
            this.send_request({
                action : 'refresh_stream',
                params : ''                
            });
        }              
    },
    
    send_request: function(settings) {
        return YAHOO.util.Connect.asyncRequest('POST', 'stream.php?do=ajax', {
			success : this.ajax_completed,
			failure : this.handle_ajax_error,
			timeout : vB_Default_Timeout,
			scope : this
		}, SESSIONURL + 'securitytoken=' + SECURITYTOKEN + '&action='
				+ settings.action + settings.params);
    },
    
    ajax_completed : function(ajax) { 
        if (ajax.responseText.length) {
    		eval("var r = ("+ajax.responseText+")");
            
            // Handle actions
            switch (r.type) {
                case 'status':
                    if (THIS_SCRIPT == 'stream') {
                        this.refresh_stream();
                    }
                    
                    if (THIS_SCRIPT == 'showthread') {
                        $('div[id|="dmods_live_status_' + this.userid + '"]').text(r.status);
                    }
                break;
                
                case 'refresh_stream':
                    if (r.html != null && r.html.length && THIS_SCRIPT == 'stream') {
                        this.dom['stream'] = $('#streamdata');
                        this.dom['stream'].fadeOut(200);                    
                        this.dom['stream'].html(r.html);
                        this.dom['stream'].fadeIn(200);
                    }
                break;
            }
        }
	}  
    
};

DMODS_LIVE.init();
