// Writes query string for on demand video clips
function playVideoClip( intClipID, intShowCC, strTargetAdsTag )
{
	var objPopup;

	objPopup = selectVideoPlayer( intClipID, "", intShowCC, escape(strTargetAdsTag), 0 );

	if ( top.FRAMEMEDIA != null )
		setVideoParams(intClipID, "", intShowCC, escape(strTargetAdsTag), objPopup);
}

// Writes query string for live streaming video
function playLiveVideo( strLiveURI, strTargetAdsTag )
{
	var objPopup;

	objPopup = selectVideoPlayer( 0, escape(strLiveURI), 0, escape(strTargetAdsTag), 0 );

	if ( top.FRAMEMEDIA != null )
		setVideoParams(0, strLiveURI, 0, escape(strTargetAdsTag), objPopup);
}

// Launches appropriate player for video
function selectVideoPlayer( strClipID, strURI, intShowCC, strTargetAdsTag, intCurrentPosition )
{
	var strBrowser;
	var intVersion;
	var strUserAgent;
	var bIsPC = true;
	var objWinPopup = null;

	//Determine current browser details
	strBrowser = navigator.appName;
	strUserAgent = navigator.userAgent;
	intVersion = parseInt( navigator.appVersion );
	bIsPC = strUserAgent.indexOf( "Win" ) >= 0;

	if ( ((strBrowser == "Microsoft Internet Explorer") && (intVersion >= 4)) || 
		 ((strBrowser == "Netscape") && (intVersion >= 4 ) && (intVersion < 5)) )
	{
		if ( bIsPC == true ) // PC
		{
			if ( ( ( strBrowser == "Netscape" ) && ( isPluginInstalled( ) ) ) ||
				 ( ( strBrowser == "Microsoft Internet Explorer" ) && ( isPlayerInstalled( ) ) ) )
				objWinPopup = playVideoPopupOrEmbedded( strClipID, strURI, intShowCC, strTargetAdsTag, intCurrentPosition );
			else if ( ( strBrowser == "Netscape" ) && ( !(isPluginInstalled( )) ) ||
					  ( strBrowser == "Microsoft Internet Explorer" ) && ( !(isPlayerInstalled( )) ) )
				displayHelp( );
		}
		else // Mac
		{
			if ( (( strBrowser == "Netscape" ) && ( isPluginInstalled( ) )) || ( strBrowser != "Netscape" ) )
				location.href = "/global/video/WorldNowASX.asp?"
					+ "ClipID=" + strClipID
					+ "&LiveURI=" + strURI
					+ "&ShowCC=" + intShowCC
					+ "&TargetAdsTag=" + strTargetAdsTag
					+ "&CurrentPosition=" + intCurrentPosition;
			else if ( ( strBrowser == "Netscape" ) && ( !(isPluginInstalled( )) ) )
				displayHelp();
		}
	}
	else
	{
		//For all other browsers/versions/platforms launch native player directly
		location.href = "/global/video/WorldNowASX.asp?"
			+ "ClipID=" + strClipID
			+ "&LiveURI=" + strURI
			+ "&ShowCC=" + intShowCC
			+ "&TargetAdsTag=" + strTargetAdsTag
			+ "&CurrentPosition=" + intCurrentPosition;
	}

	return objWinPopup;
}

function playVideoPopupOrEmbedded( strClipID, strURI, intShowCC, strTargetAdsTag, intCurrentPosition )
{
	var intWidth;
	var intHeight;
	var winPopup;
	var objWinPopup = null;

	// Determine dimensions for player
	if( intShowCC == 0 ) intHeight = 334;
	else intHeight = 426;
	intWidth = 582;

 	if ( top.FRAMEMEDIA != null )
 	{
 		if ( top.FRAMEMEDIA.m_strWhichPlayer == "popupPlayer" )
 		{
			winPopup = window.open( "/global/video/popup/pop_index.asp?"
				+ "ClipID=" + strClipID
				+ "&LiveURI=" + strURI
				+ "&ShowCC=" + intShowCC
				+ "&TargetAdsTag=" + strTargetAdsTag
				+ "&CurrentPosition=" + intCurrentPosition,
				+ "popupPlayer", "width=" + intWidth
				+ ",height=" + intHeight + ",resizable=no" );
			winPopup.focus();
			objWinPopup = winPopup;
 		}
 		else
 		{
			top.FRAMEMEDIA.playNewVideo( strClipID, strURI, intShowCC, strTargetAdsTag, intCurrentPosition );
 		}
 	}
 	else
 	{
		winPopup = window.open( "/global/video/popup/pop_index.asp?"
			+ "ClipID=" + strClipID
			+ "&LiveURI=" + strURI
			+ "&ShowCC=" + intShowCC
			+ "&TargetAdsTag=" + strTargetAdsTag
			+ "&CurrentPosition=" + intCurrentPosition,
			+ "popupPlayer", "width=" + intWidth + ",height=" + intHeight + ",resizable=no" );
		winPopup.focus();
	}

	return objWinPopup;
}

function isPlayerInstalled( )
{
	if ( top.FRAMEBRANDING != null )
		return ( top.FRAMEBRANDING.bHasMPlayer );
	else
		return true;
}

function isPluginInstalled( )
{
	if ( top.FRAMEBRANDING != null )
		return ( top.FRAMEBRANDING.bHasPlugin );
	else
		return true;
}

function setVideoParams(intClipID, strLiveURI, intShowCC, strTargetAdsTag, objPopupVideo)
{
	top.FRAMEMEDIA.m_strClipID = intClipID;
	top.FRAMEMEDIA.m_strLiveURI = strLiveURI;
	top.FRAMEMEDIA.m_strShowCC = intShowCC;
	top.FRAMEMEDIA.m_strTargetAdsTag = strTargetAdsTag;
	top.FRAMEMEDIA.m_objWinPopup = objPopupVideo;
}
