/*
Site Design
Kevin Douglas :: Satarah Studios
kdouglas@satarah.com [satarah.com]
*/

flashVersion.required; // script use
flashVersion.implant;  // script use
function flashVersion ( version ) {

  if ( /^\d{1,2}$/.test( version ) ) {

    flashVersion.required = version;
    flashVersion.implant = flashEmbed('path=images/flashVersion.swf','width=20','height=20','wmode=transparent');

  } else {

    var clientVersion = version.match( /\w+\s+(\d{1,2}),.*/ )[1];
    if ( clientVersion >= flashVersion.required ) {

      document.getElementsByTagName('body').item(0).removeChild( flashVersion.implant );

      // actions to perform, if version passes, follow here //
      // do not use a 'return' statement here--WTF //

      // handlerFunction ( clientVersion );

      var embeded = flashEmbed('path=images/header.swf','width=700','height=400','loop=false','wmode=transparent','insert=siteMenu');
      embeded.id = 'movie';

    } else {

      document.getElementsByTagName('body').item(0).removeChild( flashVersion.implant );

      // actions to perform, if version fails, follow here //
      // do not use a 'return' statement here--WTF //

      // handlerFunction ( clientVersion );

    }
  }
}



function flashEmbed () {

// Arguments accepted, in any order, are:

  var path, width, height, quality, bgcolor, scale, wmode, loop, append, insert;

  // 'path' may not be omitted, all other arguments are optional //
  // argument format is ( 'path=test.swf','width=700' ) and so on, etc. //
  // choose either: 'append' or 'insert', if omitted will append to body tag //
  // 'append' and 'insert' require a unique html-element tag #id as a value passed //


  for ( var a=0; a<arguments.length; a++ ) {

    if ( /path/.test( arguments[a] ) ) path = arguments[a].match( /path\s*=\s*(.+)/ )[1];
    if ( /width/.test( arguments[a] ) ) width = arguments[a].match( /width\s*=\s*(.+)/ )[1];
    if ( /height/.test( arguments[a] ) ) height = arguments[a].match( /height\s*=\s*(.+)/ )[1];
    if ( /quality/.test( arguments[a] ) ) quality = arguments[a].match( /quality\s*=\s*(.+)/ )[1];
    if ( /bgcolor/.test( arguments[a] ) ) bgcolor = arguments[a].match( /bgcolor\s*=\s*(.+)/ )[1];
    if ( /scale/.test( arguments[a] ) ) scale = arguments[a].match( /scale\s*=\s*(.+)/ )[1];
    if ( /wmode/.test( arguments[a] ) ) wmode = arguments[a].match( /wmode\s*=\s*(.+)/ )[1];
    if ( /loop/.test( arguments[a] ) ) loop = arguments[a].match( /loop\s*=\s*(.+)/ )[1];

    if ( /append/.test( arguments[a] ) ) append = arguments[a].match( /append\s*=\s*(.+)/ )[1];
    if ( /insert/.test( arguments[a] ) ) insert = arguments[a].match( /insert\s*=\s*(.+)/ )[1];

  }

  if ( !path ) return false;

  if ( isWin && isIE ) { // active-x with security bypass //

    var movie = document.createElement('embed');
      movie.setAttribute('type', 'application/x-shockwave-flash');
      movie.setAttribute('src', path);
      if ( width ) movie.setAttribute('width', width);
      if ( height ) movie.setAttribute('height', height);
      if ( scale ) movie.setAttribute('scale', scale);
      if ( quality ) movie.setAttribute('quality', quality);
      if ( bgcolor ) movie.setAttribute('bgcolor', bgcolor);
      if ( wmode ) movie.setAttribute('wmode', wmode);
      if ( loop ) movie.setAttribute('loop', loop);

  } else { // DOM standards compliant approach //

    var movie = document.createElement('object');
      movie.setAttribute('type', 'application/x-shockwave-flash');
      movie.setAttribute('data', path);
      if ( width ) movie.setAttribute('width', width);
      if ( height ) movie.setAttribute('height', height);
    var name = document.createElement('param');
      name.setAttribute('name', 'movie');
      name.setAttribute('value', path);
      movie.appendChild(name);
    if ( scale ) {
      var pScale = document.createElement('param');
      pScale.setAttribute('name', 'scale');
      pScale.setAttribute('value', scale);
      movie.appendChild(pScale);
    }
    if ( quality ) {
      var pQuality = document.createElement('param');
      pQuality.setAttribute('name', 'quality');
      pQuality.setAttribute('value', quality);
      movie.appendChild(pQuality);
    }
    if ( bgcolor ) {
      var pBgcolor = document.createElement('param');
      pBgcolor.setAttribute('name', 'bgcolor');
      pBgcolor.setAttribute('value', bgcolor);
      movie.appendChild(pBgcolor);
    }
    if ( wmode ) {
      var pWmode = document.createElement('param');
      pWmode.setAttribute('name', 'wmode');
      pWmode.setAttribute('value', wmode);
      movie.appendChild(pWmode);
    }

  }

  if ( append && document.getElementById( append ) ) {
    document.getElementById( append ).appendChild( movie );    
  } else if ( insert && document.getElementById( insert ) ) {
    document.getElementById( insert ).parentNode.insertBefore( movie, document.getElementById( insert ) );
  } else {
    document.getElementsByTagName('body').item(0).appendChild( movie );
  }

  return movie;
}


