var embedVideo = function(url) {
	var matches = url.match(/v=([^&]+)/);
	var videoId = matches[1];
	if (!videoId) return;
	var id = 'video-' + videoId;
	
	var html =
	'<div id="' + id + '">'+
		'<a href="javascript:void(0)" onclick="playVideo(this)">'+
			'<img src="http://img.youtube.com/vi/' + videoId + '/default.jpg" border="0" width="103" />'+
		'</a>'+
	'</div>';
	document.write(html);
};
var playVideo = function(anchor) {
	var id = anchor.parentNode.id;
	var videoId = id.split('-')[1];
	var width = 580, height = 340;
	var flashvars = {};
	var param = { allowScriptAccess: 'always' };
	var link = 'http://www.youtube.com/v/' + videoId + '?enablejsapi=1&playerapiid=ytplayer&autoplay=1';
	var domId = 'ytplayer-ct';

	// disable scrolling
	document.body.style.overflow = 'hidden';

	// create the black-out effect
	document.body.style.position = 'relative';
	var dom = document.createElement('DIV');
	dom.id = 'black-out'
	dom.className = 'black-out';
	document.body.appendChild(dom);

	// create the video player
	dom = document.createElement('DIV');
	dom.id = 'video-player-ct';
	dom.className = 'video-player-ct';
	dom.innerHTML =
	'<div class="video-player-top">'+
		'<div class="video-player-close" onclick="closeVideo()"></div>'+
	'</div>'+
	'<div class="video-player-wrap">'+
		'<div id="' + domId + '"></div>'+
	'</div>';
	document.body.appendChild(dom);
	dom = $(dom);

	var body = $(document.body);
	var bodyHeight = body.getSize().y;
	var bodyScrollTop = body.getScroll().y;
	var bodyScrollHeight = body.getScrollSize().y;
	var domHeight = dom.getSize().y;
	dom.setStyle('top', (domHeight - bodyScrollHeight) + ((bodyHeight - domHeight) / 2 + bodyScrollTop) + 'px');

	swfobject.embedSWF(
		link,
		domId,			// dom element id
		width,
		height,
		'9.0.0',		// flash version
		basePath + '/scripts/expressInstall.swf',	// express install location
		flashvars,		// flashvars
		param			// param
	);
};
var closeVideo = function() {
	var dom = $('video-player-ct');
	document.body.removeChild(dom);
	
	dom = $('black-out');
	document.body.removeChild(dom);
	
	// restore body style
	document.body.style.overflow = 'auto';
	document.body.style.position = '';
};
