
/**************************************************************

	Script		: Overlay
	Version		: 1.2
	Authors		: Samuel birch
	Modified by : Michael Coleman
	Desc		: Covers the container with a semi-transparent layer.
	Licence		: Open Source MIT Licence

**************************************************************/

var Overlay = new Class({

	getOptions: function(){
		return {
			captions: false,
			caption: null,
			colour: '#000',
			opacity: 0.7,
			zIndex: 1,
			container: document.body,
			onClick: Class.empty
		};
	},

	initialize: function(options){
		this.setOptions(this.getOptions(), options);

		this.options.container = $(this.options.container);

		this.container = new Element('div').setProperty('id', 'OverlayContainer').setStyles({
			position: 'absolute',
			left: '0px',
			top: '0px',
			width: '100%',
			zIndex: this.options.zIndex
		}).injectInside(this.options.container);
/*
		this.iframe = new Element('iframe').setProperties({
			'id': 'OverlayIframe',
			'name': 'OverlayIframe',
			'src': 'javascript:void(0);',
			'frameborder': 1,
			'scrolling': 'no'
		}).setStyles({
			'position': 'absolute',
			'top': 0,
			'left': 0,
			'width': '100%',
			'height': '100%',
			'filter': 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)',
			'opacity': 0,
			'zIndex': 1
		}).injectInside(this.container);
*/
		this.overlay = new Element('div').setProperty('id', 'Overlay').setStyles({
			position: 'absolute',
			left: '0px',
			top: '0px',
			width: '100%',
			height: '100%',
			zIndex: 2,
			backgroundColor: this.options.colour
		}).injectInside(this.container);

		if(this.options.captions){
			this.overlay.innerHTML = "<table id='overlayTable'><tr><td id='overlayCaption'>" + this.options.caption + "</td></tr></table>";
			this.options.caption = $('overlayCaption');
		}
/* commented out by Michael on April 9,2009 was causing an error and isn't used
		this.container.addEvent('click', function(){
			this.options.onClick();
		}.bind(this));
*/
		//this.fade = new Fx.Style(this.container, 'opacity').set(0);
		this.position();

		window.addEvent('resize', this.position.bind(this));
	},

	position: function(){
		if(this.options.container == document.body){
			var h = window.getScrollHeight()+'px';
			this.container.setStyles({top: '0px', height: h});
		}else{
			var myCoords = this.options.container.getCoordinates();
			this.container.setStyles({
				top: (myCoords.top+1)+'px',
				height: myCoords.height+'px',
				left: myCoords.left+'px',
				width: myCoords.width+'px'
			});
		}
	},
	fadeIn: function(){
		//this.fade.start(0,this.options.opacity);
		this.container.fade(this.options.opacity);
	},
	fadeOut: function(){
		//this.fade.start(this.options.opacity,0);
		this.container.fade(0);
	},
	show: function(){
		this.container.setStyle('opacity',this.options.opacity);
	},

	hide: function(){
		this.container.setStyle('opacity',0);;
	},

	setCaption:function(text){
		this.options.caption.innerHTML = text;
	}


});
Overlay.implement(new Options);

/*************************************************************/
