/*
---
description: MooBanner

license: MIT-style

authors:
- Josiel Rocha (josiel.rocha@gmail.com)

requires
- core/1.3: '*'

provides: [MooBanner]

---
*/

(function($) {
    this.MooBanner = new Class({
        Implements: [Options, Events],
        
        options: {
            id: 'moobanner',
            conteudo: '<p>Nenhum conteúdo foi definido</p>',
            autofechar: true,
            tempo: 10,
						url: '#'
        },
        
        initialize: function(options) {
            this.setOptions(options);

            this.desenharBox();
            this.adicionarBotoes();
            
            if(this.options.autofechar) {
                (function() {this.fechar();}).delay((this.options.tempo * 1000), this);
            }
            
            this.fireEvent('onComplete');
        },
        
        desenharBox: function() {
            this.box = new Element('div', {
                id: this.options.id,
				'class': 'MooBanner'
            }).inject(document.body);
            
            this.containerConteudo = new Element('div', {
                'class': 'conteudo',
                html: this.options.conteudo
            }).inject(this.box);
			
			this.containerConteudo.addEvent('mousedown', function(ev) {
				location.href = this.options.url;
			}.bind(this));
        },

        adicionarBotao: function(titulo, evento) {
            if(!this.containerBotoes) {
                this.containerBotoes = new Element('div', {
                    'class': 'botoes'
                }).inject(this.box);    
            }
            
            this.botoes = {};
            this.botoes[titulo] = (new Element('a', {
                html: titulo,
                href: 'javascript:void(0);',
                events: {
                    click: (evento).bind(this)
                }
            }).inject(this.containerBotoes));
        },

        adicionarBotoes: function() {
            this.options.botoes.each(function(botao, index) {
                this.adicionarBotao(botao.titulo, botao.evento);
            }, this);
        },

        fechar: function() {
            this.box.dispose();
        }
    });
})(document.id);

/*
// Utilização

$('fire').addEvent('click', function(ev) {
    if(ev) ev.stop();
    new MooBanner({
        botoes: [
            {titulo: 'Fechar', evento: function() {this.fechar();}}
        ],
        conteudo: '<img src="http://1.bp.blogspot.com/-_7CiOXWPemA/TcmNjbuV4tI/AAAAAAAAAlc/vrju3A3NIC4/s1600/tux+vader.png"/>',
        tempo: 5
    });
});
*/

