// This creates the player after the page has finished loading (onload).
function createVideoPlayer( pl )
{
	var flashvars = {};
	var params = {};
	params.menu = 'true';
	params.quality = 'best';
	params.scale = 'showall';
	params.salign = 'tl';
	params.bgcolor = '#000000';
	params.swliveconnect = 'true';
	params.allowfullscreen = 'false';
	params.allowscriptaccess = 'sameDomain';
	var attributes = {};
	attributes.id = 'videoplayer';
	attributes.name = 'videoplayer';
	swfobject.embedSWF( '/includes/swf/videoplayer.swf', 'videoplayerPlaceholder', '336', '246', '9.0.0', '/includes/swf/expressInstall.swf', flashvars, params, attributes );
	if( pl.length > 0 )
	{
		setTimeout( function(){ sendFlashEvent( 'videoplayer', 'load', pl[ 0 ] ); }, 500 );
	}
};

function sendFlashEvent( id, action, args )
{
	player = getFlashObject( id );
	if( player )
	{
		player.sendEvent( action, args );
	}
}

function getFlashObject( id )
{
	if( navigator.appName.indexOf( 'Microsoft' ) != -1 )
	{
		return window[ id ];
	}
	else
	{
		return document[ id ];
	}
};

function popup( url, winName, opts )
{

	var options = '';

	if( typeof( opts ) == 'object' )
	{
	
		var booleanOptions = { menubar: true, toolbars: true, location: true, status: true, resizable: true, scrollbars: true };
		
		opts[ 'left' ] = typeof( opts[ 'left' ] ) != 'undefined' && opts[ 'left' ] > -1 ? opts[ 'left' ] : ( screen.width && opts[ 'width' ] && ( ( screen.width - opts[ 'width' ] ) / 2 > 0 ) ? ( screen.width - opts[ 'width' ] ) / 2 : 0 );
		opts[ 'top' ] = typeof( opts[ 'top' ] ) != 'undefined' && opts[ 'top' ] > -1 ? opts[ 'top' ] : ( screen.height && opts[ 'height' ] && ( ( screen.height - opts[ 'height' ] ) / 2 > 0 ) ? ( screen.height - opts[ 'height' ] ) / 2 : 0 );

		var tempOptions = [];
		for( var i in opts )
		{
			if( booleanOptions[ i ] && typeof( opts[ i ] ) != 'string' )
			{
				opts[ i ] = opts[ i ] ? 'yes' : 'no';
			}
			tempOptions.push( i + '=' + opts[ i ] );
		}
		options = tempOptions.join( ',' );

	}

	if( typeof( window.popups ) != 'object' )
	{
		window.popups = {};
	}

	if( typeof( window.popups[ winName ] ) == 'undefined' || window.popups[ winName ].closed )
	{
		window.popups[ winName ] = window.open( url, winName, options );
	}

	if( typeof( window.popups[ winName ].opener ) == 'undefined' )
	{
		window.popups[ winName ].opener = self;
	}

	window.popups[ winName ].focus();	

}

window.onload = function()
{
	if( document.getElementById( 'videoplayerPlaceholder' ) )
	{
		createVideoPlayer( playlist );
	}
}