  
Atlantis_Web_UI_LooksBlock_Manager = new Class({

    Extends: Atlantis_Web_UI_Control_Base,

    _control: null,
    _fadeDuration: null,    

    _doInit: function(config, partial)
    {
        this._control = $(this._id);
        
        this._fadeDuration = config.fadeDuration;
        
        if (this._control && config.fadeOut) {
        
            $H(config.messages).each(function(value, key) {
            
                var message = this._control.getElements('.' + key);
                if (message && value.lifetime) {
                    // this message exists - lets appy a delayed fade to it                                    
                    this._startFadeOut.delay(parseInt(value.lifetime), this, message);                    
                }
                                
            }.bind(this));
        }
    },
    
    _startFadeOut: function(message)
    {
        if (this._messageCount() > 1) {

            message.fade(0);
        
            new Fx.Tween(message, {
                property: 'height',
                duration: this._fadeDuration,
                onComplete: function(ele) { 
                    ele.dispose(); 
                    this._disposeIfNoMessages();  
                }.bind(this)
            }).start(0);
        }
        else {
        
            new Fx.Tween(this._control, {
                property: 'opacity',
                duration: this._fadeDuration,
                onComplete: function(ele) { 
                    ele.dispose(); 
                }.bind(this)
            }).start(0);
                      
        }
    
    },
    
    _messageCount: function()
    {
        return this._control.getElements('li').length;
    },
    
    _disposeIfNoMessages: function()
    {
        if (!this._messageCount()) {
            this._control.dispose();        
        }
    
    }
});

Atlantis_Web_UI_Control_Manager_Instance.register(
    'Atlantis_Web_UI_LooksBlock', 
    'Atlantis_Web_UI_LooksBlock_Manager');
