var flashVersion = swfobject.getFlashPlayerVersion();

document.observe('dom:loaded', function()
{
  setupCoreValues.defer($('core_values'));
  setupCoreValuesDiagram.defer($('core_values_diagram'));
});

function setupCoreValues(el)
{
  // Require at least Flash version 9.
  if (flashVersion.major >= 9)
    showCoreValues(el);
  else
    showFlashInstall(el);
}

function setupCoreValuesDiagram(el)
{
  // Require at least Flash version 9.
  if (flashVersion.major >= 9)
    showCoreValuesDiagram(el);
  else
    showFlashInstall(el);
}

function showCoreValues(el)
{
  var flashVars = {
    'faust_xml': encodeURIComponent($('flash_core_values').toFlashHTML()),
    'locale': getLocaleLanguage()    
  };

  var params = {
    allowFullScreen: 'true',
    allowScriptAccess: 'always'    
  };
  
  var o = new Element('div');
  el.insert(o);
  
  swfobject.embedSWF(buildUrl('/swf/core_values.swf'), o.identify(), '900', '320', '9', '', flashVars, params, {});
}

function showCoreValuesDiagram(el)
{
  var flashVars = {
    'faust_xml': encodeURIComponent($('flash_core_values_diagram').toFlashHTML())
  };

  var params = {
    allowFullScreen: 'true',
    allowScriptAccess: 'always'    
  };
  
  var o = new Element('div');
  el.insert(o);
  
  swfobject.embedSWF(buildUrl('/swf/diagram.swf'), o.identify(), '900', '320', '9', '', flashVars, params, {});
}

function showFlashInstall(el)
{
  el.update(
    '<p>Please install the latest Flash Player 9 by <a href="http://www.adobe.com/go/getflashplayer?redirect=' + location.href + '">clicking here</a>.</p>'
  );
}
