// JavaScript Document
// http://feather.elektrum.org/book/src.html
var scripts = document.getElementsByTagName('script');
var myScript = scripts[ scripts.length - 1 ];

var queryString = myScript.src.replace(/^[^\?]+\??/,'');

var params = parseQuery( queryString );

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}
// http://feather.elektrum.org/book/src.html

var rnd = params['rnd'];
var hostdomain = params['hostDomain'];
// the headline widget will use the height set in the global.inc (WNVideo.asp)
var playerwidth = params['playerWidth'];
var playerheight = params['playerHeight'];

// the variables submitted can be changes at some point in the future 
// so added code to dynamically built a SetVariable list


var setVariableCodeBlock = '';
for (property in params) {
	if ( property == "rnd" || property == "hostDomain" || property == "playerWidth" || property == "playerHeight" ) continue;
	if ( isNaN(params[property]) ) {
		setVariableCodeBlock = setVariableCodeBlock + 'videoCanvas.SetVariable("' + property + '","' + params[property] + '");';
	}
	else {
		setVariableCodeBlock = setVariableCodeBlock + 'videoCanvas.SetVariable("' + property + '",' + params[property] + ');';
	}
}
var v_divWNHeadline = "divWNHeadline" + rnd;
var v_divWNVideoCanvas = "divWNVideoCanvas" + rnd;
var v_CallbackFunc = "WorldNowRenderEmbedVideoPlayer" + rnd;

document.write('<div id="' + v_divWNHeadline + '"></div>');

document.write('<div id="' + v_divWNVideoCanvas + '"></div>');

document.write('<scr' + 'ipt type="text/javascript" src="http://' + hostdomain + '/global/video/flash/WNVideo.asp?CallbackFunc=' + v_CallbackFunc + '"><\/script>');

eval('function ' + v_CallbackFunc + '() {var videoHeadline = new WNVideoWidget("WNHeadline", "' + v_divWNHeadline + '", "' + rnd + '");videoHeadline.SetWidth(' + playerwidth + ');videoHeadline.RenderWidget();var videoCanvas = new WNVideoWidget("WNVideoCanvas", "' + v_divWNVideoCanvas + '", "' + rnd + '");videoCanvas.SetWidth(' + playerwidth + ');videoCanvas.SetHeight(' + playerheight + ');' + setVariableCodeBlock + 'videoCanvas.RenderWidget();}');
