//################################
 //##Player Control Functions
 //This is an example of usage of the Unicorn Media SDK in communication with the Unicorn Media Player API, and is being provided for your use on an “as is” basis and without warranty implied or otherwise. Use of this software and example is at your own risk and it may not function properly if modified or altered in such a manner as it ceases to interface properly with the Unicorn Media System. If you are having difficulty with the function or implementation of this software, please contact support@unicornmedia.com.
 //################################
  	
// Returns the handle of the movie to interact with.
function thisMovie(movieName) {
  var winobj = undefined;
  var docobj = undefined;
  if (navigator.appName.indexOf("Microsoft") != -1) {
    winobj = window[movieName];
    if (winobj != undefined) {
      return winobj;
    } 
    else {
      docobj = document[movieName];
      if (docobj != undefined)
        return docobj;
    }
  } 
  else {
    docobj = document[movieName];
    if (docobj != undefined)
      return docobj;
  }
  docobj = document.getElementById(movieName);
  return docobj;
}

    	 
 	//////////////////////////////////
 	// Inbound to Flex (Getters)
 	//////////////////////////////////

// Gets the current playhead time (Number)
function GetPlayheadTime(movie) {	
  return thisMovie(movie).UMIExt_JS_GetPlayheadTime();
}

// Gets the current mediaitem title (String)
function GetMediaItemTitle(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemTitle();
}

// Gets the current mediaitem guid (String)
function GetMediaItemGuid(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemGuid();
}

// Gets the current mediaitem duration (Number)
function GetMediaItemDuration(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemDuration();
}  

// Gets the current mediaitem entity name (String)
function GetMediaItemEntityName(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemEntityName();
}

// Gets the current mediaitem type (String) 	
function GetMediaItemType(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemType();
}
	
// Gets the current mediaitem keywords (String)
function GetMediaItemKeywords(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemKeywords();
}  

// Gets the current mediaitem description (String)
function GetMediaItemDescription(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemDescription();
}

// Gets the current volume of the player (Number, 0 - 10)
function GetPlayerVolumeState(movie) {
  return thisMovie(movie).UMIExt_JS_GetPlayerVolumeState();
}

// Gets the current media item ad positions (Array)
function GetMediaItemAdBreaks(movie) {
  var adArray = thisMovie(movie).UMIExt_JS_GetMediaItemAdBreaks();
  var adList = adArray.length + " ads: (";
  for (var i = 0; i < adArray.length; i++) {
	adList = adList + " " + i + ": " + adArray[i].Duration + adArray[i].Type + "@" + adArray[i].SecondsIn + " ";
  }
  adList = adList + ")";
  return adList; 
}

// Gets the current mediaitem rating (String)
function GetMediaItemRating(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemRating();
}  

// Gets the current mediaitem thumbnail URL (String)
function GetMediaItemThumbnailURL(movie) {
  return thisMovie(movie).UMIExt_JS_GetMediaItemThumbnailURL();
}

// Gets the current mute state of the player (uint, 0 = mute on, 1 = mute off)
function GetMuteState(movie) {
  return thisMovie(movie).UMIExt_JS_GetMuteState();
}

// Gets the original embed code for the player instance
function GetPlayerEmbedCode(movie) {
  return thisMovie(movie).UMIExt_JS_GetPlayerEmbedCode();
}
	
// Gets the current Video Ad URL
function GetAdMediaURL(movie) {
  return thisMovie(movie).UMIExt_JS_GetAdMediaURL();
}

// Gets the current Companion Ad ClickThrough URL
function GetAdBannerClickURL(movie) {
  return thisMovie(movie).UMIExt_JS_GetAdCompanionBannerClickURL();
}
	
// Gets the current Companion Ad URL
function GetAdBannerURL(movie) {
  return thisMovie(movie).UMIExt_JS_GetAdCompanionBannerURL();
}

// Gets the current Companion Ad Object (ClickThrough)
function GetAdObjBannerClickURL(movie) {
  var obj = thisMovie(movie).UMIExt_JS_GetAdCompanionAd();
  if (obj != null) { obj.ClickThrough; }
  else { return "" }
}
	
// Gets the current Companion Ad Object (URL)
function GetAdObjBannerURL(movie) {
  var obj = thisMovie(movie).UMIExt_JS_GetAdCompanionAd();
  if (obj != null) { return obj.Url; }
  else { return "" }
}

// Gets the current player state, corresponding to a subset of fl.video.VideoState values (String)
function GetPlayerState(movie) {
  return thisMovie(movie).UMIExt_JS_GetPlayerState();
}
	
// Gets the Entity Thumbnail URL
function GetEntityThumbnailURL(movie) {
  return thisMovie(movie).UMIExt_JS_GetEntityThumbnailURL();
}
	
	////////  Revision 2 Items
	//		// Gets the current Playlist Name
	//		function GetPlaylistName(movie)
	//		{
	//		  	return thisMovie(movie).UMIExt_JS_GetPlaylistName();
	//		}
	//		
	//		// Gets the current Playlist Thumbnail URL
	//		function GetPlaylistThumbnailURL(movie)
	//		{
	//		  	return thisMovie(movie).UMIExt_JS_GetPlaylistThumbnailURL();
	//		}
	

 	//////////////////////////////////
 	// Inbound to Flex (Setters)
 	//////////////////////////////////

// Sets mute off
function SetPlayerMuteOff(movie) {
  thisMovie(movie).UMIExt_JS_SetPlayerMuteOff();
}
	
// Sets mute on
function SetPlayerMuteOn(movie) {
  thisMovie(movie).UMIExt_JS_SetPlayerMuteOn();
}  
	
// Toggles mute
function ToggleMute(movie) {
  thisMovie(movie).UMIExt_JS_ToggleMute();
}  

// Sets player volume (Number, 0 - 10) 	
function SetPlayerVolume(movie, volume) {
  thisMovie(movie).UMIExt_JS_SetPlayerVolume(volume);
}  

 	//////////////////////////////////
 	// Inbound to Flex (Actions)
 	//////////////////////////////////
 	
// Removes the stop-screen, optionally executes the default player start command
function RemoveStopScreen(movie, defaultStart) {
  thisMovie(movie).UMIExt_JS_RemoveStopScreen(defaultStart);
}

// Pauses the current mediaitem
function Pause(movie) {
  thisMovie(movie).UMIExt_JS_Pause();
}
	
// Resumes play of the current mediaitem
function Resume(movie) {
  thisMovie(movie).UMIExt_JS_Resume();
}

// Plays the current mediaitem from position 0
function PlayCurrentItemFromStart(movie) {
  thisMovie(movie).UMIExt_JS_PlayCurrentItemFromStart();
}

// Plays the current mediaitem from specified position
function PlayCurrentItemFromPosition(movie, position) {
  thisMovie(movie).UMIExt_JS_PlayCurrentItemFromPosition(position);
}

// Adds a mediaitem to the queue
function LoadMediaItemInQueue(movie, miGuid) {
  thisMovie(movie).UMIExt_JS_LoadMediaItemInQueue(miGuid);
}
	
// Adds a mediaitem to the queue and plays
function LoadMediaItemInQueueAndPlay(movie, miGuid) {
  thisMovie(movie).UMIExt_JS_LoadMediaItemInQueueAndPlay(miGuid);
}
	
// Adds a mediaitem to the queue and plays from specified position
function LoadMediaItemInQueueAndPlayFromPosition(movie, miGuid, position) {
  thisMovie(movie).UMIExt_JS_LoadMediaItemInQueueAndPlayFromPosition(miGuid, position);
}
	
	////////// Revision 2 Items
	//			// Loads a Playlist into the queue
	//			function LoadPlaylistInQueue(movie, plGUID)
	//			{
	//			  	thisMovie(movie).UMIExt_JS_LoadPlaylistInQueue(plGUID);
	//			}    
	//			
	//			// Loads a Playlist into the queue and plays
	//			function LoadPlaylistInQueueAndPlay(movie, plGUID)
	//			{
	//			  	thisMovie(movie).UMIExt_JS_LoadPlaylistInQueueAndPlay(movie, plGUID);
	//			}    
	//			
	//			// Loads a Playlist into the queue and Plays from given item
	//			function LoadPlaylistInQueueAndPlayFromItem(movie, plGUID)
	//			{
	//			  	thisMovie(movie).UMIExt_JS_LoadPlaylistInQueueAndPlayFromItem(movie, plGUID);
	//			}    
	//			
	//			// Loads a Playlist into the queue and Plays from given item position
	//			function LoadPlaylistInQueueAndPlayFromItemPosition(movie, plGUID)
	//			{
	//			  	thisMovie(movie).UMIExt_JS_LoadPlaylistInQueueAndPlayFromItemPosition(movie, plGUID);
	//			} 
				
// Removes all items from the queue
function ClearQueue(movie) {
  thisMovie(movie).UMIExt_JS_ClearQueue();
}

// Plays the current queue from position 0 (first item)  
function PlayCurrentQueueFromStart(movie) {
  thisMovie(movie).UMIExt_JS_PlayCurrentQueueFromStart();
}
	
// Plays the current queue from specified position   
function PlayCurrentQueueFromItemPosition(movie, position) {
  thisMovie(movie).UMIExt_JS_PlayCurrentQueueFromItemPosition(position);
}
