var launchVideo = new function()
{
	var videoContainer;
	var centerX = (window.innerWidth || document.body.offsetWidth) / 2;
	var centerY = (window.innerHeight || document.body.offsetHeight) / 2;
	var videoWidth = 375;
	var videoHeight = 250;
	var videoCenterX = videoWidth / 2;
	var videoCenterY = videoHeight / 2;

	this.initialise = function()
	{
	  var links = document.getElementsByTagName('a');
		for(var i = 0; i < links.length; i++)
		  if(links[i].className == 'video')
		  {
		    links[i].onclick = function(){return onclickHandler(this)};
		  }
	}

	function onclickHandler(link)
	{
	  var div = document.createElement('div');
		link.parentNode.appendChild(div);
	  var iframe = document.createElement('iframe');
		div.appendChild(iframe);
		var button = document.createElement('button');
		div.appendChild(button);
		div.className = 'videoPlayer';
		
		with(div.style)
		{
		  top = centerY - videoCenterY + 'px';
		  left = centerX - videoCenterX + 'px';
		}

		iframe.src = link.href;
		
		button.appendChild(document.createTextNode('X'));
		button.title = 'Close';
		button.onclick = closeVideo;
		
		videoContainer = div;
		
	  return false;
	}

	function closeVideo()
	{
	  videoContainer.parentNode.removeChild(videoContainer);
	}
}

launchVideo.initialise();
