var FMTVOverlay = new Class({
		
		Implements: [Options, Events],
		
		options: {
			duration: 400,
			background: '#000',
			opacity: 0.4
		},
		
		overlay: null,
		isOpen: false,
		
		initialize: function(options) {
			this.setOptions(options);
		},
		
		__createOverlay: function() {
			
			if(this.overlay) {
				return true;
			}
			
			this.overlay = new Element('div', {
				'class': 'fmtvOverlay',
				'styles': {
					'background': this.options.background,
					'position': 'absolute',
					'top': 0,
					'left': 0,
					'z-Index': 9998,
					'opacity': 0
				},
				'tween': {
					'link': 'chain',
					'duration': this.options.duration,
					'onComplete': function() {
						if(!this.isOpen) {
							this.overlay.dispose();
						}
					}.bind(this)
				}
			});
			
		},
		
		show: function() {
			
			this.__createOverlay();
			
			var size = window.getScrollSize();
			this.overlay.setStyles({
				'width': size.x,
				'height': size.y
			});
			
			this.overlay.inject(document.body, 'bottom');
			this.isOpen = true;
			this.overlay.tween('opacity', this.options.opacity);
		},
		
		hide: function() {
			this.isOpen = false;
			this.overlay.tween('opacity', 0);
		}
		
});


window.addEvent('domready', function() {
	
	// check if there's content in the overlay banner container
	var has_content = false;
	$$('.overlay').each(function(overlay) {
		if (!has_content && overlay.getElement('.banner').getChildren().length > 2) {
			var myOverlay = new FMTVOverlay({ duration: 300, opacity: 0.5 });

			overlay.setStyles({
				display: 'block', 
				position: 'absolute', 
				'margin-left': '-315px', 
				left: '50%', 
				top: '200px', 
				'z-index': '9999'
			});

			myOverlay.show();
			var closeBtn = new Element('div', { 'class': 'overlay-close-btn' });
			closeBtn.inject(overlay, 'top');

			closeBtn.addEvent('click', function() {
				myOverlay.hide();
				overlay.setStyle('display', 'none');
			});
			has_content = true;
		}
	});
	
});
