﻿package com.xaxisadlabs.components.xaxisvideoplayer {
	
	import flash.display.Sprite;
	
	import flash.display.MovieClip;
	import flash.net.NetConnection;
	import flash.events.NetStatusEvent;
	import flash.net.NetStream;
	import flash.media.Video;
	import flash.media.SoundTransform;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.utils.setInterval;
	import flash.utils.clearInterval;
	import flash.utils.setTimeout;
	import flash.geom.Rectangle;
	import flash.events.Event;
	import flash.media.SoundMixer;
		
	import com.greensock.*;
	import com.greensock.easing.*;	
	
	import com.xaxisadlabs.utils.*;
	import com.xaxisadlabs.components.xaxisvideoplayer.XaxisVideoPlayerConstants;
	import com.xaxisadlabs.components.xaxisvideoplayer.XaxisVideoPlayerDispatcher;

	
	public class XaxisVideoPlayer extends Sprite {

		private static const SIGNATURE:String = "XAXIS VIDEO PLAYER (DaVinci)";
		private static const VERSION:String = "VERSION 1.0.0";
		
		/// REPORTING CONSTANTS
		public static const AD_IMPRESSION:String = "ad-impression";
		public static const CREATIVE_CLICK_NOTIFICATION:String = "creative-click";
		public static const	VIDEO_CLICK_NOTIFICATION:String = "video-click";
		public static const	VIDEO_START_EVENT_NOTIFICATION:String = "video-start";
		public static const	VIDEO_FIRST_QUARTILE_EVENT_NOTIFICATION:String = "video-q1";
		public static const VIDEO_MID_EVENT_NOTIFICATION:String = "video-mid";
		public static const VIDEO_THIRD_QUARTILE_EVENT_NOTIFICATION:String = "video-q3";
		public static const VIDEO_END_EVENT:String = "video-end";
		public static const	VIDEO_READY:String = "video-ready";
		public static const VIDEO_REPORTING_NOTIFICATION:String = "video-reporting";
		public static const VIDEO_COMPLETE_NOTIFICATION:String = "video-complete-notification";
		public static const AD_CLICK:String = "ad-click";
		
		/// LAYOUT VARIABLES
		private var parentObj:Object;
		private var notifier:Function;
		
		// INIT VARIABLES
		private var videoPlayerNetConnection:NetConnection;
		private var videoPlayerNetStream:NetStream;
		private var videoPlayer:Video;
		private var customClient:Object;
		private var videoMetaData:Object;
		private var videoPlayerX:Number = 0;
		private var videoPlayerY:Number = 0;
		private var videoPlayerWidth:Number = 0;
		private var videoPlayerHeight:Number = 0;
		private var playerName:String = "XaxisVideoPlayer";
		//private var clickRect:MovieClip;
		
		///	ARRAYS
		private var playlistArray:Array =										new Array();
		
		// VIDEO PROPERITIES
		private var playbackIndex:Number =										0;
		private var loadIndex:Number =											0;
		
		//  INIT CONSTANTS
		private static const SMOOTHING:Boolean	= 								true;
		private static const BUFFER_TIME:Number	= 								8;
		
		/// STATE VARIABLES
		private var playerIsMuted:Boolean =										false;
		private var rewindOnEnd:Boolean	=										true;
		private var loopPlaylist:Boolean =										false;
		private var playerIsPlaying:Boolean =									false;
		private var currentVideoHasPlayed:Boolean = 							false;
		private var vidInt:Boolean =											false;
		private var bHideScrubber:Boolean =										false;
		private var bPauseVideoOnClick:Boolean = 								true;
		private var bUiIsOnTop:Boolean =										false;
		private var bVideoPlayerPlayIsRewound:Boolean =							false;
		private var nPoster:Number =											3;
		
		/// AUDIO PROPERTIES
		private var playerVolume:Number	=										.5;
		private var playerVolumeTransformation:SoundTransform;
		
		//  REPORTING VARIABLES
		private var videoStartReported:Boolean =								false;
		private var videoFirstQuartileReported:Boolean =						false;
		private var videoMidReported:Boolean =									false;
		private var videoThirdQuartileReported:Boolean = 						false;
		private var videoEndReported:Boolean =									false;
		private var videoReportingInt:uint;		
		private var videoContainer:Sprite =										new Sprite();
		//	UI 
		private var videoUI:MovieClip =										null;
		
		public function XaxisVideoPlayer() {
			
			// constructor code
			
			Console.log(XaxisVideoPlayer.SIGNATURE + ' ' + XaxisVideoPlayer.VERSION + ': Player Ready');
			
			// Create video player
			videoPlayer = new Video();
			
			
			// Parent object has reference to obj that instantiated
			parentObj = new Object();
			
			// Create playlist array
			playlistArray = new Array();
			
			
		}

		//////////////////////////////////////
		// PLAYER INITIALIZATION
		/////////////////////////////////////
		public function initPlayer(notObj:Object):void {
			Console.log(XaxisVideoPlayer.SIGNATURE + ' initPlayer');
			
			if(notObj.hasOwnProperty("oParent")) {
				// Create object to hold player parameters
				Console.log(XaxisVideoPlayer.SIGNATURE + " notObj contains reference to parent");
				
				parentObj = notObj["oParent"];
			} else {
				Console.log(XaxisVideoPlayer.SIGNATURE + " Error!  Initi object must pass reference to parent", "error");
				return;
			}
			if(notObj.hasOwnProperty("nPoster")) {
				if(notObj["nPoster"] >= 1) {
					nPoster = notObj["nPoster"];
					trace("$$$$$$$ setting poster=" + nPoster);
				}
			}
			if(notObj.hasOwnProperty("oRectangle")) {
				parentObj = notObj["oRectangle"];
					
					
					videoPlayerWidth = parentObj.width;
					videoPlayer.width = videoPlayerWidth;
					
					videoPlayerHeight = parentObj.height;
					videoPlayer.height = videoPlayerHeight;
				
				
					parentObj.addChild(videoPlayer);
					parentObj.removeChild(parentObj.vcTitle);
					parentObj.removeChild(parentObj.vcStage);
					/*clickRect = new MovieClip();
					clickRect.graphics.beginFill(0xFF0000);
					clickRect.graphics.drawRect(0,0,640,360);
					clickRect.graphics.endFill();
					clickRect.alpha = 0;*/
					
					//parentObj.addChild(clickRect);
					
					videoPlayer.addEventListener(Event.ENTER_FRAME, videoScaleCorrection);
					
				
			} else {
				Console.log(XaxisVideoPlayer.SIGNATURE + " Error!  Initi object must pass reference to video rectangle", "error");
				return;
			}
					
			
			if(notObj.hasOwnProperty("fNotifier")) {
				notifier = notObj["fNotifier"];
			} else {
				Console.log(XaxisVideoPlayer.SIGNATURE + " Error!  Initi object must pass reference to notifier function", "error");
				return;
			}
			
			
			if(notObj.hasOwnProperty("bMuted")) {
				playerIsMuted = notObj["bMuted"];
			}
			
			
			if(notObj.hasOwnProperty("bRewindOnEnd")) {
				rewindOnEnd = notObj["bRewindOnEnd"];
			}
			if(notObj.hasOwnProperty("nPlayerVolume")) {
				playerVolume = notObj["nPlayerVolume"];
				
			}
			if(notObj.hasOwnProperty("bLoopPlaylist")) {
				loopPlaylist = notObj["bLoopPlaylist"];
				
			}
			
			if(notObj.hasOwnProperty("bPauseVideoOnClick")) {
				bPauseVideoOnClick = notObj["bPauseVideoOnClick"];
			}
			
			if(notObj.hasOwnProperty("oPlayerUI")) {
				videoUI = notObj["oPlayerUI"];
			}
			
			// Build net stream object
			createNetConnection();
			
			var notObj:Object = new Object();
				notObj.notName = "initPlayer";
				notObj.notObj = playlistArray[playbackIndex][5];
			handleNotify(notObj);
			
		}
		
		////////////////////////////////////////
		//  PROGRESS FUNCTIONS
		////////////////////////////////////////
		private function videoScaleCorrection(e:Event):void {
			videoPlayer.removeEventListener(Event.ENTER_FRAME, videoScaleCorrection);
			//Track video scale with container object
				videoPlayer.width = 640;
				videoPlayer.height = 360;
				//clickRect.width = 640;
				//clickRect.height = 360;
				//videoUI.uiBackground.width = 640;
				//videoUI.uiBackground.height = 360;
			
			
				
				//Compute progress current time / duration
				//trace();	
			/*		var notObj = new Object();
				
					notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_PROGRESS_EVENT;
					notObj.videoPlayerProgress = XaxisMath.roundDecimal((videoPlayerNetStream.time/videoMetaData.duration), 2);
					notObj.videoPlayerDuration = videoMetaData.duration;
			
				XaxisVideoPlayerDispatcher.getInstance().dispatchEvent(new XaxisNotificationEvent(XaxisNotificationEvent.XAL_NOTOBJ, notObj));
			*/
		}
		
		////////////////////////////////////////
		//  VOLUME FUNCTIONS
		////////////////////////////////////////
		private function changeVolume(nVolume:Number):void {
			//Console.log(XaxisVideoPlayer.SIGNATURE + ' changeVolume-> volume=' + nVolume);
			
			if(videoPlayerNetStream) {
				playerVolumeTransformation.volume = nVolume;
				videoPlayerNetStream.soundTransform = playerVolumeTransformation;
				var notObj:Object = new Object();
				notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_AUDIO_EVENT_NOTIFICATION;
						notObj.playerName = playerName;
						notObj.notEvent = XaxisVideoPlayerConstants.VIDEO_PLAYER_VOLUME_CHANGE_NOTIFICATION;
						notObj.payload = nVolume;
						handleNotify(notObj);
				}
		
		}
		////////////////////////////////////////
		//  CLICK FUNCTIONS
		////////////////////////////////////////		
		private function handleVideoClick(e:MouseEvent):void {
		/*	navigateToURL(new URLRequest(playlistArray[playbackIndex][2]));
			if(bPauseVideoOnClick) {
				pauseVideo();
			}*/
		}		
		////////////////////////////////////////
		// NET STREAM FUNCTIONS
		////////////////////////////////////////
		private function createNetConnection():void {
			
			Console.log(XaxisVideoPlayer.SIGNATURE + ' createNetConnection');
			videoPlayerNetConnection = new NetConnection();
			videoPlayerNetConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			videoPlayerNetConnection.connect(null);
			
		}
		private function createNetStream():void {
			
			Console.log(XaxisVideoPlayer.SIGNATURE + ' createNetStream');
			videoPlayerNetStream = new NetStream(videoPlayerNetConnection);
			videoPlayerNetStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			
			customClient = new Object()
			try {
					customClient.onMetaData = onMetaData 
				} catch(e:Error) {
					Console.log(XaxisVideoPlayer.SIGNATURE + " onMetaData error: " + e, "error");
				}
			

			videoPlayerNetStream.client = customClient;
			videoPlayerNetStream.bufferTime = BUFFER_TIME;
		
			videoPlayer.attachNetStream(videoPlayerNetStream);
			videoPlayer.smoothing = SMOOTHING;
			
			playerVolumeTransformation = new SoundTransform();				
				
			var notObj = new Object();
				notObj.notName = "netStreamReady";
				notObj.notObj = playlistArray[playbackIndex][5];
				handleNotify(notObj);
				
		}
		private function onMetaData(info:Object):void {
			Console.log(XaxisVideoPlayer.SIGNATURE + " metaDataHandler");

			if(!playerIsMuted) {
				changeVolume(playerVolume);
			} else {
				muteVideo();
			}
			if(!bUiIsOnTop && videoUI !=null) {
				parentObj.swapChildren(videoPlayer, videoUI);
				bUiIsOnTop = true;
			}
			videoMetaData = info;
			playerIsPlaying = true;
			
			var notObj = new Object();
				notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_METADATA;
				notObj.muteState = getPlayerIsMuted();
				notObj.duration = videoMetaData.duration;
				
				handleNotify(notObj);
			
			Console.log(XaxisVideoPlayer.SIGNATURE + " videoMetaData -> duration=" + videoMetaData.duration);

		}
		private function netStatusHandler(e:NetStatusEvent):void {
			
			Console.log(XaxisVideoPlayer.SIGNATURE + " netStatusHandler -> status = " + e.info.code);
			var notObj = new Object();
			switch (e.info.code) {
				case "NetConnection.Connect.Success":
						createNetStream();
					break;
				case "NetStream.Play.Start":
						playerIsPlaying = true;

						notObj.notName = XaxisVideoPlayer.VIDEO_REPORTING_NOTIFICATION;
						notObj.playerName = playerName;
						notObj.notEvent = XaxisVideoPlayerConstants.VIDEO_NET_STREAM_READY;
						handleNotify(notObj);
						
						notObj.notEvent = "init-"+playlistArray[playbackIndex][5];
						handleNotify(notObj);
				
						notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_PLAYBACK_EVENT;
						notObj.playerName = playerName;
						notObj.notEvent = XaxisVideoPlayerConstants.VIDEO_PLAYER_PLAY;
						handleNotify(notObj);
						
						this.addEventListener(Event.ENTER_FRAME, handleVideoProgress);
				
						if(!vidInt) {
							videoReportingInt = setInterval(handleVideoReporting, 1000);
						} else {
							vidInt = true;
						}
						
						if(playlistArray[playbackIndex][3] == true) {
							
							videoStartReported =								false;
							videoFirstQuartileReported =						false;
							videoMidReported =									false;
							videoThirdQuartileReported = 						false;
							videoEndReported =									false;
							
							handleVideoReporting();
							
						}
					break;
				case "NetStream.Play.StreamNotFound":
					
				break;
				case "NetStream.Pause.Notify":
						playerIsPlaying = false;
						notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_PLAYBACK_EVENT;
						notObj.playerName = playerName;
						notObj.notEvent = XaxisVideoPlayerConstants.VIDEO_PLAYER_PAUSE;
						handleNotify(notObj);
					break;
				case "NetStream.Unpause.Notify":
						playerIsPlaying = true;
						notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_PLAYBACK_EVENT;
						notObj.playerName = playerName;
						notObj.notEvent = XaxisVideoPlayerConstants.VIDEO_PLAYER_PLAY;
						handleNotify(notObj);
					break;
				case "NetStream.Play.Stop":
					
					Console.log(XaxisVideoPlayer.SIGNATURE + " FOURTH QUARTILE", "log", true);
					videoEndReported = true;
					
					this.removeEventListener(Event.ENTER_FRAME, handleVideoProgress);
	
				
				/*	if(playlistArray[playbackIndex][2] != "") {
						hideClickRectangle();
					} */
					notObj.notName = XaxisVideoPlayer.VIDEO_REPORTING_NOTIFICATION;		
					notObj.playerName = playerName;
					notObj.notUrl = playlistArray[playbackIndex][0];
					notObj.notEvent = XaxisVideoPlayerConstants.VIDEO_END_EVENT;
					
					//Console.log("///////// QUARTILE REPORTING END /////////");
					Console.dumpLog();
					
					handleNotify(notObj);
				
					if(rewindOnEnd) {
						bVideoPlayerPlayIsRewound = true;
						videoPlayerNetStream.seek(nPoster);
						pauseVideo();
						
				
						notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_PROGRESS_EVENT;
						notObj.videoPlayerProgress = 0;
						notObj.videoPlayerDuration = videoMetaData.duration;
			
						handleNotify(notObj);
						
					}	
					
					if(loopPlaylist) {
						playlistNext();
					}
				break;
				
				
			}
		}
		private function handleVideoProgress(e:Event):void {
			var notObj:Object = new Object();
				notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_PROGRESS_EVENT;
				notObj.videoPlayerProgress = XaxisMath.roundDecimal((videoPlayerNetStream.time/videoMetaData.duration), 2);
				notObj.videoPlayerDuration = videoMetaData.duration;
			
				handleNotify(notObj);
		}
		/////////////////////////////////////////
		// PLAYBACK FUNCTIONS
		/////////////////////////////////////////
		public function loadVideo(videoObj:Object):void {
			
			Console.log(XaxisVideoPlayer.SIGNATURE + " loadVideo " + videoObj.sURL);
			try { videoObj.sURL; } catch (e:Error) { Console.log(XaxisVideoPlayer.SIGNATURE + " ERROR: YOU MUST DEFINTE A URL IN THE LOAD VIDEO OBJECT videoObj.sURL", "error"); return};
			try { videoObj.bAutoPlay; } catch (e:Error) { Console.log(XaxisVideoPlayer.SIGNATURE + " ERROR: YOU MUST SPECIFY IF THE VIDEO IS AUTO PLAY VIA BOOLEAN videoObj.bAutoPlay", "error"); return};
			try { videoObj.sClickURL; } catch (e:Error) { Console.log(XaxisVideoPlayer.SIGNATURE + " ERROR: YOU MUST DEFINTE A CLICK URL IN THE LOAD VIDEO OBJECT videoObj.sClick URL.  THE VALUE CAN BE ''", "error"); return};
			try { videoObj.bReportQuartiles; } catch (e:Error) { Console.log(XaxisVideoPlayer.SIGNATURE + " ERROR: YOU MUST SPECIFY IF THE VIDEO SHOULD REPORT QUARTILE EVENTS", "error"); return};
			try { videoObj.sPlayerName; } catch(e:Error) {Console.log(XaxisVideoPlayer.SIGNATURE + " ERROR: YOU MUST NAME THE VIDEO PLAYER", "error"); return};

			
			Console.log(XaxisVideoPlayer.SIGNATURE + " loadVideo into playlist array");
			playlistArray.push([videoObj.sURL, videoObj.bAutoPlay, videoObj.sClickURL, videoObj.bReportQuartiles, bHideScrubber, videoObj.sPlayerName]);
			Console.log(XaxisVideoPlayer.SIGNATURE + " playlistArray updated.  sURL=" + playlistArray[loadIndex][0]);
			Console.log(XaxisVideoPlayer.SIGNATURE + " playlistArray updated.  sPlayerName=" + playlistArray[loadIndex][5]);
			loadIndex ++;
			
			
		}
		///////////////////////////////////////////
		// PLAYER API
		//////////////////////////////////////////
		public function playVideo(playlistIndex:Number=0):void {
			
			Console.log(XaxisVideoPlayer.SIGNATURE + " playVideo playlistIndex=" + playlistIndex + " clickURL=" + playlistArray[playlistIndex][2]);

			videoPlayerNetStream.play(playlistArray[playlistIndex][0]);
		
			playerName = playlistArray[playlistIndex][5];
			playbackIndex = playlistIndex;	
			playerIsPlaying = true;	
			
			/*if(playlistArray[playbackIndex][2] != "") {
				//showClickRectangle();
			} */
			
			Console.log(XaxisVideoPlayer.SIGNATURE + " playVideo playState=" + playerIsPlaying);
			
		}
		public function pauseVideo():void {
			Console.log(XaxisVideoPlayer.SIGNATURE + " pauseVideo");			
			
			videoPlayerNetStream.pause();
			playerIsPlaying = false;

			
			Console.log(XaxisVideoPlayer.SIGNATURE + " play state=" + playerIsPlaying);
		}
		public function resumeVideo():void {
			Console.log(XaxisVideoPlayer.SIGNATURE + " resumeVideo");
			
			/*If the video has been rewound, it needs to be replayed from the beginning*/
			if(bVideoPlayerPlayIsRewound) {
				playVideo(playbackIndex);
				bVideoPlayerPlayIsRewound = false;
			} else { 
				videoPlayerNetStream.resume();
				playerIsPlaying = true;
			}
			
			Console.log(XaxisVideoPlayer.SIGNATURE + " resumeVideo playState=" + playerIsPlaying);
		}
		public function muteVideo():void {
			playerIsMuted=true;
			changeVolume(0);
		}
		public function unMuteVideo():void {
			playerIsMuted=false;
			changeVolume(playerVolume);
		}
		public function updateVolume(nPlayerVolume:Number):void {
			playerVolume = nPlayerVolume;
			changeVolume(playerVolume);
			playerIsMuted = false;
		}
		public function playlistNext(e:MouseEvent=null):void {
			Console.log(XaxisVideoPlayer.SIGNATURE + " playlistNext"); 
			/*
				If the play event is the result of a click as opposed to an auto playlist transition, unmute the audio. 
			*/
			if(e!=null) { unMuteVideo(); };
			var videoToPlay:Number = playbackIndex;
				videoToPlay ++;
			if(videoToPlay > playlistArray.length-1) {
				videoToPlay = 0;
			}
			
			playVideo(videoToPlay);
		}
		public function playlistPrevious(e:MouseEvent=null):void {
			Console.log(XaxisVideoPlayer.SIGNATURE + " playlistPrevious"); 
			/*
				If the play event is the result of a click as opposed to an auto playlist transition, unmute the audio. 
			*/
			if(e!=null) { unMuteVideo(); };
			var videoToPlay:Number = playbackIndex;
				videoToPlay --;
			if(videoToPlay < 0) {
				videoToPlay = playlistArray.length-1;
			}

			playVideo(videoToPlay);
		}

		public function resizeAndRepositionPlayer(w:Number, h:Number, xPos:Number, yPos:Number, dir:String="to", dur:Number=1):void {
				//Console.log(XaxisVideoPlayer.SIGNATURE + " resizeAndResposition: x=" + xPos + " y=" + yPos + " w=" + w + " h=" + h + " dur=" + dur);
				var resizeScaleFactor = w/videoPlayer.width;
				if(dir == "to") {
					TweenLite.to(parentObj, dur, {scaleX:resizeScaleFactor, scaleY:resizeScaleFactor, x:xPos, y:yPos, easing:Expo.easeOut});
					
				} else {
					TweenLite.from(parentObj, dur, {scaleX:resizeScaleFactor, scaleY:resizeScaleFactor, x:xPos, y:yPos, easing:Expo.easeOut});
					
				}
			
		}
		
		public function getPlayerIsPlaying():Boolean {
			//trace("xaxis player +++++ playerIsPlaying=" + playerIsPlaying);
			return playerIsPlaying;
		}
		public function getPlayerIsMuted():Boolean {
			return playerIsMuted;
		}
		public function notifyClick():void {
			var notObj = new Object();
				notObj.notName = XaxisVideoPlayerConstants.VIDEO_PLAYER_CLICK_EVENT_NOTIFICATION;
				notObj.playerName = playerName;
				notObj.clickURL = playlistArray[playbackIndex][2];
				handleNotify(notObj);
		}
	/*	public function hideClickRectangle():void {
			clickRect.removeEventListener(MouseEvent.CLICK, handleVideoClick);
			clickRect.buttonMode = false;
		}
		public function showClickRectangle():void {
			clickRect.addEventListener(MouseEvent.CLICK, handleVideoClick);
			clickRect.buttonMode = true;
		} */
		public function getVideoURL():String {
			return playlistArray[playbackIndex][2];
		}
		public function seekVideo(timecode:Number = 1) {
			try {
				videoPlayerNetStream.seek(timecode);
			} catch(e:Error) {
				Console.log(XaxisVideoPlayer.SIGNATURE, " seekVideo Error=" + e);
			}
		}
		////////////////////////////////////////
		//	CLEAN-UP
		////////////////////////////////////////
		
		////////////////////////////////////////
		//	REPORTING
		////////////////////////////////////////
		private function handleVideoReporting():void {
			
			//Console.log(XaxisVideoPlayer.SIGNATURE + " handleVideoReporting->");
			
			try { 
				var currentTime:Number;
				var duration:Number;
				var time:Number;
			} catch(e:Error) {
				Console.log(XaxisVideoPlayer.SIGNATURE + " handleVideoReportingError -> " + e, "error");
			}
			
			var notObj = new Object();
				notObj.notEvent = XaxisVideoPlayer.VIDEO_REPORTING_NOTIFICATION;		
				notObj.playerName = playerName;
				notObj.notUrl = playlistArray[playbackIndex][0];
			
			if(!videoStartReported) {
				//Console.log("///////// QUARTILE REPORTING START /////////");
				Console.log(XaxisVideoPlayer.SIGNATURE + " VIDEO START: " + String(currentTime), "log", true);
				videoStartReported = true;
				notObj.notEvent = XaxisVideoPlayer.VIDEO_START_EVENT_NOTIFICATION;
				
				
			} else if(!videoFirstQuartileReported) {
				
				currentTime = videoPlayerNetStream.time as Number;
				duration = videoMetaData.duration as Number;
				if(currentTime >= (duration / 4)) {
					
					Console.log(XaxisVideoPlayer.SIGNATURE + " FIRST QUARTILE: " + String(currentTime), "log", true);
					videoFirstQuartileReported = true;
					notObj.notEvent = XaxisVideoPlayer.VIDEO_FIRST_QUARTILE_EVENT_NOTIFICATION;
	
				}
				
			}  else if(!videoMidReported) {
				
				currentTime = videoPlayerNetStream.time as Number;
				duration = videoMetaData.duration as Number;
				if(currentTime >= (duration / 2)) {
					
					Console.log(XaxisVideoPlayer.SIGNATURE + " MID QUARTILE: " + String(currentTime), "log", true);
					videoMidReported = true;
					notObj.notEvent = XaxisVideoPlayer.VIDEO_MID_EVENT_NOTIFICATION;
					
				}
			} else if(!videoThirdQuartileReported) {
				
				currentTime = videoPlayerNetStream.time as Number;
				duration = videoMetaData.duration as Number;
				if(currentTime >= ((duration / 2) + (duration / 4))) {
					
					Console.log(XaxisVideoPlayer.SIGNATURE + " THIRD QUARTILE: " + String(currentTime), "log", true);
					videoThirdQuartileReported = true;
					notObj.notEvent = XaxisVideoPlayer.VIDEO_THIRD_QUARTILE_EVENT_NOTIFICATION;

				}
			} 
			
		
			handleNotify(notObj);
			notObj = null;
			
		}
		////////////////////////////////////////
		// NOTIFICATIONS
		///////////////////////////////////////
		private function handleNotify(notObj):void {
			
			var prntObj:Object = new Object();
			XaxisVideoPlayerDispatcher.getInstance().dispatchEvent(new XaxisNotificationEvent(XaxisNotificationEvent.XAL_NOTOBJ, notObj));
			
			if(parentObj != null) {
				//if(notObj.notEvent != undefined) { trace("notifier"+ notObj.notEvent); };
				notifier(notObj);
			} else {
				Console.log(XaxisVideoPlayer.SIGNATURE + " WARNING PARENT OBJECT IS UNDEFINED OR NULL", "warn");
			}
			
		}
		

	}
	
}
