/**
 * JPX Class.
 */
function jpxLoadingPage() { }
jpxLoadingPage.appId           = '';
jpxLoadingPage.productId       = '';
jpxLoadingPage.jpxId           = '';
jpxLoadingPage.minFlashVersion = '9.0.124';

jpxLoadingPage.flashVars       = new Object;
jpxLoadingPage.flashParams     = new Object;
jpxLoadingPage.divflashProductSetter = 'flashProductSetter';
jpxLoadingPage.isInitialized   = false;

jpxLoadingPage.launchActivity = function (throw_error) 
{
	jpxDebug.debugMessage('jpxLoadingPage', 'launchActivity', 'called');
	
	//check whether there is a product to start
	if (jpxLoadingPage.productId == '')
	{
		jpxLoadingPage.showMessage('no_product');
		return;
	}
	
	// When the browser is not compatible, display an error.
	if (!jpxBrowser.isCompatible()) 
	{
		jpxDebug.debugMessage('jpxLoadingPage', 'launchActivity', 'The browser is not compatible: ' + jpxBrowser.getErrorMessage()); 
		jpxLogger.logAction('notcompatible_Browser');
		
        jpxLoadingPage.showMessage(jpxBrowser.getErrorMessage());
		return;
	}
	
    if (jpxBrowser.swfobject.hasFlashPlayerVersion(jpxLoadingPage.minFlashVersion) == false) 
    {
		if(typeof jpxDebug != "undefined") { jpxDebug.debugMessage('jpxLoadingPage', 'launchActivity', 'Not Compatible Flash'); }
		jpxLogger.logAction('notCompatibleFlash');
		jpxLoadingPage.showMessage('notcompatible_Flash');
		return;
	}
	
	if (!jpxBrowser.canLaunch(throw_error)) 
	{
		if (throw_error != false) 
		{
			jpxDebug.debugMessage('jpxLoadingPage', 'launchActivity', 'The activity can\'t launch for some reason: ' + jpxBrowser.getErrorMessage());
			
			jpxLogger.logAction('notCompatibleMsn');
			jpxLoadingPage.showMessage(jpxBrowser.getErrorMessage());
		}
		return;
	}
	
	if (jpxLoadingPage.isInitialized == false)
	{
		jpxDebug.debugMessage('jpxLoadingPage', 'launchActivity', 'Initialize loading page');
		
		jpxLoadingPage.initialize();
		return;
	}
	
	jpxBrowser.launchActivity(jpxLoadingPage.appId);
	jpxLogger.logAction('startJpx');
	jpxLoadingPage.showMessage('startagain');
}

jpxLoadingPage.onPageLoad = function ()
{
	jpxDebug.debugMessage('jpxLoadingPage', 'onPageLoad', 'called');
	
	//check whether there is a product to start
	if (jpxLoadingPage.productId == '')
	{
		jpxLoadingPage.showMessage('no_product');
		return;
	}
	
	// Precheck
	if (jpxBrowser.preFilter())
	{
		jpxLoadingPage.showMessage('initializing');
		
		// there is a product, so try to start it automatically
		if (jpxLib.getUrlParam('jpx_autoload') != false)
		{
			jpxDebug.debugMessage('jpxLoadingPage', 'onPageLoad', 'autostarting activity');
			jpxLoadingPage.showMessage('initializing');
			setTimeout("jpxLoadingPage.launchActivity(true)", jpxBrowser.setTimeOutAutloadInt);
		}
		else
		{    
			// Dubble call for ie5.5 (png not showing)
			jpxLoadingPage.showMessage('startagain');
			window.setTimeout (
				function(){
					jpxLoadingPage.showMessage('startagain');	
				},
				500);
		}
 	}
}

jpxLoadingPage.initialize = function ()
{
	jpxDebug.debugMessage('jpxLoadingPage', 'initialize', 'called');
	
	if (jpxLoadingPage.isInitialized == false) 
	{
		jpxLoadingPage.showMessage('initializing');
		
		if (swfobject.hasFlashPlayerVersion(jpxLoadingPage.minFlashVersion))
		{
			jpxDebug.debugMessage('jpxLoadingPage', 'initialize', 'Compatible Flash Player detected');
			
			if (!(document.getElementById(jpxLoadingPage.divflashProductSetter)))
			{
				var divSetter = document.createElement('DIV');
				divSetter.setAttribute('id', jpxLoadingPage.divflashProductSetter);
				document.getElementsByTagName('body')[0].appendChild(divSetter);
			}
			
			jpxLoadingPage.flashVars.item = jpxLoadingPage.productId;
			jpxLoadingPage.flashVars.jpxID = jpxLoadingPage.jpxId;
			jpxLoadingPage.flashParams.wmode = "transparent";
			jpxLoadingPage.flashParams.allowscriptaccess = "always";
			
			jpxDebug.debugMessage('jpxLoadingPage', 'initialize', 'Starting flashProductSetter');
			
			swfobject.embedSWF(
					STATIC_HOST+'swf/flashProductSetter.swf', 
					jpxLoadingPage.divflashProductSetter, 
					"1", 
					"1",
					jpxLoadingPage.minFlashVersion, 
					STATIC_HOST+"swf/expressInstall.swf",
					jpxLoadingPage.flashVars,
					jpxLoadingPage.flashParams
			);
		}
		else
		{
			jpxDebug.debugMessage('jpxLoadingPage', 'initialize', 'Not Compatible Flash');
			jpxLoadingPage.showMessage('notcompatible_Flash');
		}
	}
}

jpxLoadingPage.deinitialize = function ()
{
	jpxDebug.debugMessage('jpxLoadingPage', 'deinitialize', 'called');
	
	if (document.getElementById(jpxLoadingPage.divflashProductSetter))
	{
		swfobject.removeSWF(jpxLoadingPage.divflashProductSetter);
		jpxDebug.debugMessage('jpxLoadingPage', 'deinitialize', 'deinitialized the flash product setter');
	}
}

jpxLoadingPage.installFlashPlayer = function () 
{
	jpxDebug.debugMessage('jpxLoadingPage', 'installFlashPlayer', 'called');
	
	jpxLogger.logAction('installFlashPlayer');
}

jpxLoadingPage.flashAfterInstall = function () 
{
	jpxDebug.debugMessage('jpxLoadingPage', 'flashAfterInstall', 'called');
	
	jpxLogger.logAction('flashAfterInstall');
	var window_location = window.location.href;
	if(!window_location.match('jpx_autoload'))
	{
		window_location += "&jpx_autoload=true";
	}
	window.location.href = window_location;
}

jpxLoadingPage.flashProductIdSet = function ()
{
	jpxDebug.debugMessage('jpxLoadingPage', 'flashProductIdSet', 'called');
	jpxLoadingPage.isInitialized = true;
	
	jpxLoadingPage.showMessage('startagain');
	
	window.setTimeout ( function () { swfobject.removeSWF(jpxLoadingPage.divflashProductSetter); }, 200 );
	jpxLoadingPage.launchActivity(true);
}

jpxLoadingPage.flashProductIdPending = function ()
{
	jpxDebug.debugMessage('jpxLoadingPage', 'flashProductIdPending', 'called');
	
	jpxLoadingPage.showMessage('initializing');
	
	var size = jpxLib.getViewportSize();
	
	var fps_el = document.getElementById(jpxLoadingPage.divflashProductSetter);
	fps_el.style.position = "absolute";
	fps_el.style.top = "0";
	fps_el.style.left = "0";
	fps_el.style.width = size.width + "px";
	fps_el.style.height = size.height + "px"; 

	fps_el.retryFlush(size.width, size.height);
}

jpxLoadingPage.flashProductIdNotSet = function ()
{
	jpxDebug.debugMessage('jpxLoadingPage', 'flashProductIdNotSet', 'called' + var_pietje_puk);
	
	jpxLoadingPage.showMessage('product_not_set');
	window.setTimeout ( function () {
		document.getElementById(jpxLoadingPage.divflashProductSetter).parentNode.removeChild(document.getElementById(jpxLoadingPage.divflashProductSetter));	
	},200)
}

jpxLoadingPage.flashProductIdNeverSet = function ()
{
	jpxDebug.debugMessage('jpxLoadingPage', 'flashProductIdNeverSet', 'called');
	
	jpxLoadingPage.showMessage('product_not_set');
	window.setTimeout ( function () {
		document.getElementById(jpxLoadingPage.divflashProductSetter).parentNode.removeChild(document.getElementById(jpxLoadingPage.divflashProductSetter));	
	},200)
}

jpxLoadingPage.showMessage = function (msg)
{
	jpxLoadingPage.closeMessages();
	document.getElementById(msg).style.display = "block";
	window.scroll(0, 0);
} 

jpxLoadingPage.closeMessages = function ()
{
	var els = document.getElementById('loadingMsg').getElementsByTagName('DIV');
	for(var i = 0; i < els.length; i++) {
		els.item(i).style.display = "none";
	}
}

jpxLib.addEvent(window, 'beforeunload', jpxLoadingPage.deinitialize);