/**
 *  pfWMP.js
 *  --> implements pfVideoInterface.js
 *  
 *  This is a WMP plugin wrapper based on
 *	protofumc.com's Quicktime wrapper. 
 *  
 *  @author Boris Searles (protofunc.com)
 *	modded by Paul Ford (pauleford@gmail.com)
 */

// Constructor
function pfWMP(movie) {
	this.movie = new Object();
	this.movie = movie || null;
}

pfWMP.prototype.playVideo = function() {
	if(this.movie) {
		if(browser == 'ie')	{
			this.movie.Play();			
		} else {
			this.movie.controls.play();
		}
	}
}

pfWMP.prototype.pauseVideo = function() {
	if(this.movie) {
		if(browser == 'ie')	{
			this.movie.Pause();
		} else {
			this.movie.controls.pause();
		}
	}
}

pfWMP.prototype.stopVideo = function() {
	if(this.movie) {
		if(browser == 'ie')	{
			this.movie.Stop();
		} else {
			this.movie.controls.stop();
		}
	}
}

pfWMP.prototype.getStatus = function() {
	if(this.movie) {
		if(browser == 'ie') {
			var status = {num : this.movie.playState, name : 'none'};
			switch(status.num) {
				case 6: // buffering
				case 9: // transitioning
				case 11: // reconnecting
					status.name = 'loading';
					break;
				case 0: // undefined
				case 1: // stopeed
				case 2: // paused
				case 4: // scan fwd
				case 5: // scan rvs
				case 7: // waiting
				case 3: // playing
				case 10: // ready
					status.name = 'ready';
					break;
				case 8: // media ended
					status.name = 'stopped';
					break;
				default:
					status.name = 'error';
			}
		} else {
			var status = {num : this.movie.controls.playState, name : 'none'};
			switch(status.num) {
				case 6: // buffering
				case 9: // transitioning
				case 11: // reconnecting
					status.name = 'loading';
					break;
				case 0: // undefined
				case 1: // stopeed
				case 2: // paused
				case 4: // scan fwd
				case 5: // scan rvs
				case 7: // waiting
				case 3: // playing
				case 10: // ready
					status.name = 'ready';
					break;
				case 8: // media ended
					status.name = 'stopped';
					break;
				default:
					status.name = 'error';
			}
		}
		return status;
	}
}

pfWMP.prototype.getOpenState = function() {
	if(this.movie) {
		if(browser == 'ie') {
			var state = this.movie.openState;
		} else {
			var state = this.movie.openState;
		}
		return state;
		/*
		0 	Undefined 	Windows Media Player is in an undefined state.
		1 	PlaylistChanging 	New playlist is about to be loaded.
		2 	PlaylistLocating 	Windows Media Player is attempting to locate the playlist. The playlist can be local (library or metafile with an .asx file name extension) or remote.
		3 	PlaylistConnecting 	Connecting to the playlist.
		4 	PlaylistLoading 	Playlist has been found and is now being retrieved.
		5 	PlaylistOpening 	Playlist has been retrieved and is now being parsed and loaded.
		6 	PlaylistOpenNoMedia 	Playlist is open.
		7 	PlaylistChanged 	A new playlist has been assigned to currentPlaylist.
		8 	MediaChanging 	A new media item is about to be loaded.
		9 	MediaLocating 	Windows Media Player is locating the media item. The file can be local or remote.
		10 	MediaConnecting 	Connecting to the server that holds the media item.
		11 	MediaLoading 	Media item has been located and is now being retrieved.
		12 	MediaOpening 	Media item has been retrieved and is now being opened.
		13 	MediaOpen 	Media item is now open.
		14 	BeginCodecAcquisition 	Starting codec acquisition.
		15 	EndCodecAcquisition 	Codec acquisition is complete.
		16 	BeginLicenseAcquisition 	Acquiring a license to play DRM protected content.
		17 	EndLicenseAcquisition 	License to play DRM protected content has been acquired.
		18 	BeginIndividualization 	Begin DRM Individualization.
		19 	EndIndividualization 	DRM individualization has been completed.
		20 	MediaWaiting 	Waiting for media item.
		21 	OpeningUnknownURL 	Opening a URL with an unknown type.*/
	}
}

pfWMP.prototype.getTime = function() {
	if(this.movie) {
		if(browser == 'ie')	{
			return this.movie.currentPosition;
		} else {
			return this.movie.controls.currentPosition;
		}
	}
}

pfWMP.prototype.setTime = function(sec) {
	if(this.movie) {
		if(browser == 'ie')	{
			this.movie.currentPosition = sec;
		} else {
			this.movie.controls.currentPosition = sec;
		}
	}
}

pfWMP.prototype.getDuration = function() {
	if(this.movie) {
		if(browser == 'ie')	{
			return this.movie.selectionEnd;
		} else {
			return this.movie.currentMedia.duration;
		}
	}
}

/*pfWMP.prototype.getVolume = function() {
	if(this.movie)
		return parseInt(this.movie.GetVolume() * 100 / 255);
}

pfWMP.prototype.setVolume = function(vol) {
	if (this.movie)
		this.movie.SetVolume(255 * parseInt(vol) / 100);
}*/

pfWMP.prototype.loadURL = function(url) {
	if (this.movie) {
		if (browser == 'ie') {
			this.movie.FileName = url;
		} else {
			// Firefox 2
			if ( navigator.userAgent.match('Firefox/2') || safari == true ) this.movie.URL = url;
			// Firefox 3
			else this.movie.data = url;
		}
	}
}

/*pfWMP.prototype.getBufferStatus = function() {
	if (this.movie) {
		var timenowLoaded = this.movie.GetMaxTimeLoaded()
		var duration = this.movie.GetDuration();
		bufferStatus = parseInt(timenowLoaded * 100 / duration);
		return bufferStatus;
	}
}

pfWMP.prototype.setFullscreen = function() {
	// currently not supported
}*/
