window.lightBox = new Object();
(function($) {
	var lbIndex = 0;
	function LightBox(dest) {
		this.videoPlaying = false;
		this.container = null, boxout = null, overlay = null;

		this.__construct = function() {
			// Create lightbox layers
			// Top: Div to hold them all
			// 	|-> Boxout div (covers whole page)
			//	|-> Lightbox
			//    |-> Close
			//	  |-> Video
			//	    |-> Flash Object
			var lightbox = $('<div id="LightBox-' + lbIndex++ + '"></div>')
					.css('display', 'none');
			this.boxout = $('<div onclick="window.lightBox.stop();"></div>')
					.css({
							position : 'absolute',
							top : 0,
							left : 0,
							width : '100%',
							zIndex : 1000,
							background : '#777777',
							opacity : 0
					})
					.appendTo(lightbox);
			this.overlay = $('<div></div>')
					.css( {
						background : '#FFFFFF',
						border : '1px solid',
						position : ($.browser.msie && $.browser.version == '6.0') ? 'absolute' : 'fixed',
						top : '10em',
						zIndex : 1100,
						left : '50%',
						width : 'auto'
					})
					.append(
							'<div><a href="#" onclick="window.lightBox.stop(); return false;">Close</a></div>')
					.css( {
						textAlign : 'center',
						paddingRight : '1em',
						paddingTop : '0.5em'
					})
					.appendTo(lightbox);
			this.overlay.append('<div class="video"></div>');
			this.container = lightbox;
			
			var _this = this;
			
			// Add the layers to the body only when document is ready
			// Prevents IE 'operation aborted' error
			$(function() {
				lightbox.appendTo('body');
				_this.boxout.css('height', $('body').height());
			});
		}

		/**
		 * Plays the specified video
		 */
		this.play = function(video) {
			if (this.videoPlaying)
				return;

			this.videoPlaying = true;

			this.container.show();
			this.boxout.animate( {
				opacity : 0.8
			}, 750);
			this.overlay.animate( {
				height : '420px',
				marginLeft : '-259px',
				width : '518px'
			}, 1000, null, function() {
				$(this).find('.video').html(
						'<center><div id="video"></div></center>');
				swfobject.embedSWF(video, "video", "518", "380", "8.0.0");
			});
		};

		/**
		 * Stops the currently running video and hides lightbox layers
		 */
		this.stop = function() {
			if (!this.videoPlaying)
				return;

			this.videoPlaying = false;
			var _this = this;
			_this.overlay.find('.video').html('');
			_this.overlay.animate( 
				{opacity : 0}, 500, null, 
				function() {
					$(this).css({
						opacity : 1
					});
				}
			);
			this.boxout.animate( 
				{opacity : 0}, 500, null, 
				function() {
					_this.container.hide();
					_this.overlay.css( {
						height : '0px',
						marginLeft : '0px',
						width : '0px'
					});
				}
			);
		} /* end function */

		this.__construct();
	}

	window.lightBox = new LightBox();
})($jQ132);