/**
 * (c) Copyright 2008 Oakley, Inc.
 *
 */

window.addEvent( 'domready', function()
{
	// Pull in the query string object
	objParams = parseQueryString();

	// Is the athlete set?
	if( objParams.athlete )
	{
		// Lets update the flash on the page
		rewriteFlash( objParams.athlete );
	}
	
});

function parseQueryString()
{
	// Pull the query string into a var
	strQuery = window.location.search.substring(1);

	// Split the name/value pairs into an array
	aryQuery = strQuery.split( "&" );

	// Initialize a POJO to hold our name value pairs
	var objParams = new Object();

	// Loop the array and split each name value pair
	for( i=0; i < aryQuery.length; i++ )
	{
		aryPair = aryQuery[ i ].split( "=" );
		objParams[ aryPair[ 0 ]] = aryPair[ 1 ];
	}

	return objParams;
};

function rewriteFlash( strAthlete )
{
	// First, let's get the ID of the flash block, since it can't be counted to generate consistently
	strFlashBlockId = $E( '.flash_block', '#brochure-head' ).getProperty( "id" );

	// Now, let's generate a new SWF object
	objSWF = new SWFObject( '/myway/flash/' + strAthlete + '/index.swf', strFlashBlockId, '970', '575', 8, '#0F0F0F', 'high');
	objSWF.addParam( 'allowscriptaccess', 'always' );

	if( !window.gecko || !window.mac )
	{
		objSWF.addParam( 'wmode', 'transparent' );
	}
	objSWF.addParam( 'menu', 'true' );
	objSWF.addVariable( 'curBase', '/myway/flash/' + strAthlete + '/' );
	objSWF.addVariable( 'baseURL', '/myway/flash/' + strAthlete + '/' );
	objSWF.addVariable( 'assetID', '');

	// Write the flash in place of the current flash
	objSWF.write( strFlashBlockId );
};
