/**
 * @namespace VFA_PLAYER
 *
 * The VFA_PLAYER namespace contains functions to interact with the VFA Flash video player.
 */
var VFA_PLAYER = {

	// DOM element id for the Flash player
	ID: "Player", 

	/**
	 * Internal function for getting the DOM element id.	
	 */
	GetPlayer : function() {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[this.ID];
         	} else {
			return document[this.ID];
	        }
    	}, 
 
	/**
	 * Play a video.
	 * @param video - javascript object with video info; 3 properties are required: 'id' - video content id, 'url' - video url, 'image' - image url
	 */
	Play : function(video) {
		 
		this.GetPlayer().playVideo(video);
	},
	
	/**
	 * Pauses or resumes playback depending on current state.
	 */
	TogglePause : function() {
		this.GetPlayer().togglePause();
	},
	
	/**
	 * Stop the video. Completely closes the stream so playback cannot be resumed.
	 */
	Stop : function() {
		this.GetPlayer().stopVideo();
	},
	
	/**
	 * Display the ending movieclip (includes video image and "pick an ad" prompt).
	 */
	DisplayEnding : function() {
		this.GetPlayer().displayEnding();
	}, 
	
	/** 
	 * Display the error message (stops playback).
	 * The player will display the error message by default, but you can trigger it here if needed
	 */
	DisplayError : function() {
		this.GetPlayer().displayError();
	},
	
	/**
	 * On player loaded callback. Fires after the Flash is loaded and ready to go.
	 */
	OnPlayerLoaded : function() {
		
		// this is where you want to call play for your first video
		
		/****** EXAMPLE ******/
		// calling the example playlist start function
		 
		 	//VFA.playIntro();
			VFA.start();
		 
	},
	
	/** 
	 * On video start callback.
	 */
	OnVideoStart : function(event) {
		// add omniture start tracking here
		// event.type - string containing the event code
		// event.target - the exact video object that was passed to flash (event.target.id, event.target.url, etc)
		
	 	// count the video view
	 	VFA.updateVideoView($(".player").data("videoId"));
		
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	}, 
	
	/**
	 * On video midpoint callback.
	 */
	OnVideoMid : function(event) {
		// add omniture mid tracking here
		// event.type - string containing the event code
		// event.target - the exact video object that was passed to flash (event.target.id, event.target.url, etc)
				
		
		
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	}, 
	
	/**
	 * On video end callback.
	 */
	OnVideoEnd : function(event) {
		// add omniture end tracking here
		// event.type - string containing the event code
		// event.target - the exact video object that was passed to flash (event.target.id, event.target.url, etc)
				
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
		
		// if there's more items in the playlist, tell flash to play the next one; otherwise tell flash to display the ending image	
		
		/****** EXAMPLE ******/
		//VFA_PLAYER.Play(VFA.PlayList[VFA.currentIndex]);
		 
		VFA.currentIndex++;
		if (VFA.currentIndex < VFA.PlayList.length && VFA.playAll == "true" && VFA.playDeepLinkVideo==false) {
			var videoId = VFA.PlayList[VFA.currentIndex].id;
			//update data
			//var videoInfo = VFA.currentPlaylistMap[videoId];
			ThumbListArea.updatePlayer(VFA.currentPlaylistMap[videoId]); 
			VFA_PLAYER.Play(VFA.PlayList[VFA.currentIndex]);
		} else {
			this.DisplayEnding();
		}
		 
	},
	
	/**
	 * On video error callback.
	 */
	OnVideoError : function(event) {
		// add error handling here if wanted
		// event.type - string containing the event code
		// event.message - message describing the type of error
		// event.target - the exact video object that was passed to flash (event.target.id, event.target.url, etc)
		
		//alert(event.type + ": " + event.target.id + " - " + event.message);
		//log(event.type + ": " + event.target.id + " - " + event.message);
	},
	
	/**
	 * On enter fullscreen callback.
	 */
	OnEnterFullScreen : function(event) {
		// add omniture tracking here
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	}, 
	
	/**
	 * On exit fullscreen callback.
	 */
	OnExitFullScreen : function(event) {
		// add omniture tracking here
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	}, 
	
	/** 
	 * On video pause callback.
	 */
	OnVideoPause : function(event) {
		// add omniture tracking here
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	}, 
	
	/**
	 * On video play callback.
	 */
	OnVideoPlay : function(event) {
		// add omniture tracking here
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	}, 
	
	/**
	 * On video mute callback.
	 */
	OnVideoMute : function(event) {
		// add omniture tracking here
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	}, 
	
	/** 
	 * On video unmute callback.
	 */
	OnVideoUnmute : function(event) {
		// add omniture tracking here
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	},
	
	/**
	 * On audio adjust callback.
	 */
	OnAudioAdjust : function(event) {
		// add omniture tracking here
		//log(event.type + ": "  + event.target.url + "(" + event.target.id + ")");
	}
}	