
overlayMessage = Class.create();
overlayMessage.prototype = {

	initialize : function () {
		
		this.overlayDiv = DC("DIV");
		this.overlayDiv.className = "overlay";
		document.body.appendChild(this.overlayDiv);
		if (document.all) this.overlayDiv.style.position = 'absolute';
		styler.stylize(this.overlayDiv, 'wd:1px;hg:1px;dis:none;zi:100999');
		
		this.messageDiv = DC("DIV");
		styler.stylize(this.messageDiv, 'dis:none');
		styler.stylize(this.messageDiv, 'boT:3px solid #A2041E;boB:3px solid #A2041E;bg:#FFF;cl:#096FC5;fw:bold;ta:center');
		styler.stylize(this.messageDiv, 'pd:5px 15px;mrg:0% 10%;ps:absolute;T:0px;L:0px;zi:199999;wd:80%');
		document.body.appendChild(this.messageDiv);
		
		this.fadeOutFunc = this.fadeOut.bind(this);
	},
	
	showMessage : function (text) {
		
		this.messageDiv.innerHTML = text;
		this.showOverlay();
		
		this.step = 20;
		this.fadeOut();
		
	},
	
	showConfirm : function (question, func) {
		
		
		this.showOverlay();
		this.messageDiv.innerHTML = question;
		
		var div = document.createElement('DC');
		div.className = "confimationBox";
		
		var span = document.createElement('span');
		Event.observe(span, "mousedown", this.onYes.bind(this));
		span.innerHTML = "YES";
		span.className = "yesButton";

		div.appendChild(span);

		var span = document.createElement('span');
		Event.observe(span, "mousedown", this.onNo.bind(this));
		span.innerHTML = "NO";
		span.className = "noButton";
		
		div.appendChild(span);

		this.messageDiv.appendChild(div);

		this.confirmCallBack = func || this.noConfirmThanks.bind(this);		
		
	},
	
	noConfirmThanks : function () {
		
	},
	
	onYes : function () {
		this.hideOverlay();
		this.confirmCallBack(true);
	},
	
	onNo : function () {
		this.hideOverlay();
		this.confirmCallBack(false);
	},
	
	fadeOut : function () {
		
		this.step-=2;
		if (this.step <= 0) {
			this.hideOverlay();
		} else {
			var currentAlpha = Math.min(100, this.step * 10);
			makeAlpha(this.overlayDiv, currentAlpha * 0.6);
			makeAlpha(this.messageDiv, currentAlpha);	
			window.setTimeout(this.fadeOutFunc.bind(this), 125);
		}
		
	},
	
	hideOverlay : function () {
		
		styler.stylize(this.overlayDiv, 'dis:none');
		styler.stylize(this.messageDiv, 'dis:none');
			
	},
	
	showOverlay : function () {
		
		var pagesize = this.getPageSize();
		var windowWidth = pagesize[0];
		var windowHeight = pagesize[1]+80;
		
		var t = this.getPageScroll() + pagesize[3]/2 - 50;
		styler.stylize(this.overlayDiv, 'wd:'+windowWidth+'px;hg:'+windowHeight+'px;dis:block');
		styler.stylize(this.messageDiv, 'dis:block;T:'+t+'px');
		
		var currentAlpha = 100;
		makeAlpha(this.overlayDiv, currentAlpha * 0.6);
		makeAlpha(this.messageDiv, currentAlpha);	
			
	},
	
	getPageSize : function (){
	
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}


		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	},
	
	getPageScroll : function (){

		var yScroll;

		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}

		return yScroll;
	}
	
};