function hdplayer(videoid, width, height) {
  width = width || 720;
  height = height || 405;
  var rstring = random();
  YD.addClass(document.body, "htmlonly");
  document.write("<div id='thevideo_"+ rstring +"' class='playerBox'>Wait...</div>");
  generatePlayer("thevideo_"+ rstring, videoid, width, height, 1, 1);
}

function sdplayer(videoid, width, height, switchable) {
  width = width || 640;
  height = height || 480;
  var rstring = random();
  YD.addClass(document.body, "htmlonly");
  document.write("<div id='thevideo_"+ rstring +"' class='playerBox'>Wait...</div>");
  generatePlayer("thevideo_"+ rstring, videoid, width, height, 0, switchable);
}

function generatePlayer(elementId, videoid, width, height, hd, switchable) {
  document.getElementById(elementId).innerHTML = '<embed src="http://www.motionbox.com/external/hd_player/type='
+ (hd ? 'hd' : 'sd') + ',video_uid=' + videoid
+ ',autoPlay=true,affiliate_name=beta" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" width="' + width + '" height="' + height + '" allowFullscreen="true">'
+ (switchable ? '<p><div class="playerToggle" onClick="generatePlayer(\'' + elementId + '\',\''+ videoid +'\', ' + width + ',' + height + ',' + (hd ? '0' : '1') + ',1);">' +
(hd ? '<b>HD is on</b>. Click here to turn it off.' : 'HD is off. Click here to turn it on.')  + '</div></p>' : '');
}

function random(){
  var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
  var sRnd = '';
  for (i=0; i>5; i++) {
    var randomPoz = Math.floor(Math.random() * chars.length);
    sRnd += chars.substring(randomPoz,randomPoz+1);
  }
  return sRnd;
}
