var Msg = new Class({
   
    opt: function(id, opt) {
        this.opt = {
			msgHTML: '',
			msgType: 'success',
            successColor1: '2C801D',
            successColor2: '216015',
            warningColor1: '1e5b8d',
            warningColor2: '3676aa',
			errorColor1: 'FF0000',
			errorColor2: 'CC0000',
			colorChangeDuration: 600,
			autoHide: true,
			hideDelay: 7000,
			hideDuration: 500,
			onStartPosition:true,
			msgStyle: {
				paddingTop: '4px',
				height: '16px',
				color: '#FFFFFF',
				textAlign: 'center',
				border: '1px inset'				
			}
        };
        this.id = $(id);
		this.newStyle = Object.extend(this.opt.msgStyle, opt.msgStyle || {});
        Object.extend(this.opt, opt || {});
    },
   
    initialize: function(id, opt) {
        this.opt(id, opt);
        this.create();   
    },
	
	hideMsg: function() {
		this.hideEffect.toggle();
	},
	
	cycleColor: function() {
		var msgColorStart;
		var msgColorEnd;
		if (this.opt.msgType == 'error' ) {
			msgColorStart = this.opt.errorColor1;
			msgColorEnd = this.opt.errorColor2;
		} else if (this.opt.msgType == 'warning') {
			msgColorStart = this.opt.warningColor1;
			msgColorEnd = this.opt.warningColor2;
		} else {
			msgColorStart = this.opt.successColor1;
			msgColorEnd = this.opt.successColor2;
		}
		if (this.opt.onStartPosition) {
			try {this.colorFX.start(msgColorStart, msgColorEnd);} catch(e) {};
		} else {
			try {this.colorFX.start(msgColorEnd, msgColorStart);} catch(e) {};
		}
		this.opt.onStartPosition = !this.opt.onStartPosition;
	},
	
	removeFX: function() {
		this.colorFX.stop();
		this.colorFX = null;
		this.hideEffect.stop();
		this.hideEffect = null;
	},
   
    create: function() {
		this.id.setStyles(this.newStyle);
		this.id.setHTML(this.opt.msgHTML);
		
		if (this.opt.autoHide) {
			this.myTimer = function() {
				this.hideMsg();
			}.bind(this).delay(this.opt.hideDelay);
			
			this.hideEffect = new Fx.Slide(this.id, {
				duration: this.opt.hideDuration, 
				transition: Fx.Transitions.sineInOut, 
				onComplete: function() {
					this.removeFX();
				}.bind(this)
			});
		}
		
		this.colorFX = new Fx.Style(this.id, 'background-color', {
			duration: this.opt.colorChangeDuration, 
			wait: false, 
			onComplete: function() {
				this.cycleColor();
			}.bind(this)
		});
		
		this.cycleColor();
		
    }
});