var notice = {
    hide_interval: 3, // seconds
    notice_types: ['success', 'message', 'warning', 'error'],
    notices_list: {},

    add : function (ntype, str) {
        if (typeof this.notices_list[ntype] == 'undefined') {
            this.notices_list[ntype] = [];
        }
        this.notices_list[ntype].push(str);
    },

    clear: function() {
        this.notices_list = {};
        $('.noticebox').remove();
    },
    show: function(is_flash) {
        if (!this.notices_list) {
            return;
        }
        // create notices box
        for (var ni in this.notice_types) {
            var ntype = this.notice_types[ni];
            if (typeof this.notices_list[ntype] != 'undefined') {
                // check noticsbox ntype exist
                var noticebox = $('div[class="noticebox ' + ntype +'"]');
                if (noticebox.length === 0) {
                    noticebox = $('<div class="noticebox ' + ntype + '"></div>');
                }
                var list = this.notices_list[ntype];
                for (var nj in list) {
                    if (typeof(list[nj]) != 'function') {
                        noticebox.append('<div class="notice">' + list[nj] +'</div>');
                    }
                }

                $("#cont").prepend(noticebox);
            }
        }
        this.notices_list = {};

        // hide notices after this.err_hide_interval seconds
        if (typeof is_flash == 'undefined' || is_flash === true) {
            setTimeout(function() {
                $('.noticebox').hide('fast').remove();
            }, this.hide_interval*1000);
        }
    } // end show
};