var popupWidth, popupHeight, originalDocumentWidth;
		
		function showPopup(title, flashUrl, width, height)
		{
			var elSource = document.getElementById('popupSource');
			var el = document.getElementById('popupMask');
			var elContent = document.getElementById('popupContent');
		
			// Store input dimensions
			popupWidth = width;
			popupHeight = height;
			originalDocumentWidth = document.documentElement.scrollWidth;
			
			// Copy source html into elContent
			elContent.innerHTML = elSource.innerHTML.split("<!--@Title-->").join(title);
			
			// Load SWF
			if(flashUrl.indexOf('swf') > 0)
			{
				var so = new SWFObject(flashUrl + "?rndm=" + Math.round(1000*Math.random()), "flvplayer", width, height, "8", "#FFFFFF");
				so.addParam("wmode","transparent");
				so.write("swfFlvPlayer");
			}
			else
			{
				var so = new SWFObject("/Files/Filer/flv/Player.swf?rndm=" + Math.round(1000*Math.random()), "flvplayer", width, height, "8", "#FFFFFF");
				so.addParam("wmode","transparent");
				so.addParam("salign","tl");
				so.addVariable("skinName","/Files/Filer/flv/SteelExternalAll.swf");
				so.addVariable("streamHeight","350");
				so.addVariable("streamName",flashUrl);
				so.write("swfFlvPlayer");
			}
			
			// Set dimensions
			setPopupDimensions(el, elContent, width, height);
			
			// Set visibility
			el.style.display = '';
			elContent.style.display = '';
			
			// Detect resizes
			window.onresize = setPopupDimensions;
			window.onscroll = setPopupDimensions;
			StopFlashVideo();
		}
		
		function setPopupDimensions(el, elContent)
		{	
			var elSource = document.getElementById('popupSource');
			var el = document.getElementById('popupMask');
			var elContent = document.getElementById('popupContent');
			
			// Get stored dimensions
			width = popupWidth;
			height = popupHeight;
		
			// The SWF needs some extra margins
			width = width + 12;
			height = height + 2;
			
			// Get scroll position
			var scrollY = document.documentElement.scrollTop;
			var scrollX = document.documentElement.scrollLeft;
			
			// Get document dimensions
			var documentHeight = document.body.clientHeight > document.documentElement.clientHeight ? document.body.clientHeight : document.documentElement.clientHeight;
			var documentWidth = originalDocumentWidth < document.documentElement.scrollWidth ? originalDocumentWidth : document.documentElement.scrollWidth;
			
			// Get browser dimensions
			if(self.innerHeight)
				var innerHeight = self.innerHeight;
			else
				var innerHeight = document.documentElement.clientHeight;
			var innerWidth = document.documentElement.clientWidth < document.body.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
			
			if(documentWidth < innerWidth)
				documentWidth = innerWidth;
			
			// Set dimensions of background mask
			el.style.width = documentWidth + 'px';
			el.style.height = documentHeight + 'px';
			el.style.top = 0;
			el.style.left = 0;
			
			// Set dimensions of content
			elContent.style.width = width + 'px';
			elContent.style.height = height + 'px';
			elContent.style.top = (scrollY + innerHeight / 2 - height / 2 - 48 / 2) + 'px';
			elContent.style.left = (scrollX + innerWidth / 2 - width / 2) + 'px';
		}
		
		function cancelPopup()
		{
			// Hide view
			document.getElementById('popupMask').style.display = 'none';
			document.getElementById('popupContent').style.display = 'none';
			document.getElementById('swfFlvPlayer').innerHTML = '';
			
			// Don't handle resizes
			window.onresize = null;
			window.onscroll = null;
			
			StartFlashVideo();
		}
		
		function StopFlashVideo()
		{
			thisMovie("video_bakery").stopVideo();
		}
		
		function StartFlashVideo()
		{
			thisMovie("video_bakery").startVideo();
		}
		
		function thisMovie(movieName) {
			if (navigator.appName.indexOf("Microsoft") != -1) {
				return window[movieName]
			}
			else {
				return document[movieName]
			}
		}
