/**
 * This script contains embed functions for common plugins. This scripts are complety free to use for any purpose.
 */

/*
function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}
*/

var player;
function playerReady(obj) {
 player = document.getElementById(obj.id);
 set_page_button_state(true);
 add_listeners();
}

function add_listeners() {
  if (player) {
    player.addModelListener("STATE", "player_state_handler")
  }
  else {
    setTimeout("add_listeners", 100);
  }
}
 /* (id, client, version, oldstate, newstate) */
function player_state_handler(obj)
{
  if (obj.newstate == "COMPLETED") {
    set_page_button_state(false);
    $('next-page').form.submit();
  }
}

function set_page_button_state(disabled_state) {
  $('next-page').disabled = disabled_state;
}

/* use a custom function for flash files */
function writeFlash(p) {
  document.write('<div id="container"></div>');
  var s1 = new SWFObject("http://media.equationresearch.com/plugin_assets/common/swf/player.swf","ply",p.width,p.height,"9","#FFFFFF");

  var flashvars = {
            autostart : true,
            allowfullscreen : false,
            controlbar : 'none', 
            file : p.src,
            displayclick : 'none',
            icons : false
  };
  
  /* add streaming options if the source url looks like a streamer */
  if (p.src.match("^(flv|mp4):")) {
    flashvars["bufferlength"] = 5;
    flashvars["streamer"] = "rtmp://75.101.142.207/vods3";
  }

  s1.addParam("flashvars", Object.toQueryString(flashvars));
  s1.addParam("allowfullscreen","false");
  s1.addParam("allowscriptaccess","always");

  s1.write("container");
}

function writeShockWave(p) {
	writeEmbed(
	'166B1BCA-3F9C-11CF-8075-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	'application/x-director',
		p
	);
}

function writeQuickTime(p) {
	writeEmbed(
		'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
		'video/quicktime',
		p
	);
}

function writeRealMedia(p) {
	writeEmbed(
		'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'audio/x-pn-realaudio-plugin',
		p
	);
}

function writeWindowsMedia(p) {
	p.url = p.src;
	writeEmbed(
		'6BF52A52-394A-11D3-B153-00C04F79FAA6',
		'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
		'application/x-mplayer2',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}

function writeFlashEmbed(p) {
	var h = '';
  var v = "autostart=true&showdigits=false&enablejs=true&allowfullscreen=false"; 

	if (typeof(p.src) != "undefined") {
    v += '&file=' + p.src;
  }

  h += '<object id="flvplayer" name="flvplayer" type="application/x-shockwave-flash" data="http://www.eqrtools.com/swf/flvplayer.swf"'
  h += typeof(p.width) != "undefined" ? 'width="' + p.width + '" ' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '" ' : '';
  h += '>';

  h += '<param name="flashvars" value="' + v + '"/> ';
  h += '<param name="allowscriptaccess" value="always" /> '
  /*
   h += '<embed id="flvplayer" name="flvplayer" src="http://www.eqrtools.com/swf/flvplayer.swf" allowscriptaccess="always" ' 

	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '" ' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '" ' : '';


  h += 'flashvars="' + v + '" ';

	h += '/>';
  */

  h += '</object>';
  
	document.write(h);
}
