/**
 *  pfQuicktime.js
 *  --> implements pfVideoInterface.js
 *  
 *  This is a Quicktime plugin wrapper, intended to simplfy
 *  and unify manipulation of video plugins. Quicktime plugin
 *  version as of writing is 7.4. 
 *  
 *  @author Boris Searles (protofunc.com)
 */


// Constructor
function pfQuicktime(movie) {
	this.movie = movie || null;
}

pfQuicktime.prototype.playVideo = function() {
	if(this.movie)
		this.movie.Play();
}

pfQuicktime.prototype.pauseVideo = function() {
	if(this.movie) 
		this.movie.Stop();
}

pfQuicktime.prototype.stopVideo = function() {
	if(this.movie) {
		this.movie.Stop();
		this.movie.Rewind();
	} 
}

pfQuicktime.prototype.getStatus = function(){
	if(this.movie) {
		var status = this.movie.GetPluginStatus();
		switch(status){
            case 'Waiting':
			case 'Loading':
                status = 'loading';
                break;
            case 'Playable':
            case 'Complete':
                status = 'ready';
                break;
			default:
				status = 'error';
		}
		return status;			
	}
}

pfQuicktime.prototype.getTime = function() {
	if(this.movie)
		return this.movie.GetTime() / this.movie.GetTimeScale();
}

pfQuicktime.prototype.setTime = function(sec) {
	if (this.movie) {
		var mediaFrames = sec * this.movie.GetTimeScale();
		this.movie.SetTime(mediaFrames);
	}
}

pfQuicktime.prototype.getDuration = function() {
	if(this.movie) {
		var duration = this.movie.GetDuration(); // returns time scale units
		if(duration == -1) return -1; // -1 returned if movie not fully initialized
		return duration / this.movie.GetTimeScale();
	}
}

pfQuicktime.prototype.getVolume = function() {
	if(this.movie)
		return parseInt(this.movie.GetVolume() * 100 / 255);
}

pfQuicktime.prototype.setVolume = function(vol) {
	if (this.movie)
		this.movie.SetVolume(255 * parseInt(vol) / 100);
}

pfQuicktime.prototype.loadURL = function() {
	if (this.movie) {
		var url = document.getElementById('movie-url').value;
		this.movie.SetURL(url);
		this.movie.SetControllerVisible(false);
	}
}

pfQuicktime.prototype.getBufferStatus = function() {
	if (this.movie) {
		var timenowLoaded = this.movie.GetMaxTimeLoaded()
		var duration = this.movie.GetDuration();
		bufferStatus = parseInt(timenowLoaded * 100 / duration);
		return bufferStatus;
	}
}

pfQuicktime.prototype.setFullscreen = function(){
	// currently not supported
}