var CondorUIComponentRenderer =
{
	RenderChart: function( sComponentName, sSwfName, sXmlUrl, iWidth, iHeight, sAlignment, eTargetElement )
	{
		switch ( sComponentName )
		{
			case 'FusionCharts':

				// Get vars
				var dDate = new Date();
				var iTimestamp = Math.round( dDate.getTime() );
				var sDivId = ( eTargetElement == null ) ? 'CondorChartDiv' + iTimestamp : eTargetElement.id;

				// Render div
				if ( eTargetElement == null )
				{
					document.write( '<div id="' + sDivId + '"' );
					if ( sAlignment )
						document.write( ' style="float: ' + sAlignment + '"' );
					document.write( '></div>' );
				}

				// Include FusionCharts and add this function call to onload if it doesn't exist yet
				if ( window.FusionCharts == null )
				{
					var sBaseHref = document.getElementsByTagName( 'BASE' )[ 0 ].href;
					var sIncludeString = sBaseHref + 'System/UIComponents/FusionCharts/FusionCharts.js';
					if ( document.body.innerHTML.indexOf( sIncludeString ) < 0 )
					{
						// Add script to body
						document.write( '<script type="text/javascript" src="' + sIncludeString + '"></script>' );

						//var eScript = document.createElement( 'SCRIPT' );
						//eScript.type = 'text/javascript';
						//eScript.src = sIncludeString;
						//document.body.appendChild( eScript );

						// Get div
						if ( eTargetElement == null )
							eTargetElement = document.getElementById( sDivId );
						
						// Do not render chart directly, wait until window has loaded completely
						$( document ).ready( function() 
						{
							CondorUIComponentRenderer.RenderChart( sComponentName, sSwfName, sXmlUrl, iWidth, iHeight, sAlignment, eTargetElement ); 
						});
					}
					return;
				}
				

				// Render chart
				var fusionChart = new FusionCharts
				( 
					'System/UIComponents/FusionCharts/' + sSwfName, 
					sDivId.replace( 'Div', '' ), 
					iWidth, 
					iHeight 
				);
               	fusionChart.setDataURL( sXmlUrl );
               	fusionChart.render( sDivId );

				break;
		}
	}
}