/* -*- 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 QuickTimeController()
 {
 }
 
// Ensure prototype
new QuickTimeController(null, null);

QuickTimeController.prototype.createPlayer = function(videoContainer, width, height, initialmediaURL)
{
	videoContainer.innerHTML = '';
	initialmediaURL = "http://www.esm.psu.edu/Faculty/Gray/graphics/movies/reardon_residence1.mov";

   	var videoHTML = '<EMBED ID="video" NAME="video"';
   	videoHTML+= ' AUTOPLAY="false" WIDTH="'+width+'px" HEIGHT="'+height+'px"';
   	videoHTML+= ' AUTOHREF="false"';
   	videoHTML+= ' TYPE="video/quicktime"';
   	videoHTML+= ' CONTROLLER="true"';
   	videoHTML+= ' SRC="'+initialmediaURL+'" />';

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

QuickTimeController.prototype.stop = function()
{
	try {
		this.video.Stop();
	} catch(e){
	}
	this.state1 = "stopped";
}

QuickTimeController.prototype.pause = function()
{
	try {
		this.video.Stop();
	} catch(e){
	}
	this.state1 = "paused";
}

QuickTimeController.prototype.play = function()
{
	this.video.Play();
	this.state1 = "playing";
}

QuickTimeController.prototype.setPosition = function(pos)
{
	this.video.SetTime(pos);
}

QuickTimeController.prototype.getPosition = function()
{
	return this.video.GetTime();
}

QuickTimeController.prototype.setSource = function(source)
{
	//source = "http://www.esm.psu.edu/Faculty/Gray/graphics/movies/reardon_residence1.mov";
	println("Setting to "+source);
	this.video.SetHREF(source);
}

QuickTimeController.prototype.checkState = function()
{
	try {
		this.state = this.video.GetPluginStatus();
	} catch(e) {
		// Crashed
		this.state = "Error";
	}
	//println("State: "+this.state);
}

QuickTimeController.prototype.wasDead = function()
{
	return this.state == "Error";
}

QuickTimeController.prototype.wasStopped = function()
{
	return this.state1 == "stopped";
}

QuickTimeController.prototype.wasBuffering = function()
{
	return this.state == "Loading";
}

QuickTimeController.prototype.wasPlaying = function()
{
	return this.state1 == "playing";
}

QuickTimeController.prototype.wasPaused = function()
{
	return this.state1 == "paused";
}

QuickTimeController.prototype.wasSeeking = function()
{
	return this.state == "Loading";
}
