function initializeLaunchPage()
{
	initializePage();
	executeOrder66();
}

function getSmileboxCommand()
{
	var theDictionary = parseQueryString( window.location.search );
	var theAction = theDictionary['action'];
	var theTemplateId = theDictionary['templateId'];
	var theCategoryPath = theDictionary['path'];
	var theSearchKeywords = theDictionary['keywords'];
	
	var theCommand = "smilebox://start";
	if (theAction && theAction.length > 0)
	{
		theCommand = "smilebox://" + theAction;
	}
	
	if (theTemplateId && theTemplateId.length > 0)
	{
		theCommand += "?templateId=" + theTemplateId;
	}
	else if (theCategoryPath && theCategoryPath.length >0)
	{
		theCommand += "?path=" + theCategoryPath;
	}
	else if (theSearchKeywords && theSearchKeywords.length >0)
	{
		theCommand += "?keywords=" + theSearchKeywords;
	}
	
	return theCommand;
}

function isForceDownloadFlagSet()
{
	var theDictionary = parseQueryString( window.location.search );
	var theForceDownload = theDictionary['forceDownload'];
	return ( "true" == theForceDownload );
}

function getPartnerCode()
{
	var theDictionary = parseQueryString( window.location.search );
	var thePartner = theDictionary['partner'];

	if (thePartner && thePartner.length > 0)
	{
		return thePartner;
	}
	
	if (isPartnerCookieSet())
	{
		thePartner = getSmileboxProperty("partner");
	}
	else
	{
		thePartner = "smilebox";
	}
	return thePartner;
}

function redirectToPartnerPage()
{
	document.location = "/go/launchClientInstalled/" + getPartnerCode();
}

function redirectToDownloadPage()
{
	forceDownload( false );
}

function launchSmileboxWithCommand()
{
	setTimeout( redirectToPartnerPage, 1000 );
	document.location = getSmileboxCommand();
}

function executeOrder66()
{
	if ( isSmileboxPropertyRegistrarReady() || !isUpgradeableFlashVersion())
	{
		setSmileboxProperty( "startupArgs", getSmileboxCommand() );
		if ( !isClientInstalled() || isForceDownloadFlagSet() )
		{
		    setTimeout( redirectToDownloadPage, 200 );
		}
		else
		{
			setTimeout( launchSmileboxWithCommand, 200 );
		}
	}
	else
	{
		setTimeout( executeOrder66, 500 );
	}
}
