var Controller = Class.create({
    initialize:function()
    {

    },

    initQuickInfo:function(state)
    {
        this.executers = new Array();
        this.previousMessage = undefined;

        if (state==1)
            this.showQuickInfo();
        else if (state==2)
            this.hideQuickInfo();
        else
            this.minQuickInfo();
    },

    startExecuter:function()
    {         
        this.executers.push(new PeriodicalExecuter(this.loadUsers.bind(this), 300));
        this.executers.push(new PeriodicalExecuter(this.loadComments.bind(this), 30));
    },

    loadUsers:function()
    {
        this.loadQuickInfo('users');
    },

    loadComments:function()
    {
        this.loadQuickInfo('comments');
    },

    stopExecuter:function()
    {
        if (this.executers)
            for (var i=0; i<this.executers.length; i++)
                this.executers[i].stop();
    },

    minQuickInfo:function()
    {
        this.setWindowState(3);
        this.stopExecuter();
        $('QuickInfoContainer').setStyle({
            overflow:'hidden'
        });
        anim = new YAHOO.util.Anim($('QuickInfo'));
        anim.attributes.height = {
            to:$('QuickInfoHeader').offsetHeight
        };
        anim.duration = 0.5;
        anim.method = YAHOO.util.Easing.easeOut;
        anim.animate();
        $('QuickInfoMin').hide();
        $('QuickInfoMax').show();
    },

    maxQuickInfo:function()
    {
        this.setWindowState(1);
        this.startExecuter();
        $('QuickInfoContainer').setStyle({
            overflow:'auto'
        });
        anim = new YAHOO.util.Anim($('QuickInfo'));
        anim.attributes.height = {
            to:200
        };
        anim.duration = 0.5;
        anim.method = YAHOO.util.Easing.easeOut;
        anim.animate();
        $('QuickInfoMax').hide();
        $('QuickInfoMin').show();
    },

    loadQuickInfo:function(cmd)
    {
        var loader = new AsyncLoader();
        var container;        

        if (cmd=='users')
            container = 'LoggedInUserThumbs';
        else if (cmd=='comments')
        {
            container = 'Comments';
            loader.onSuccess = function(o)
            {
                if (o.argument[2].previousMessage != undefined
                    && o.argument[2].previousMessage != o.responseText)
                    StartAlerting('QuickInfo');
                o.argument[2].previousMessage = o.responseText;
            }
        }
        loader.server = URL_SERVERS+'quick-info.php';
        loader.element = container;
        loader.params = SESS_ID+'&cmd='+cmd;
        loader.load(this);
    },

    showQuickInfo:function()
    {
        this.setWindowState(1);
        $('QuickInfo').show();
        this.startExecuter();
    },

    hideQuickInfo:function()
    {
        this.setWindowState(2);
        this.stopExecuter();
        $('QuickInfo').hide();
    },

    setWindowState:function(state)
    {
        var loader = new AsyncLoader();
        loader.server = URL_SERVERS+'set-quick-info-state.php';
        loader.success = function(){};
        loader.params = SESS_ID+'&state='+state;
        loader.load();
    },



});

