var MessageBox = new Class({
    options: {
        delay: 1,
        onShow: $empty,
        FxOptions: {},
        width: 200
    },
    initialize: function(msg, type, options) {
        $extend(this.options, options);
        this.createBox(msg, type);

    },
    createBox: function(msg, type) {
        var msgCLIP = /<h4[^>]*>([\s\S]*?)<\/h4>/;
        var tempmsg = msg;
        if (tempmsg.test(msgCLIP)) {
            tempmsg.replace(msgCLIP,
            function() {
                msg = arguments[1];
                return '';
            });
        }
        var box = new Element('div').setStyles({
            'position': 'absolute',
            'visibility': 'hidden',
            'width': this.options.width,
            'opacity': 0,
            'zIndex': 65535
        }).inject(document.body);
        var obj = this;
        
		var el = box.addClass(type).setHTML("<h4>", msg, "</h4>").amongTo(window);
		el.addEvent("click",function(){el.remove()});
        (function(){
            el.effect('opacity').start(1,0).chain(function(){
                el.remove();
                if (obj.options.onShow) {
                    obj.options.onShow.apply(obj, [obj]);
                }
            });
        }).delay(this.options.delay*1000)
        return box;
    }

});

MessageBox.success = function(msg, options) {
    return new MessageBox(msg || "操作成功!", 'success', options);
};
MessageBox.error = function(msg, options) {
    return new MessageBox(msg || "操作失败!", 'error', options);
};
MessageBox.show = function(msg, options) {
    if (msg.contains('failedSplash')) {
        return new MessageBox(msg || "操作失败!", 'error', options);
    }
    return new MessageBox(msg || "操作成功!", 'success', options);

};