var vimeo_a = 'http://vimeo.com/moogaloop.swf?clip_id=';
var vimeo_b = '&amp;server=vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;hd_off=0';
var utube_a = 'http://www.youtube.com/v/v/';
var utube_b = '&autoplay=0&hl&hl=en&rel=0&egm=0&showsearch=0&playerapiid=lowdefplayer';
var ooyala_a = 'http://www.ooyala.com/player.swf?embedCode=';
var ooyala_b = '&version=2';

var yt=new function(){
  var _throwOnNull=function(value){
  if(value==null)throw "ExpectedNotNull";
  }
}

// pulling in just the YouTube functions we actually need
yt.VideoQualityConstants={ AUTO:0, LOW:1, HIGH:2 }

/* The ID becomes the element ID 'movie_player'
 * the playerapiid becomes playerId passed into onYouTubePlayerReady
 *
 * embedSWF comes from the google swfobject code
 * swfobject.embedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj)
 *
 */


function loadMovie(videoID, quality) {
  var params = { allowScriptAccess: 'always', bgcolor: '#000000', wmode: 'transparent' }; // these get used by swfobject
  
  if (videoService == 'Vimeo') {
	  swfobject.embedSWF(vimeo_a + videoID + vimeo_b, 'hidefcontainer', width, height, '8', false, null, params, atts);
	  
  } else if (videoService == 'Ooyala') {
    width = 580;
    height = 326;
    var flashVars = { embedCode: videoID, embedType: 'directObjectTag&embedCode=' + videoID }
    swfobject.embedSWF(ooyala_a + videoID + ooyala_b, 'hidefcontainer', width, height, '8', false, flashVars, params, atts);
  } else if (videoService == 'YouTube') {
    var qualfmt = "&enablejsapi=1";
    var atts = { id: 'hidefplayer' };
    swfobject.embedSWF(utube_a + videoID + utube_b + qualfmt, 'hidefcontainer', width, height, '8', false, null, params, atts);

	}
	
}

function playerError(error) {
  if (error == 100) { // 100 = video not found 101 = video not allowed to be embedded
    loadMovie(mastervideo,yt.VideoQualityConstants.LOW);
  }
}