/***
*	RealPlayer 0.0.1
*
*	An implementation class for the MediaPlayer Interface.  
*	Should be called by the MediaPlayerFactory.
*
*	(c) 2006 Tachometry Corporation.  
*	contact: support@tachometry.com
*
*	Licensed under the Apache License (v. 2.0)
*	http://www.apache.org/licenses/LICENSE-2.0
*/

/**
*	Inherit from MediaPlayer
*/
RealPlayer.prototype = new MediaPlayer();
RealPlayer.prototype.constructor = RealPlayer;
RealPlayer.superclass = MediaPlayer.prototype;

/**
*	Constructor
*/
function RealPlayer(src, width, height, version)
{
	this.init(src, width, height, version);
}

/**
*	Initializor
*/ 
RealPlayer.prototype.init = function(src, width, height, version) {    
    RealPlayer.superclass.init.call(this, src, width, height);
    this.setRequiredVersion( version || "1" );
	this.setPlayerClassId( "clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" );
	//this.setApplicationType("video/x-pn-realvideo");
	this.setApplicationType("audio/x-pn-realaudio-plugin");
	this.setPluginName( "Real Player" );
	this.setParam("autostart",true);
	this.setParam("console","one");
	this.controlsheight = 36;
}

/**
*	Player Controls
*/ 

RealPlayer.prototype.play = function() {
	this.getPlayerElement().DoPlay();
}

RealPlayer.prototype.pause = function() {
	this.getPlayerElement().DoPause();
}

RealPlayer.prototype.stop = function() {
	this.getPlayerElement().DoStop();
}

RealPlayer.prototype.playPause = function() {
	this.getPlayerElement().DoPlayPause();
}

RealPlayer.prototype.canPlay = function() {
	return this.getPlayerElement().CanPlay();
}

RealPlayer.prototype.canPause = function() {
	return this.getPlayerElement().CanPause();
}

RealPlayer.prototype.canStop = function() {
	return this.getPlayerElement().CanStop();
}

RealPlayer.prototype.canPlayPause = function() {
	return this.getPlayerElement().CanPlayPause();
}

/**
*	Stream State Controls
*/ 
RealPlayer.prototype.canSeek = function() {
	return this.getPlayerElement().GetCanSeek();
}

/* Returns the length of the clip in milliseconds */
RealPlayer.prototype.getLength = function() {
	return this.getPlayerElement().GetLength();
}

/* Returns the current position of the clip in milliseconds */
RealPlayer.prototype.getPosition = function() {
	return this.getPlayerElement().GetPosition();
}

/* Sets the position of the clip.  Requires a a position in milliseconds */
RealPlayer.prototype.setPosition = function( new_milli_position ) {
	if ( new_milli_position != null ) {
		this.getPlayerElement().SetPosition( new_milli_position );
	}
}

/* Is the clip a live stream? */
RealPlayer.prototype.isLiveStream = function() {
	return this.getPlayerElement().GetLiveState();
}

/* Returns the title of the current stream */
RealPlayer.prototype.getStreamTitle = function() {
	return this.getPlayerElement().GetTitle();
}

/* Returns the copyright of the current stream */
RealPlayer.prototype.getClipCopyright = function() {
	return this.getPlayerElement().GetCopyright();
}

/* Returns the current play state of the stream */
RealPlayer.prototype.getPlayerState = function() {
	var state = this.getPlayerElement().GetPlayState();
	return this.getStateMap( state );
}

/* Returns the number of entiries in the playlist. */
RealPlayer.prototype.getNumClips = function() {
	return this.getPlayerElement().GetNumEntries();
}

/* Returns the index of the current entry in the playlist */
RealPlayer.prototype.getClipIndex = function() {
	return this.getPlayerElement().GetCurrentEntry();
}

/* Returns the title of the current entry in the playlist */
RealPlayer.prototype.getClipTitle = function( clip_index ) {
	var title = "";
	try {
		title = this.getPlayerElement().GetEntryTitle( clip_index - 0 );
	} catch (e) {
		new Error("The player mehod GetEntryTitle returned an error:" + e);
	}
	return title;
}

/* Returns the version information for the embedded player */
RealPlayer.prototype.getPlayerVersion = function() {
	return this.getPlayerElement().GetVersionInfo();
};

RealPlayer.prototype.getHTML = function()
{
    var html = "";
	html += '<div class="theVideo">';
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
		// Image window
        html += '<object classid="' + this.getPlayerClassId() + '" width="' + this.getWidth() + '" height="' + this.getHeight() + '" id="' + this.getObjectId() + '"';
		if (this.getCodebase != "") { html += ' codebase="' + this.getCodebase() + '"'; }
		if (this.getApplicationType != "") { html += ' type="' + this.getApplicationType() + '"'; }
		html += '>';
        html += '<param name="src" value="' + this.getSrc() + '" />';;
        if (this.getParamTags() != null) {
            html += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            html += '<param name="realVars" value="' + this.getVariablePairs() + '" />';
        }
		html += '<param name="controls" value="ImageWindow">';
        html += '</object></div>';
		
		// Controller
		
		html += '<div class="theControls">';
		html += '<object classid="' + this.getPlayerClassId() + '" width="' + this.getWidth() + '" height="' + this.controlsheight + '" id="' + this.getObjectId() + '1"';
		if (this.getCodebase != "") { html += ' codebase="' + this.getCodebase() + '"'; }
		if (this.getApplicationType != "") { html += ' type="' + this.getApplicationType() + '"'; }
		html += '>';
        html += '<param name="src" value="' + this.getSrc() + '" />';;
        if (this.getParamTags() != null) {
            html += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            html += '<param name="realVars" value="' + this.getVariablePairs() + '" />';
        }
		html += '<param name="controls" value="ControlPanel">';
        html += '</object></div>';
		
    }
    else { // Everyone else
		// First put in the Image Window
        html += '<embed src="' + this.getSrc() + '" width="' + this.getWidth() + '" height="' + this.getHeight() + '" id="' + this.getObjectId() + '" name="' + this.getObjectId() +'"';
        for (var param in this.getParams()) {
            html += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            html += ' realVars="' + this.getVariablePairs() + '"';
        }
		html += ' CONTROLS="ImageWindow" SCRIPTCALLBACKS="NONE" ';
        html += '></embed></div>';
		
		// Now add the controls
		
		html += '<div class="theControls">';
		
		html += '<embed src="' + this.getSrc() + '" width="' + this.getWidth() + '" height="' + this.controlsheight + '" id="' + this.getObjectId() + '1" name="' + this.getObjectId() +'1"';
        for (var param in this.getParams()) {
            html += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            html += ' realVars="' + this.getVariablePairs() + '"';
        }
		html += ' CONTROLS="ControlPanel" ';
        html += '></embed>';
    }
	html += '</div>';
    return html;
};



document.write('<OBJECT ID="'+ this.getObjectId +'" WIDTH=0 HEIGHT=0 CLASSID="CLSID:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"></OBJECT>');

