function embedVideoPlayer(src, width, height) {
  
  if (!$("videoPlayerBackground")) {
    /*
    <div id="videoPlayerBackground" style="margin: 0px; padding: 0px; z-index: 1000; width: 100%; height: 100%; display: none; position: absolute;">
	    <div id="videoPlayerWrapper" style="position: absolute; z-index:6;"><div id="videoPlayerDiv"></div></div>
  		<div id="videoPlayerBlack" style="position: absolute; z-index:5; background-color: black; width: 100%; height: 100%;"></div>
	  </div>
	  */
    var div1 = new Element("div", {id: "videoPlayerBackground"}).setStyle({margin:"0px", padding:"0px", zIndex:"1000", width:"100%", height:"100%", display:"none", position:"fixed", marginTop:"-27px"});
    var div2 = new Element("div", {id: "videoPlayerWrapper"}).setStyle({position:"absolute", zIndex:"6"});
    var div3 = new Element("div", {id: "videoPlayerDiv"});
    var div4 = new Element("div", {id: "videoPlayerBlack"}).setStyle({position:"absolute", zIndex:"5", backgroundColor:"black", width:"100%", height:"100%"});
    
    div2.insert(div3)
    div1.insert(div2);
    div1.insert(div4);
    $(document.body).insert({top:div1});
  }
  
  var flashvars = {
	  flashVideoId: "videoPlayerFlash",
    //controlsURL: "res/controlsExternalZurich.swf",
    controlsURL: "res/controlsOverBlack.swf",
	  //previewImageURL: "images/preview.png",
	  //videoURL: "zurichTechCastAudio_01.mp4",
	  videoURL: src,
	  autoPlay: true
	};
	var params = {};
	var attributes = {
	  id: "videoPlayerFlash"
	};
  
  $("videoPlayerBlack").setStyle({opacity:.75}).observe("click", closeVideo);;
  $("videoPlayerBackground").setStyle({display:"block"});
	swfobject.embedSWF("res/videoPlayer.swf", "videoPlayerDiv", width, height, "9.0.0", false, flashvars, params, attributes, resizeVideo);
	
  Event.observe(window, "resize", resizeVideo);
}

function resizeVideo() {
  
  var videoElement = $("videoPlayerFlash");
  
  if (videoElement) {
    
    var videoDimensions = videoElement.getDimensions();
    
    if (videoDimensions.width != 0 && videoDimensions.height != 0) {
      
      var backgroundDimensions = $("videoPlayerBackground").getDimensions();
      
      var left = parseInt((backgroundDimensions.width - videoDimensions.width) * .5);
      var top = parseInt((backgroundDimensions.height - videoDimensions.height) * .5);
      $("videoPlayerWrapper").setStyle({
        width: videoDimensions.width + "px",
        height: videoDimensions.height + "px",
        left: left + "px",
        top: top + "px"
      });
    } else {
      setTimeout(resizeVideo, 150);
    }
  };
}

function closeVideo(event) {
  $("videoPlayerBlack").stopObserving("click", closeVideo);
  
  videoElement = $("videoPlayerFlash");
  videoElement.wrap( new Element('div', {'id':'videoPlayerDiv'}) );
  swfobject.removeSWF(videoElement);
  videoElement.remove();
  
  $("videoPlayerBackground").setStyle({display:"none"});
}

function btnPlayClick() {
  $("videoPlayerFlash").play();
}
function btnPauseClick() {
  $("videoPlayerFlash").pause();
}

