/* Video Popup Script: handles links (A) with rel="video"  to open videolinks in a new popup screen*/

/* Close window function: closes window when popup allready (still open)  Needed for focussing on the opened video*/
function closeWin(){
	if (document.newWindow != null){
		if(!document.newWindow.closed)
			document.newWindow.close();
	}
}


/* The popup function itsellf that opens a new window */
 function popUpWin(url){
	closeWin();
	var w = 540;
	var h = 432;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	tools = "resizable=no,toolbar=no,location=no,scrollbars=no,width="+w+",height="+h+",left="+winl+",top="+wint+"";
	document.newWindow = window.open(url, 'newWin', tools);
	document.newWindow.focus();
}

/* The popup function that gives sizes and other variables to the popup anbd cancels the normal link action */
function doPopUp(e)
{	
	//call the popup script
	popUpWin(this.href);
	//cancel the default link action if pop-up activated
	if (window.event) 
	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	} 
	else if (e) 
	{
		e.stopPropagation();
		e.preventDefault();
	}
	return false;
}

/* Find links who have a rel=video to add a Popup handler */
findPopUps = function()
{
	var popups = document.getElementsByTagName("a");
	for (i=0;i<popups.length;i++)
	{
		if (popups[i].rel.indexOf("video")!=-1)
		{
			
			// attach popup behaviour
			popups[i].onclick = doPopUp;
			// add info to title attribute to alert fact that it's a pop-up window
			popups[i].title = "Videoplayer [Opent in pop-up scherm]";
		}
	}
}

/* Load actions when page is loaded */
//addEvent(window, 'load', findPopUps, false);
window.onload.actions.push(findPopUps);
