var def_makeMovie = "V1.0";			// Make sure this is here, richtext.js will check for it

var stdWidth   = 350;				// Change here or overwrite in page (-1 keeps original size)
var movieImage = "/art/icons/movie.gif";

function makeMovie( type, movieId, width, height )
{
  var newWidth  = ( ( stdWidth == -1 ) ? width : stdWidth );
  var newHeight = ( ( stdWidth == -1 ) ? height : Math.round( height / width * stdWidth ) );

  if( type == "youtube" )
  {
    document.write( '<object width="' + newWidth + '" height="' + newHeight + '"><param name="movie" value="http://www.youtube.com/v/' + movieId + '"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/' + movieId + '" type="application/x-shockwave-flash" wmode="transparent" width="' + newWidth + '" height="' + newHeight + '"></embed></object>' );
  }
  else if( type == "gametrailers" )
  {
    document.write( '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="gtembed" width="' + newWidth + '" height="' + newHeight + '"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid=' + movieId + '"/> <param name="quality" value="high" /> <embed src="http://www.gametrailers.com/remote_wrap.php?mid=' + movieId + '" swLiveConnect="true" name="gtembed" align="middle" allowScriptAccess="sameDomain" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + newWidth + '" height="' + newHeight + '"></embed> </object>' );
  }
}

function getEndIndexOf( text, match )
{
  return text.indexOf( match ) + match.length;
}

function getBetween( text, start, end )
{
  var p1 = getEndIndexOf( text, start );
  return text.substring( p1, text.indexOf( end, p1 ) );
}

function parseMovie( rawHtml )
{
  var type;
  var movieId;
  var width;
  var height;

  if( rawHtml.toLowerCase().indexOf( "www.youtube.com" ) != -1 )
  {
    type = "youtube";
    movieId = getBetween( rawHtml, "www.youtube.com/v/" , '"' );
  }
  else if( rawHtml.toLowerCase().indexOf( "www.gametrailers.com" ) != -1 )
  {
    type = "gametrailers";
    movieId = getBetween( rawHtml, "www.gametrailers.com/remote_wrap.php?mid=", '"' );
  }
  else
  {
    alert( 'That movie HTML is currently unsupported.\nPlease contact support via the "email support" link to have it enabled.' );
    return "";
  }

  width  = getBetween( rawHtml, 'width="',  '"' );
  height = getBetween( rawHtml, 'height="', '"' );

  return '<img src="' + movieImage + '" alt="' + type + ':' + movieId + ':' + width + ':' + height + '"/>';
}
