//###############################
// MPFErrorCodes
//###############################
/**
 * MPFErrorCodes
 * 	codes for all errors fired out by the player
 * 
 *		Codes 2XXX are FLVController specific 
 *		Codes 3XXX are Player specific 
 * 		Codes 8XXX are Protocol specific
 * 		Codes 11XXX are MediaObject specific
 * 		Codes 12XXX are Generic Controller errors 
 */
MPFErrorCodes = {};

//-----------------------------
// Constants
		
/** 2003 FLVController reports NetStream.Play.NoSupportedTrackFound */
MPFErrorCodes.NO_SUPPORTED_TRACK_FOUND = 2003; 
		
/** 2004 FLVController reports NetStream.FileStructureInvalid */
MPFErrorCodes.FILE_STRUCTURE_INVALID = 2004; 

/** 2005 FLVController reports NetStream.Failed */
MPFErrorCodes.NETSTREAM_FAILED = 2005; 
		
/** 2006 FLVController reports NetStream.PlayFailed */	
MPFErrorCodes.NETSTREAM_PLAY_FAILED	= 2006; 
		
/** 2007 FLVController reports NetStream.InsufficientBW */
MPFErrorCodes.NETSTREAM_PLAY_INSUFFICIENTBW	= 2007;

/** 2008 FLVController reports FlashStreamConnector has encountered a non-supported format. Supported formats are: MBR,MP3,FLV*/
MPFErrorCodes.UNSUPPORTED_FORMAT = 2008;	
		
/** 2009 FLVController reports NetStream.SeekFailed */
MPFErrorCodes.NETSTREAM_SEEK_FAILED	= 2009; 
		
/** 2010 FLVController reports NetStream.InvalidSeekTime - occurs if attempting to seek past last keyframe */		
MPFErrorCodes.NETSTREAM_SEEK_INVALIDTIME = 2010; 
		
/** 2011 Occurs when seek time exceeds media duration  or seek time is less than zero. */
MPFErrorCodes.SEEK_OUTOFBOUNDS = 2011;

/** 2014 Occurs when all attempts to connect to an FMS server have failed */	
MPFErrorCodes.NET_CONNECTION_FAILED	= 2014;	

/** 2014 Occurs when attempts to connect to an FMS server were rejected (SWF verification or Auth failure) */	
MPFErrorCodes.NET_CONNECTION_REJECTED = 2015;
	
/** 2016 Occurs when all attempts to connect to an FMS server have failed  */	
MPFErrorCodes.NET_CONNECTION_CLOSED = 2016;	

/** 2017 Occurs when the attempts to connect to an FMS server have taken to long and time out */
MPFErrorCodes.NET_CONNECTION_TIMEOUT = 2017;
	
/** 2018 Occurs when the player didn't have the property permissions to make a remote FMS connection request  */	
MPFErrorCodes.NET_CONNECTION_SECURITY_ERROR = 2018;	

/** 2019 Occurs when an async event with the server goes unhandled by the player  */	
MPFErrorCodes.NET_CONNECTION_ASYNC_ERROR = 2019;	


/** 3001 An unsupported media type was passed to the Player*/		
MPFErrorCodes.UNSUPPORTED_MEDIA_TYPE = 3001;	

/** 8001 Occurs when a streaming or progressive download protocol cannot be determined from available data*/
MPFErrorCodes.UNSUPPORTED_PROTOCOL_TYPE = 8001;	

/** 11001  Occurs if a custom StreamConnector class is not of the correct type*/
MPFErrorCodes.CONNECTOR_TYPE_INVALID = 11001;
	
/** 12001 Occurs on an invalid NetStream request. */ 
MPFErrorCodes.MEDIA_NOT_FOUND = 12001;





//###############################
// ConnectorType
//###############################
/**
 * ConnectorType
 * 	specifies the connector type to use when connecting to FMS servers
 */
ConnectorType = {};

//-----------------------------
// Constants

/** a multiple protocol/port attempt to connect to an FMS server. */ 
ConnectorType.SHOTGUN = "shotgun";

/** a simple native FP based attempt to connect to an FMS server */ 
ConnectorType.SIMPLE = "simple";






//###############################
// ScaleMode
//###############################
/**
 * ScaleMode
 * 	specifies the scale mode for a display
 */
ScaleMode = {};

//-----------------------------
// Constants

/** scales up and down, but maintains aspect ratio. */ 
ScaleMode.UNIFORM = "uniform";

/** scales down only (if content is bigger than view), but maintains aspect ratio. */ 
ScaleMode.UNIFORM_DOWN = "uniformDown";

/** does not apply any scaling. */ 
ScaleMode.NONE = "none";

/** fills a display to the exact dimensions of a view and doesn't maintain aspect ratio. */
ScaleMode.FILL = "fill";

/** maintains aspect ratio. but fills the screen competely with content */
ScaleMode.UNIFORM_FILL = "uniformFill";



//###############################
// PlayerEventType
//###############################
/**
 * PlayerEventType
 * 	specifies the event types thrown by the player
 */
PlayerEventType = {};

//-----------------------------
// Constants

PlayerEventType.CUE_POINT_TRIGGERED = "cuePointTriggered";
PlayerEventType.INITIALIZED = "initialized";
PlayerEventType.MEDIA_FAILED = "mediaFailed";
PlayerEventType.MEDIA_EXPIRED = "mediaExpired";
PlayerEventType.MEDIA_PAUSED = "mediaPaused";
PlayerEventType.MEDIA_RESUMED = "mediaResumed";
PlayerEventType.MEDIA_STARTED = "mediaStarted";
PlayerEventType.MEDIA_COMPLETED = "mediaCompleted";
PlayerEventType.MEDIA_STALLED = "mediaStalled";
PlayerEventType.MEDIA_AUTH_FAILED = "mediaAuthFailed";
PlayerEventType.MEDIA_AUTH_SUCCEEDED = "mediaAuthSucceeded";
PlayerEventType.POPOUT_REQUESTED = "popoutRequested";
PlayerEventType.PULSE_CLEAR_PREVIOUS_SESSION = "pulseClearPreviousSession";
PlayerEventType.PULSE_FAILED = "pulseFailed";
PlayerEventType.QUALITY_HELP_REQUESTED = "qualityHelpRequested";
PlayerEventType.QUALITY_SPECS_REQUESTED = "qualitySpecsRequested";




//###############################
// OmnitureConfig
//###############################
/**
 * OmnitureConfig
 * 	configuration for setting up Omniture for a player
 */
function OmnitureConfig()
{
	this.pageURL = document.location;
	this.pageName = document.title;
}

//-----------------------------
// Properties

// define values for defaults, but still allow for instance overrides
OmnitureConfig.prototype.account = "wdgfepmpf2";
OmnitureConfig.prototype.dc = "112";

OmnitureConfig.prototype.pageName = null;
OmnitureConfig.prototype.pageType  = "DOL testPage";
OmnitureConfig.prototype.pageURL = null;
			
OmnitureConfig.prototype.playerName = "D2CPlayer";
OmnitureConfig.prototype.trackingServer = "w88.go.com";
OmnitureConfig.prototype.trackingServerSecure = "sw88.go.com";
OmnitureConfig.prototype.visitorNamespace = "fullepisodePlayer";

/** 
 * Defines the interval, as a percentage of the video watched. 
 * Specify the milestones as a comma-separated string of whole numbers. 
 * DO NOT SPECIFY 0, 100 or you get double counts (EX: "20,40,60,80) 
 * NOTE: you can use either trackMilestones or trackSeconds not both
 * if you define both trackMilestones and trackSeconds, trackSeconds will be used
 */
OmnitureConfig.prototype.trackMilestones = null;

/**
 * Defines the interval, in seconds, for sending video tracking data.
 * The value must be set in increments of 5 seconds.
 * Setting the value to 15, will send a track every 15 seconds that the video is playing.
 * NOTE: you can use either trackMilestones or trackSeconds not both
 * if you define both trackMilestones and trackSeconds, trackSeconds will be used
 */
OmnitureConfig.prototype.trackSeconds = null;

/** returns an XML string representation of the Omniture config. */
OmnitureConfig.prototype.toXMLString = function()
{
	var s = "";
	
	s += "<omniture>";
	
	if (this.account != undefined && this.account != null)
		s += "<account>" + this.account + "</account>";
	if(this.dc != undefined &&this.dc != null)
		s += "<dc>" + this.dc + "</dc>";
	if (this.pageName != undefined &&this.pageName != null) 
		s += "<pageName>" + this.pageName + "</pageName>";
	if (this.pageType != undefined &&this.pageURL != null)
		s += "<pageType>" + this.pageType + "</pageType>";
	if (this.pageURL != undefined &&this.pageURL != null) 
		s += "<pageURL>" + this.pageURL + "</pageURL>";
	if (this.playerName != undefined && this.playerName != null) 
		s += "<playerName>" + this.playerName + "</playerName>";

	if(this.trackSeconds != undefined && this.trackSeconds != null)
	{
		if(this.trackSeconds < 5 || (this.trackSeconds % 5) != 0)
			alert("OmnitureConfig.trackSeconds must be in increments of 5");
		else
			s += "<trackSeconds>" + this.trackSeconds + "</trackSeconds>";
	}		
	else if(this.trackMilestones != undefined && this.trackMilestones != null)
	{
		s += "<trackMilestones>" + this.trackMilestones + "</trackMilestones>";
	}
		
	if (this.trackingServer != undefined && this.trackingServer != null) 	
		s += "<trackingServer>" + this.trackingServer + "</trackingServer>";
	if (this.trackingServerSecure != undefined && this.trackingServerSecure != null) 		
		s += "<trackingServerSecure>" + this.trackingServer + "</trackingServerSecure>";
	if (this.visitorNamespace != undefined && this.visitorNamespace != null) 
		s += "<visitorNamespace>" + this.visitorNamespace + "</visitorNamespace>";
		
	s += "</omniture>";	

	return s;
}

//###############################
// ConvivaConfig
//###############################
/**
 * ConvivaConfig
 * 	properites for the Conviva
 */
function ConvivaConfig()
{
	this.eventTags = {};
	this.customerID = document.getElementById('convivaCID').innerHTML;
	
}

//-----------------------------
// Properties

// define values for defaults, but still allow for instance overrides
ConvivaConfig.prototype.eventTags = null;
ConvivaConfig.prototype.serviceURL = "http://livepass.conviva.com";
//ConvivaConfig.prototype.customerID = "c3.DisneyMoviesOnline";
ConvivaConfig.prototype.pluginNamespace = "http://www.conviva.com"
ConvivaConfig.prototype.pluginURL = "http://livepassdl.conviva.com/OSMF/ConvivaOSMFPlugin-1.0.16313.swf";
ConvivaConfig.prototype.pageURL = document.location;
ConvivaConfig.prototype.useEMS = true;
ConvivaConfig.prototype.userID = null;

/** returns an XML string representation of the services config. */
ConvivaConfig.prototype.toXMLString = function()
{
	var s = "";
	var prop;
	
	s += "<conviva>";
	s += "<pageURL>" + this.pageURL + "</pageURL>";
	s += "<serviceURL>" + this.serviceURL + "</serviceURL>";
	s += "<eventTags>";
	
	for(prop in this.eventTags) 
		s+= "<" + prop + ">" + this.eventTags[prop] + "</" + prop + ">";
		
	s += "</eventTags>";
	s += "<customerID>" + this.customerID + "</customerID>";
	s += "<pluginNamespace>" + this.pluginNamespace + "</pluginNamespace>";
	if(this.pluginURL != null && this.pluginURL != undefined)
		s += "<pluginURL>" + this.pluginURL + "</pluginURL>";	
	s += "<useEMS>" + (this.useEMS ? "true" : "false") + "</useEMS>";		
	if(this.userID != null && this.userID != undefined)
		s += "<userID>" + this.userID + "</userID>";	
	s += "</conviva>";	
	
	return s;
}


//###############################
// AnalyticsConfig
//###############################
/**
 * AnalyticsConfig
 * 	properites for the analytics
 */
function AnalyticsConfig()
{
}

AnalyticsConfig.prototype.conviva = new ConvivaConfig();
AnalyticsConfig.prototype.omniture = new OmnitureConfig();


AnalyticsConfig.prototype.toXMLString = function()
{
	var s = "";
	
	s += "<analytics>";
	s += this.conviva.toXMLString();
	s += this.omniture.toXMLString();
	s += "</analytics>";	
	
	return s;
}
//###############################
// ServicesConfig
//###############################
/**
 * ServicesConfig
 * 	properites for the services
 */
function ServicesConfig()
{
	this.heartbeatURL = document.getElementById('pingBackUrl').href;
	this.authBaseURL = document.getElementById('tokenGenerationUrl').href;
	this.errorNotificationURL = document.getElementById('errorNotificationUrl').href;
}

//-----------------------------
// Properties

// define values for defaults, but still allow for instance overrides
//moving toward overriding these in the constructor
//ServicesConfig.prototype.heartbeatURL = "http://enhdold2c03.wdig.com:4280/pingBack/challenge";
//ServicesConfig.prototype.authBaseURL = "http://enhdold2c03.wdig.com:4180/service/tokenGenService?swid=12345";
//ServicesConfig.prototype.errorNotificationURL = "";

/** returns an XML string representation of the services config. */
ServicesConfig.prototype.toXMLString = function()
{
	var s = "";
	
	s += "<servicesConfig>";
	s += "<heartbeatURL>" + this.heartbeatURL + "</heartbeatURL>";
	s += "<authBaseURL>" + this.authBaseURL + "</authBaseURL>";
	s += "<errorNotificationURL>" + this.errorNotificationURL + "</errorNotificationURL>";
	s += "</servicesConfig>";	
	
	return s;
}


//###############################
// PlayerType
//###############################
/**
 * PlayerType
 */
PlayerType = {};

//-----------------------------
// Constants

/** main player type */
PlayerType.DEFAULT = "default";

/** pop out window */
PlayerType.POPOUT = "popout";



//###############################
// PlayerConfig
//###############################
/**
 * PlayerConfig
 * 	properites for configuring the player
 */
function PlayerConfig(p_externalEventHandler, p_userID)
{
	this.externalEventHandler = p_externalEventHandler;
	this.userID = p_userID; 
}

/** specifies the external JavaScript function that handles events from the Flash media player. */
PlayerConfig.prototype.externalEventHandler = null;

/** specifies the user's ID. */
PlayerConfig.prototype.loggingEnabled = true;
PlayerConfig.prototype.userID = null;
PlayerConfig.prototype.useFullScreenHardwareAcceleration = true;
PlayerConfig.prototype.playerType = PlayerType.DEFAULT;
PlayerConfig.prototype.analytics = new AnalyticsConfig();
PlayerConfig.prototype.services = new ServicesConfig();
PlayerConfig.prototype.serverMaxBurstRate = 1.6;
//-----------------------------
// Properties

PlayerConfig.prototype.toXMLString = function()
{
	var s = ""
	
	s += "<playerConfig>";
	
	if(this.userID != null && this.userID != undefined)
		s += "<userID>" + this.userID + "</userID>";
	s += "<loggingEnabled>" + (this.loggingEnabled ? "true" : "false") + "</loggingEnabled>";			
	s += "<playerType>" + this.playerType + "</playerType>";	
	s += "<externalEventHandler>" + this.externalEventHandler + "</externalEventHandler>";
	
	s += "<serverMaxBurstRate>" + this.serverMaxBurstRate + "</serverMaxBurstRate>";
	s += "<useFullScreenHardwareAcceleration>" + this.useFullScreenHardwareAcceleration + "</useFullScreenHardwareAcceleration>";
	s += this.analytics.toXMLString();
	s += this.services.toXMLString();
	s += "</playerConfig>";
	
	return s;
}





//###############################
// MediaFormats
//###############################
/**
 * MediaFormats
 * 	constants for each of the media formats supported by the MediaObject
 */
MediaFormats = {};

//-----------------------------
// Constants

/** Used for al Flash video types, with the exception of Multi-BitRate streams. */
MediaFormats.FLV = "flv";

/** Used exclusively for Multi-BitRate streaming from an FMS server */
MediaFormats.MBR = "mbr";





//###############################
// ProtocolTypes
//###############################
/**
 * ProtocolTypes
 * 	constants that specify the methods of delivery for MediaObjects
 */
ProtocolTypes = {};

//-----------------------------
// Constants

/** specifies that a progressive protocol be used */
ProtocolTypes.PROGRESSIVE = "progressive";

/** specifies that a streaming protocol be used */
ProtocolTypes.STREAMING = "streaming";





//###############################
// StreamItemEntry
//###############################
/**
 * StreamItemEntry
 * 	The StreamItemEntry object is a single bitrate stream
 * @param {String} p_stream - name/url for a stream
 * @param {Number} p_bitrate - bitrate for this stream
 */
function StreamItemEntry(p_stream, p_bitrate)
{
	this.stream = p_stream;
	this.bitrate = p_bitrate == null ? -1 : p_bitrate;
}

//-----------------------------
// Properties

/** [Optional] specifies  name/url for a stream */
StreamItemEntry.prototype.stream = null;

/** [Optional] specifies bitrate for this stream */
StreamItemEntry.prototype.bitrate = -1;





//###############################
// StreamItem
//###############################
/**
 * StreamItem
 * 	The StreamItem object maintains and manages the collection of cue points assigned to a MediaObject
 * @param {String} p_stream - name/url for a stream
 * @param {Number} p_bitrate - bitrate for this stream
 */
function StreamItem(p_stream, p_bitrate)
{
	this.streams = [];
	
	if (p_stream != null && p_stream != undefined) 
	{
		this.addStream(p_stream, p_bitrate);
	}
}

//-----------------------------
// Properties

/** [Optional] specifies max buffer length for the item */
StreamItem.prototype.defaultBitrate = -1;

/** [Optional] specifies max buffer length for the item */
StreamItem.prototype.maxBufferLength = null;

/** [Optional] specifies min buffer length for the item */
StreamItem.prototype.minBufferLength = null;

/** specifies an Array containing all the child StreamItemEntry objects */
StreamItem.prototype.streams = null;

//-----------------------------
// Methods

/** adds a StreamItemEntry object to this StreamItem's collection. Each StreamItemEntry represents a different bitrate */
StreamItem.prototype.addStream = function(p_stream, p_bitrate)
{
	this.streams.push(new StreamItemEntry(p_stream, p_bitrate));
}





//###############################
// CuePoint
//###############################
/**
 * CuePoint
 * 	Represents an object that can be triggered at a point in time for a video
 * @param {String} p_id - specifies the ID for the cuePoint
 * @param {Number} p_timeCode - specifies the timeCode at which the cuePoint will be triggered
 */
function CuePoint(p_id, p_timeCode)
{
	this.id = p_id;
	this.timeCode = p_timeCode;
}

//-----------------------------
// Properties

/** specifies the ID for the cuePoint */
CuePoint.prototype.id = null;

/** specifies the timeCode at which the cuePoint will be triggered */
CuePoint.prototype.timeCode = null;




//###############################
// CuePointCollection
//###############################
/**
 * CuePointCollection
 * 	The CuePointCollection object maintains and manages the collection of cue points assigned to a media object. d
 */
function CuePointCollection()
{
	this.allCuePoints = [];
}

//-----------------------------
// Properties

/** specifies an Array containing all CuePoint objects */
CuePointCollection.prototype.allCuePoints = null;

//-----------------------------
// Methods

/** 
 * adds a CuePoint object to the collection 
 * @param {Object} p_cuePoint - CuePoint to add
 */
CuePointCollection.prototype.addCuePoint = function(p_cuePoint)
{
	this.allCuePoints.push(p_cuePoint);
}




//###############################
// MediaChapter
//###############################
/**
 * MediaChapter
 * 	Represents a chapter for the media
 */
function MediaChapter(p_start, p_imageURL, p_title)
{
	this.start = p_start;
	this.end = p_start;
	this.imageURL = p_imageURL;
	this.title = p_title;
}

//-----------------------------
// Properties

/** specifies the title of the chapter */
MediaChapter.prototype.title = null;

/** specifies the image associated with the chapter */
MediaChapter.prototype.imageURL = null;

/** specifies the start of the chapter */
MediaChapter.prototype.start = -1;

/** specifies the end of the chapter */
MediaChapter.prototype.end = -1;





//###############################
// MediaObject
//###############################
/**
 * MediaObject
 * 
 * An object that defines a media instance to be played by the media player
 * 
 * @param {Object} p_name - title of the media
 * @param {Object} p_URL - media's URL path
 * @param {Object} p_id - media's ID
 * @param {Object} p_format - format of the media
 * @param {Object} p_protocol [OPTIONAL] method of delivery "progressive" or "streaming" (default: progressive)
 * @param {Object} p_streamItem [OPTIONAL]
 */
function MediaObject(p_name, p_URL, p_id, p_format, p_protocol, p_streamItem)
{
	this.chapters = [];
	this.name = p_name;
	this.url = p_URL;
	this.id = p_id; 
	this.format = p_format; 
	this.protocol = p_protocol == null ? ProtocolTypes.PROGRESSIVE : p_protocol;
	this.streamItem = p_streamItem;
	var playbackEntitlementElement = document.getElementById('playbackEntitlement');
	if (typeof playbackEntitlementElement != 'undefined' && playbackEntitlementElement != null)
	{
		this.entitlement = document.getElementById('playbackEntitlement').textContent;
	} else {
		this.entitlement = null;
	}
}

//-----------------------------
// Properties

/** specifies whether the media will autoPlay or not */
MediaObject.prototype.autoPlay = true;

MediaObject.prototype.bufferTime = null;

/** specifies the chapters associated with the media */
MediaObject.prototype.chapters = null;

/** specifies the connector type to use when attempting to connect to an FMS server */
MediaObject.prototype.connectorType = ConnectorType.SHOTGUN;

/** specifies the entitlement of a video */
//Set in constructor
//MediaObject.prototype.entitlement = null;

/** specifies the message to display when loading */
MediaObject.prototype.loadingMessage = null;

/** specifies the poster image for the media */
MediaObject.prototype.posterURL = null;

/** specifies whether the media can be resumed from the position last viewed by the user */
MediaObject.prototype.resumable = false;

/** specifies the title for a media object (used in tracking) */
MediaObject.prototype.name = null;

/** specifies the URL path to the media */
MediaObject.prototype.url = null;

/** specifies the ID used to identify the media instance */
MediaObject.prototype.id = null;

/** specifies the format type for the media instance @see MediaFormats */
MediaObject.prototype.format = null;

/** [OPTIONAL] specifies the delivery method for the media instance @see ProtocolTypes */
MediaObject.prototype.protocol = ProtocolTypes.PROGRESSIVE;

/** [OPTIONAL] specifies a scale mode of the media */
MediaObject.prototype.scaleMode = ScaleMode.UNIFORM;

/** [OPTIONAL] specifies a stream collection of variant bitrate streams to use @see StreamItem */
MediaObject.prototype.streamItem = null;

/** [OPTIONAL] specifies a CuePointCollection containing cuePoints to be fired while a media instance is playing */
MediaObject.prototype.cuePointCollection = null;

/** specifies whether the object is secure or not */
MediaObject.prototype.secure = false;

/** [OPTIONAL] specifies the lock limit for dropped frames */
MediaObject.prototype.droppedFramesLockLimit = 8;	


//###############################
// SecureMediaObject
//###############################
/**
 * SecureMediaObject
 * 
 * An object that defines secure media to be played by the media player
 * 
 * @param {Object} p_name - title of the media
 * @param {Object} p_id - media's ID
 */
function SecureMediaObject(p_name, p_id)
{
	this.name = p_name;
	this.id = p_id; 
}

// define super class
SecureMediaObject.prototype = new MediaObject();
SecureMediaObject.prototype.constructor = SecureMediaObject;

// override defaults for super class properties
SecureMediaObject.prototype.secure = true;
SecureMediaObject.prototype.format = MediaFormats.MBR;
SecureMediaObject.prototype.protocol = ProtocolTypes.STREAMING;

