﻿/*
NETJOHNHENRY.VideoPlayer

The VideoPlayer namespace defines generic functions that are called from within the flash video player.
Responsibility of the frontend is assigning with a function all the Custom-starting variables.
    
Usage: 
    
NETJOHNHENRY.VideoPlayer.EventPlayStarted  = function(video_name) {ITVM.Tracking.track(ITVM.Tracking.contexts.VIDEO, ITVM.Tracking.actions.PLAY, video_name)};  
*/
//if (NETJOHNHENRY) {
NETJOHNHENRY = window.NETJOHNHENRY || {};

NETJOHNHENRY.VideoPlayer = (function()
{
	//Delegate called from EventPlayStarted event which is raised when the Video starts playing.
	var CustomEventPlayStarted;

	//Event called from within flash when video start playing.
	function EventPlayStarted(video_title)
	{
		if (this.CustomEventPlayStarted)
		{
			this.CustomEventPlayStarted(video_title);
		}
	}

	//Reset the size of object/embed tag to fit the video player
	function ResetSize(object_id, videoWidth, videoHeight)
	{
		if (object_id)
		{
			var container;
			var flashvars = $("#" + object_id).attr('flashvars');
			var values = flashvars.split('&');
			var currentPath = '';
			for (var i2 = 0; i2 < values.length; i2++)
			{
				var key = values[i2].split('=')[0];
				if (key == 'in_markup_id')
				{
					var currentId = values[i2].split('=')[1];
					currentId = unescape(currentId);
					var container = $("#" + object_id);
					if (currentId == object_id)
					{
						var currentElement = document.getElementById(currentId);
						var height = currentElement.offsetHeight;
						var width = currentElement.offsetWidth;
						videoHeight = parseInt(videoHeight, 10);
						videoHeight = videoHeight + 40;
						currentElement.style.height = videoHeight + 'px';
						currentElement.style.width = videoWidth + 'px';
						break;
					}
				}
			}
		}
	}

	return {
		CustomEventPlayStarted: CustomEventPlayStarted,
		EventPlayStarted: EventPlayStarted,
		ResetSize: ResetSize
	}
})();
//}