/* 
	swfobject-helpers-custom.js
	=================================================================	
	swfobject - custom helper functions
	Created 30.04.2009 by DS
	-----------------------------------------------------------------
*/

/*	
	@	flash_customEmbed()
	---------------------------------------------------------------			
	A clone of flash_advancedEmbed().
	Refer: swfobject-helpers-core-jquery.js
	
	This variation adds support for flash_custom_args.flash_supportingtext.
	
	_______________________________________________________________
*/		

	function flash_customEmbed(flash_src, flash_containerId, flash_width, flash_height, flash_reqdVersion, flash_expressInstaller, flash_vars, flash_params, flash_attributes, flash_custom_args)
	{		
		//console.info( 'flash_customEmbed(', flash_src, ', ', flash_containerId, ', ', flash_width, ', ', flash_height, ', ', flash_reqdVersion, ', ', flash_expressInstaller, ', ', flash_vars, ', ', flash_params, ', ', flash_attributes, ', ', flash_custom_args, ')' );
	
		if (flash_browser.supports_basicSwfobjectEmbed)
		{		
			switch (swfobject.hasFlashPlayerVersion(flash_reqdVersion))				
			{ 
				// Flash Player version is available:					
				case true : 	
					// if a Flash movie has been specified, insert the Flash movie
					if (flash_src)
					{
						swfobject.embedSWF((flash_src + flash_cacheFix(flash_src)), flash_containerId, flash_width, flash_height, flash_reqdVersion, flash_expressInstaller, flash_vars, flash_params, flash_attributes);										
					}						
					// if a warning exists, remove the warning
					if (flash_custom_args.flash_warningContainerId) 
					{ 
						flash_removeWarning(flash_custom_args.flash_warningContainerId, 'module'); 
						
						// prevent the removed warning from reserving vertical whitespace above #rss..
						if ($.globals.isIE6)
						{									
							$('.footer-liner').css(
								{						
									'zoom' : '1'									
								}
							);
						}							
					}
					if (flash_custom_args.flash_supportingtext)
					{
						flash_format_supporting_text(flash_custom_args.flash_supportingtext, flash_containerId, flash_width);
					}					
					
					break;				
				
				// Flash Player version is not available:
				case false :	

					// if a Flash movie has been specified, and expressInstall is enabled, output the expressInstaller so the user can upgrade to the latest version of Flash
					if (flash_src && flash_expressInstaller)
					{
						swfobject.embedSWF((flash_src + flash_cacheFix(flash_src)), flash_containerId, flash_width, flash_height, flash_reqdVersion, flash_expressInstaller, flash_vars, flash_params, flash_attributes);	
					}
					// if a warning exists, change the old-browser warning to an old-Flash warning							
					if (flash_custom_args.flash_warningContainerId)
					{
						flash_oldFlashWarning(flash_custom_args.flash_warningContainerId); 	
					}															
					break; 				
			}
		}
	}

/*	
	@	flash_format_supportingtext()
	---------------------------------------------------------------			
	Insert a block of formatted supporting text after a Flash embed.
	
	Arguments:
	1 x flash_custom_args.flash_supportingtext) - the text to format.
	1 x flash_containerId - the embed to append insert the text after.
	1 x flash_width - the width the supporting text block should be
	_______________________________________________________________
*/	

	function flash_format_supporting_text(flash_supportingtext, flash_containerId, flash_width)
	{			
		$('#' + flash_containerId).parents('div:first')
		.append( 
			$('<div/>') /* was $('p') - this caused loop repeat of this function - perhaps it was trying to replicate all Ps on the page? */
			.attr('class', 'flash-supporting-text curved')
			.attr('id', (flash_containerId + '-text'))
			.css('width', (flash_width + 'px'))
			.append(
				$('<p/>')		
				.text(flash_supportingtext)					
			)		
		);
		
		/*
			add_curves() called here as the supporting text is output dom.onload - ie after our other scripts have run.
			This could potentially lead to 2 sets of curves, if differnt browsers run the scripts in a different order,
			but as the curves are absolutely positioned, there shouldn't be any visible difference if this does happen.
		*/		
		add_curves(); 
	}
	
/*	
	@	flash_inline()
	---------------------------------------------------------------			
	Generate inline players		
	_______________________________________________________________
*/	

	function flash_inline()
	{
		var themecolour_once;
		
		// override global selected SWFOBJECT embed preferences:			
		var flash_src = '/resources/ui/media/nfa_videoplayer_resizable.swf'; 				
				//flash_vars.themecolour = '0xfc9a1f';
				flash_params.wmode = 'transparent';	// allow overlay of dropdown menus				
		
		$('#content').find('.video').each(
			function(f)
			{				
				var g = f+1;	
				
				if (themecolour_once == '')
				{
					themecolour_once = ( '0x' + get_theme_colour('body') );		
					flash_vars.themecolour = themecolour_once;
				}
				else
				{
					flash_vars.themecolour = themecolour_once;
				}
				
				$(this).attr( 'id', 'flash-' + g );
				
				var preroll_img = $(this).find('dt:first').find('img:first');				
				var caption = $(this).find('dd:first').find('p:first');							
				
				// SWFOBJECT Flash [warning, no expressInstall]							
				// override global selected SWFOBJECT embed preferences:															
					
				var flash_width = preroll_img.attr('width');				
				var flash_height = ( preroll_img.attr('height') + 28 );
				var flash_containerId = flash_createContainer( flash_reqdVersion, ( 'flash-' + g + '-content' ), 'replaceContents', ( 'flash-' + g ) );				
				
				var preroll_img_src, preroll_img_file, video_path, video_file;
				
						preroll_img_src = preroll_img.attr('src');
						preroll_img_file = preroll_img_src.substring( preroll_img_src.lastIndexOf('/'), preroll_img_src.length );
						
						video_path = '/video';						
			
						video_file = preroll_img_file.replace('.jpg', '.mov');
						video_file = video_file.replace('.gif', '.mov');
						video_file = video_file.replace('.png', '.mov');					
						
						flash_vars.videoURL = ( video_path + video_file );	
						flash_vars.videoImage = preroll_img.attr('src');
						
						flash_custom_args.flash_supportingtext = $(caption).text();											
						
						flash_customEmbed(flash_src, flash_containerId, flash_width, flash_height, flash_reqdVersion, flash_expressInstaller, flash_vars, flash_params, flash_attributes, flash_custom_args);					
			}
		)		
	}
	
/*	
	@	add_load_event()
	---------------------------------------------------------------			
	_______________________________________________________________
*/		
	
	function add_load_event(func)
	{
		// BPA P98
		
		var oldonload = window.onload;
		
		if (typeof window.onload != 'function')
		{
			window.onload = func;	
		}
		else
		{
			window.onload = function()
			{
				if (oldonload)
				{
					oldonload();	
				}
				func();
			};
		}
	}	
