// OD 2011
// JavaScript Player Controls
//
//**********************************************************************
// Video Source Setup
//**********************************************************************
// Configure the source in the below object to instantly load and play
// play the video automatically. If you would like to pass the video
// to the player from and external source (i.e. playlist), then comment
// out
var videoObj = new Object();  

function passObj(obj)
{
	
 videoObj = obj;	
 //alert(videoObj._protocol+"<--->"+videoObj.hostApp+"<--->"+videoObj.videoFeeds+"<--->"+videoObj.eventType+"<--->"+videoObj.thumbnailURL+"<--->"+videoObj.seekOffset+"<--->"+videoObj.clipTitle+"<--->"+videoObj.clipList+"<--->"+videoObj.volume);
}

// Event type is either "live" or "vod". Live mode will disable the seek bar. If the event is live, on the Akamai HD
// Network, and has DVR capabilities enabled on the stream, select "vod" as the event type to enable time shift.
//videoObj.eventType = "vod";

// Delivery protocal of stream - values are HD (Akamai HD Network), RTMP, RTMPT, RTMPE, RTMPTE, or RTMP-ANY (will try all)
//videoObj._protocol = "HD"; 

/*
// The hostApp is the host or base name for the stream without the protocol (rtmp:// or http:// for HD), for example:
//
// rtmp://cp81944.edgefcs.net/ondemand/marketing/mp4:/Edition11_final_1200.mp4
//
// would be: "cp81944.edgefcs.net/ondemand/maketing/"
*/
//videoObj.hostApp = "sandboxsd-f.akamaihd.net";

// videoFeeds is where you define one, or more (for adaptive) stream bit rates.
// The format is "feed|bitrate,feed|bitrate,feed|bitrate,..."
// Bit rates should be expressed in bytes - 900 kbps = 900000, 1200 kbps = 1200000
// HD network example: "rf_livestream_1500k@45647|1500000,crf_livestream_1000k@45647|100000"
//videoObj.videoFeeds = "20110608/1f145fc7-0573-48e9-8dfc-dc1d29ee69931_Ike Video2_640x360_696.mp4|696000";

// If you would like to display a thumbnail instead of auto-starting the player, specify a URL. Otherwise leave it
// blank and the player will auto start
//videoObj.thumbnailURL = "";

// The number of seconds into the video to start playing from (VOD only), leave blank or comment out to start at beginning
//videoObj.seekOffset = "";

// This is the clip title that will display in the player while the player while controls are visible
//videoObj.clipTitle = "Test Title";

// Play only portion of the video: totalHighlightTime|seektime|videoendTime,
// i.e. start at second 55 and play to 60 for a total highligh length of 5 seconds would be "5|55|60"
//videoObj.clipList="";

// Specify the default volume when the player loads - 1 is full volume, 0 is off 
//videoObj.volume = 1;



// This function will be triggered by the player when it is fully loaded.
function playerReady(val){
	setPlaybackControlVisible(true);  // Set to "false" if you do not want the player controls visible
	setPlaybackControlAutohide(true);  // Set to "false" if if you do not want the controls to auto-hide
	setTitleBarVisible(true);         // Set to "false" if you do not want the title bar visible
	playerAction("loadVideo",true,videoObj);  // This tells the player to play the video defined above
}

 
//********************************************************************
// External Player Controls
//********************************************************************
// You can us the following functions to create external buttons that will control
// the player from the page where it is embedded. The example "index.html" has a
// number of these buttons implemented as examples, but they are not necessary.

// Key function to handle a player action passed within the code or via the embedded page.
/*
   playerAction(EVENT, ACTION, OBJECT)

    	EVENT possible values( data type String) :
			EVENT = PLAY; 
			EVENT = PAUSE; 
			EVENT = STOP; 
			EVENT = SKIP; 
    		EVENT = loadVideo; 
			EVENT = MUTE;
			EVENT = unMUTE;
			EVENT = setVisility;
			EVENT = setVolume;
			EVENT = setPlaybackControlVisible;
			EVENT = setPlaybackControlAutohide;

	   ACTION possible values ( data type String):
				ACTION =  true;
				ACTION = false;
				
	   OBJECT possible values ( data type object):
				videoObj =  null;
				videoObj = videoObj;
*/

function playerAction(param,action,obj){
	// alert(param) // Uncomment this alert to see which paramerter was passed to the function.
    calledFlashMovie = document.getElementById("playerLayer");
   	calledFlashMovie.playerAction(param,action,obj);
}

function onStateChange(state){
	//alert("onStateChange "+state);
}

function onError(val){
	(+val +"\n")
}

function playVideo(){
    playerAction("PLAY",true,null)
}

function pauseVideo(){
    playerAction("PAUSE",true,null)
}

function stopVideo(){
    playerAction("STOP",true,null)
}

function doSkip(val){
    videoObj = new Object();
    videoObj.seekOffset = val;
    playerAction("SKIP", true, videoObj)
}

function mute(){
	 playerAction("MUTE",true,null)
}

function unMute(){
	 playerAction("unMUTE",true,null)
}

function setVisility(param){
	 playerAction("setVisility", param, null)
}

function setVolume(){
	videoObj = new Object();
    videoObj.volume = 0.1;
    playerAction("setVolume", true, videoObj)
}

function setPlaybackControlVisible(param){
    playerAction("setPlaybackControlVisible",param, null)
}

function setPlaybackControlAutohide(param){
    playerAction("setPlaybackControlAutohide",param, null)
}

function setTitleBarVisible(param){
    playerAction("setTitleBarVisible",param, null)
}

//********************************************************************
// Player Information Functions
//********************************************************************
// These functions can be called from the embed page to return
// information about the player and its current state.

/* The controls playerInformation() will overload functions names possible values:
    getVideoUrl()  - returns the full URL for the video, including hostApp and the current feed
	getVideoType()  - returns either "live" or "vod"
	getVideoDuration()  - returns total length of the video
	getVolume() – returns the current volume between 1 and 0
	getState() – returns -1 if not currently playing and 1 if a video is playing
	getFullScreeen()  - returns true or false if the player is in full screen mode or not
	muteState()  - returns true or false if the player is muted
	getVideoTimeNow()  - returns the current "time" within the video

*/

function playerInformation(){
	// overload caller
	var myCaller = playerInformation.caller.name;
	calledFlashMovie = document.getElementById("playerLayer");
   	(calledFlashMovie.playerInformation(myCaller)[myCaller]);
}

function getVideoUrl(){
	playerInformation()
}
function getVideoType(){
	playerInformation()
}
function getVideoTimeNow(){
	playerInformation()
}
function getVideoDuration(){
	playerInformation()
}
function getVolume(){
	playerInformation()
}
function getState(){
	playerInformation()
}
function getFullScreeen(){
	playerInformation()
}
function muteState(){
	playerInformation()
}

