var popupScreen = null;
var popupTitle = null;
var popupWindow = null;
var popupContent = null;

function centerPositionInScreenWithSize(width, height)
{
	var size = {};

	if (window.innerWidth) {
		size.left = (window.innerWidth - width) / 2;
		size.top = (window.innerHeight - height) / 2;
	}
	else {
		size.left = (document.documentElement.clientWidth - width) / 2;
		size.top = (document.documentElement.clientHeight - height) / 2;
	}

	return size;
}

function initializePopup()
{
	if (!popupScreen) {
		popupWindow = document.createElement("div");
		popupContent = document.createElement("div");

		popupTitle = document.createElement("h1");
		popupTitle.appendChild(document.createTextNode(""));

		var closeButton = popupTitle.appendChild(document.createElement("a"));
		closeButton.setAttribute("id", "popup-close");
		closeButton.setAttribute("href", "#");
		closeButton.onclick = closePopup;

		popupWindow.appendChild(popupTitle);
		popupWindow.appendChild(popupContent);
		popupWindow.setAttribute("id", "popup-window");
		popupContent.setAttribute("id", "popup-content");

		popupScreen = document.createElement("div");
		popupScreen.setAttribute("id", "popup-screen");
		popupScreen.appendChild(popupWindow);

		document.getElementsByTagName("body").item(0).appendChild(popupScreen);
	}
	//document.getElementById('scale-content').style.display = 'none';
}

function openPopup(title, swfUrl, width, height, vars)
{
	initializePopup();

	popupContent.innerHTML = "";
	var popupData = popupContent.appendChild(document.createElement("div"));
	popupData.setAttribute("id", "popup-data");

	swfobject.embedSWF(swfUrl, "popup-data", "100%", "100%", "9.0.0", "expressInstall.swf", vars, {
		menu: "false",
		allowScriptAccess: "always",
		wmode: "transparent"
	}, {});

	var centerPosition = centerPositionInScreenWithSize(width, height);

	popupTitle.replaceChild(document.createTextNode(title), popupTitle.firstChild);
	popupWindow.style.left = centerPosition.left + "px";
	popupWindow.style.top = (centerPosition.top - 40) + "px";
	popupWindow.style.width = width + "px";
	popupContent.style.height = height + "px";
	popupScreen.style.display = "block";
}

function openPopupWithContent(title, content, width, height)
{
	initializePopup();

	var centerPosition = centerPositionInScreenWithSize(width, height);

	popupContent.innerHTML = content;
	popupTitle.replaceChild(document.createTextNode(title), popupTitle.firstChild);
	popupWindow.style.left = centerPosition.left + "px";
	popupWindow.style.top = (centerPosition.top - 40) + "px";

	popupWindow.style.width = width + "px";
	popupContent.style.height = height + "px";
	popupScreen.style.display = "block";
}
function openPopupWithVideo(title, video, width, height)
{
	initializePopup();

	var centerPosition = centerPositionInScreenWithSize(width, height);
	
	dom_link = document.createElement("a");
	dom_link.href = video;
	dom_link.style.display="block";
	dom_link.style.width=width+"px";
	dom_link.style.height=height+"px";
	dom_link.id = "playerBig";
	popupContent.appendChild(dom_link);

	popupTitle.replaceChild(document.createTextNode(title), popupTitle.firstChild);
	popupWindow.style.left = centerPosition.left + "px";
	popupWindow.style.top = (centerPosition.top - 40) + "px";
	popupWindow.style.width = width + "px";
	popupContent.style.height = height + "px";
	popupScreen.style.display = "block";

	 flowplayer("playerBig", "fileadmin/videos/flowplayer/flowplayer-3.1.0.swf", { 
	     clip:  { 
	       autoPlay: true, 
	       autoBuffering: true 
	     },
	     plugins:  { 
	       controls: {
	         all:false, 
	         scrubber:true, 
	         play:true, 
	         mute:true,
		 volume:true,
	         autoHide: 'always'
	       }
	     }
	}); 
}


function closePopup(event)
{
	if (popupScreen) {
		document.getElementsByTagName("body").item(0).removeChild(popupScreen);
		popupScreen = null;
		//popupContent.innerHTML = "";
		//popupScreen.style.display = "none";
	}

	//document.getElementById('scale-content').style.display = 'block';

	return false;
}

function switchTab(tabName)
{
	var tabOlsen = document.getElementById('tab-olsen');
	var tabTwitter = document.getElementById('tab-twitter');
	var tabRSS = document.getElementById('tab-rss');
	
	tabOlsen.style.display = "none";
	tabTwitter.style.display = "none";
	tabRSS.style.display = "none";
	
	switch (tabName) {
		case 'tab-olsen':
			tabOlsen.style.display = "block";
			break;
		case 'tab-twitter':
			tabTwitter.style.display = "block";
			break;
		case 'tab-rss':
			tabRSS.style.display = "block";
			break;
	}
}
