TextFader = Class.create();
TextFader.BG_ID = 'bgFilter';
TextFader.MESSAGE_ID = 'msgFront';
TextFader.FADE_DELAY = 40;
TextFader.OPACITY_STEP_SIZE = .22;
TextFader.OPACITY_MAX = .85;
TextFader.prototype = {
	varName: null,
	bgEl: null,
	messageEl: null,
	opacity: null,
	fadeInterval: null,
	form: null,
	submittable: false,
	
	initialize: function(varName, formId) {
		this.varName = varName;
		this.bgEl = $(TextFader.BG_ID);
		this.messageEl = $(TextFader.MESSAGE_ID);
		this.opacity = 0;
		this.form = $(formId);
	},
	
	setBgOpacity: function(opacity) {
		this.opacity = opacity;
		this.bgEl.style.opacity = this.opacity;
		this.bgEl.style.filter = 'alpha(opacity=' + this.opacity*100 + ')';
	},
	
	fadeBgInStep: function () {
		var opacity = this.opacity + TextFader.OPACITY_STEP_SIZE;
		this.setBgOpacity(opacity)
		if (opacity >= TextFader.OPACITY_MAX) {
			clearInterval(this.fadeInterval);
		}
	},
	
	getBgDimensions: function() {
		var width = 0; height = 0;
	 	if (document.documentElement && document.documentElement.scrollHeight > 0 && document.body && document.body.scrollHeight > 0) {
		 	height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
			width = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
		}
	 	return [width, height];
	},
	
	showMessage: function() {
		var bgDimensions = this.getBgDimensions();
		this.bgEl.style.width = bgDimensions[0] + 'px';
		this.bgEl.style.height = bgDimensions[1] + 'px'; 
		
		this.setBgOpacity(0);
		this.bgEl.show();
		this.fadeInterval = window.setInterval(this.varName+'.fadeBgInStep()', TextFader.FADE_DELAY);
		this.messageEl.show();
	},
	
	acceptMessage: function () {
		this.bgEl.hide();
		this.messageEl.hide();
		this.submittable = true;
		if (this.form) this.form.submit();
		return true;
	},
	
	rejectMessage: function () {
		this.bgEl.hide();
		this.messageEl.hide();
		this.submittable = false;
		return false;
	}
	
};