/**
 * avisosHelper, Clase para realizar mensajes gráficos de aviso en una pantalla
 *
 * Librería de uso general que permite el mostrar tres diferentes tipos de avisos
 * en una pantalla, pudiendo ser: 1) Avisos de éxito, 2) Avisos de fallos o "Warnings"
 * y 3) Avisos de Error
 * @author David Osiris Magallón Chávez
 * @version 1.0
 */
var avisosHelper = new Class({
    Implements: [Options, Events, Chain],

    options: {
        divWarning: "warning",
        divAviso: "aviso",
        divError: "error",
        duracionAnimacion: 'short',
        tiempoDespliegue: 2500
    },

    divAviso: null,
    divWarning: null,
    divError: null,

    morphAviso: null,
    morphWarning: null,
    morphError: null,

    bandAviso: false,
    bandWarning: false,
    bandEror: false,

    timerAviso: null,
    timerWarning: null,
    timerError: null,

    initialize: function(options){
        this.setOptions(options);

        this.divAviso = $(this.options.divAviso);
        this.divWarning = $(this.options.divWarning);
        this.divError = $(this.options.divError);

        this.divAviso.addClass('divAviso');
        this.divWarning.addClass('divWarning');
        this.divError.addClass('divError');

        var opciones = {duration:this.options.duracionAnimacion, link:'cancel'};

        this.morphAviso = new Fx.Morph(this.options.divAviso,opciones);
        this.morphWarning = new Fx.Morph(this.options.divWarning,opciones);
        this.morphError = new Fx.Morph(this.options.divError,opciones);

        this.morphAviso.set('.divHide');
        this.morphWarning.set('.divHide');
        this.morphError.set('.divHide');
    },

    /**
     * Muestra el div de Aviso con el mensaje que se le pase y lo esconde
     * @param mensaje El mensaje a mostrar
     */
    showAvisoTiempo: function(mensaje){
        if(this.timerAviso!=null){
            $clear(this.timerAviso);
        }
        this.showAviso(mensaje);
        this.timerAviso = this.hideAviso.delay(this.options.tiempoDespliegue,this);
    },

    /**
     * Muestra el div de Aviso con el mensaje que se le pase
     * @param mensaje El mensaje a mostrar
     */
    showAviso : function(mensaje){
        this.divAviso.set('text',mensaje);
        this.morphAviso.start('.divAvisoShow');

        if(this.divWarning.getStyle('height')!=0){
            this.morphWarning.start('.divHide');
        }
        if(this.divError.getStyle('height')!=0){
            this.morphError.start('.divHide');
        }
    },

    /**
     * Esconde el aviso
     */
    hideAviso: function(){
        if(this.divAviso.getStyle('height')!=0){
            this.morphAviso.start('.divHide');
        }
    },

    /**
     * Muestra el div de Warning con el mensaje que se le pase y lo esconde
     * @param mensaje El mensaje a mostrar
     */
    showWarningTiempo: function(mensaje){
        if(this.timerWarning!=null){
            $clear(this.timerWarning);
        }
        this.showWarning(mensaje);
        this.timerWarning = this.hideWarning.delay(this.options.tiempoDespliegue,this);
    },

    /**
     * Muestra el div de Warning con el mensaje que se le pase
     * @param mensaje El mensaje a mostrar
     */
    showWarning: function(mensaje){
        this.divWarning.set('text',mensaje);
        this.morphWarning.start('.divWarningShow');

        if(this.divAviso.getStyle('height')!=0){
            this.morphAviso.start('.divHide');
        }
        if(this.divError.getStyle('height')!=0){
            this.morphError.start('.divHide');
        }

    },

    /**
     * Esconde el div de Warning
     */
    hideWarning: function(){
        if(this.divWarning.getStyle('height')!=0){
            this.morphWarning.start('.divHide');
        }
    },

    /**
     * Muestra el div de Error con el mensaje que se le pase y lo esconde
     * @param mensaje El mensaje a mostrar
     */
    showErrorTiempo: function(mensaje){
        if(this.timerError!=null){
            $clear(this.timerError);
        }
        this.showError(mensaje);
        this.timerError = this.hideError.delay(this.options.tiempoDespliegue,this);
    },

    /**
     * Muestra el div de Error con el mensaje que se le pase
     * @param mensaje El mensaje a mostrar
     */
    showError: function(mensaje){
        this.divError.set('text',mensaje);
        this.morphError.start('.divErrorShow');

        if(this.divWarning.getStyle('height')!=0){
            this.morphWarning.start('.divHide');
        }
        if(this.divAviso.getStyle('height')!=0){
            this.morphAviso.start('.divHide');
        }

        //this.hideError().wait(1000);
    },

    /**
     * Esconde el Error
     */
    hideError: function(){
        if(this.divError.getStyle('height')!=0){
            this.morphError.start('.divHide');
        }
    }

});
