/*
	title:	title of Confirm box
	msg:	message of Confirm box
	arrBtns:	array of objects
				text:	text of button
				id:	id of button
	fn:	function that will be call when user click a button. This function will receive id of clicked button
*/
var TransLayerClass = new Class({
	initialize: function(popupID, zIndex) {
		if (!zIndex || zIndex == null) {
			var zIndex = 1000;
		}
		
		// disable select box (fix IE)
		this.iframe = new Element('iframe');
		this.iframe.setStyles({
			filter:'alpha(opacity=0)',
			visibility: "hidden",
			position: 'absolute',
			border: "none",
			//"z-index": zIndex,
			top: 0,
			left: 0
		});
		
		// create transparent layer , include color (if needed)
		this.overlayDiv = new Element('div');
		this.overlayDiv.setStyles({
			filter:'alpha(opacity=0)',
			position: 'absolute',
			border: "none",
			//"z-index": zIndex,
			top: 0,
			left: 0
		});
		
		// change some style values of popup, make it movable
		this.popup = $(popupID);
		this.popup.setStyles({
			position: 'absolute',
			//"z-index": zIndex,
			top: -1000
		});
	},
	
	changeSize: function() {
		var width = window.getWidth();
		var height = window.getScrollHeight();
		
		if (height < document.body.clientHeight) {
			height = document.body.clientHeight;
		}
		
		this.iframe.setStyles({
			width: width,
			height: height
		});
		
		this.overlayDiv.setStyles({
			width: width,
			height: height
		});		
		
		var divWidth;
		//var divHeight;
		if (this.popup.currentStyle) {
			divWidth = this.popup.currentStyle['width'];
			//divHeight = this.dialogDiv.currentStyle['height'];
		} else if (window.getComputedStyle) {
			divWidth = document.defaultView.getComputedStyle(this.popup, null).getPropertyValue('width');
			//divHeight = document.defaultView.getComputedStyle(this.dialogDiv, null).getPropertyValue('height');
		}
		
		divWidth = parseInt(divWidth);
		if (isNaN(divWidth)) {
			divWidth = 0;
		}
		//divHeight = parseInt(divHeight);
		//alert(divWidth);
		
		if (height > window.getHeight()) {
			height = window.getHeight();
		}
		
		this.popup.setStyles({
			left: (window.getWidth() - divWidth) / 2 + window.getScrollLeft(),
			top: height / 4 + window.getScrollTop()
		});
	},
	
	hide: function() {
		window.transLayer = null;
		window.removeEvents('resize');
		window.removeEvents('scroll');
		
		try {
			this.iframe.remove();
			this.overlayDiv.remove();
			this.popup.setStyle('top', -1000);
		} catch (e) {};
	},
	
	show: function() {
		window.transLayer = this;
		window.addEvent('resize', function(){window.transLayer.changeSize()});
		window.addEvent('scroll', function(){window.transLayer.changeSize()});
		
		var body = $$('body')[0];
		this.iframe.injectInside(body);
		this.overlayDiv.injectInside(body);
		this.popup.injectInside(body);
		
		this.changeSize();
	}
});



