/* -*- JavaScript -*-
 *
 * Copyright (c) 2007
 * Spoken Language Systems Group
 * MIT Computer Science and Artificial Intelligence Laboratory
 * Massachusetts Institute of Technology
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 **/
 
 function RealPlayerController()
 {
 }
 
// Ensure prototype
new RealPlayerController(null, null);

RealPlayerController.prototype.createPlayer = function(videoContainer, width, height, initialmediaURL)
{
	videoContainer.innerHTML = '';

   	var videoHTML = '<EMBED ID="video" NAME="lecture-video"';
   	videoHTML+= ' MAINTAIN-ASPECT="true" CONTROLS="ImageWindow" CONSOLE="one"';
   	videoHTML+= ' AUTOSTART="false" WIDTH="'+width+'px" HEIGHT="'+height+'px"';
   	videoHTML+= ' TYPE="audio/x-pn-realaudio-plugin"';
   	//videoHTML+= ' TYPE="'+this.mimetype+'"';
   	videoHTML+= ' SRC="'+initialmediaURL+'"';
	videoHTML+= ' />';
	
   	var contHTML = '<EMBED ID="video-control-panel"';
   	contHTML+= ' WIDTH="'+width+'px" HEIGHT="36px"';
   	contHTML+= ' NAME="lectureControl" CONTROLS="ControlPanel" CONSOLE="one" AUTOSTART="false"';
   	contHTML+= ' TYPE="audio/x-pn-realaudio-plugin"';
   	//contHTML+= ' TYPE="'+this.mimetype+'"';
   	contHTML+=' />';

   	videoContainer.innerHTML = videoHTML+contHTML;
   	
	this.video = document.getElementById("video");
   	if (!this.video)
    	return;
   	this.videoControl = document.getElementById("video-control-panel");
   	this.video.parentNode.style.display = "block";
}

RealPlayerController.prototype.stop = function()
{
	this.video.DoStop();
}

RealPlayerController.prototype.pause = function()
{
	this.video.DoPause();
}

RealPlayerController.prototype.play = function()
{
	this.video.DoPlay();
}

RealPlayerController.prototype.setPosition = function(pos)
{
	this.video.SetPosition(pos);
}

RealPlayerController.prototype.getPosition = function()
{
	return this.video.GetPosition();
}

RealPlayerController.prototype.setSource = function(source)
{
	this.video.SetSource(source);
}

RealPlayerController.prototype.checkState = function()
{
	try {
		this.state = this.video.GetPlayState();
	} catch(e) {
		// Crashed
		this.state = -1;
	}
}

RealPlayerController.prototype.wasDead = function()
{
	return this.state == -1;
}

RealPlayerController.prototype.wasStopped = function()
{
	return this.state == 0;
}

RealPlayerController.prototype.wasBuffering = function()
{
	return this.state == 2;
}

RealPlayerController.prototype.wasPlaying = function()
{
	return this.state == 3;
}

RealPlayerController.prototype.wasPaused = function()
{
	return this.state == 4;
}

RealPlayerController.prototype.wasSeeking = function()
{
	return this.state == 5;
}
