//
// Copyright (c) 2005 Advanced Computer Graphics, Inc. All rights reserved.
//
// The information in this file is protected by copyright law and international
// treaty provisions. Unauthorized reproduction, distribution or reverse
// engineering of this file, or any portion of it, is strictly prohibited.
//
// For information on licensing this software, please contact us by visiting
// our website at <www.acgmultimedia.com>.
//


//
// This class is used to compensate for the "IE, Popup, Flash, Windows Media Player 'dynamic loading'" bug.
// These technologies in combination seem to cause the parent "launcher" page
// to lockup after the popup window is closed (usually after 2 or more launches).
// So, instead of just simply using a Media Player object, we
// create an IFRAME and load a new document into it. The new document is responsible
// for creating the actual video object. When a new video is desired, the
// IFRAME is re-loaded, re-creating the Media Player object.
//
//
// Assumes:
// video.html is available
// default mp parameters (currently no way to pass in default params)
// video.html creates a video object named "pVideo"
// video.html does not currently support custom properties, like position and size to be set
// Event callbacks are available: Buffering, playStateChange
//
function ACG_MediaMPHack( pParent, sName, sFile, iX, iY, iWidth, iHeight, iZ )
{
	this.m_sFrameName = sName + "frame";
	parent._sCurrentFile = sFile;

	//zde var sToInsert = "<iframe id='" + this.m_sFrameName + "' src='video.html?file=" + sFile + "' frameborder='0' style='position:absolute; left:" + iX + "px; top:" + iY + "px; width:" + iWidth + "px; height:" + iHeight + "px; z-index:" + iZ + " background-color:white; color:white;'></iframe>";
	var sToInsert = "<iframe id='" + this.m_sFrameName + "' src='video.html' frameborder='0' style='position:absolute; left:" + iX + "px; top:" + iY + "px; width:" + iWidth + "px; height:" + iHeight + "px; z-index:" + iZ + " background-color:white; color:white;'></iframe>";	
	document.body.insertAdjacentHTML( "BeforeEnd", sToInsert );
}

ACG_MediaMPHack.prototype.SetVisible = function( bVisible )
{
	if ( typeof( document.frames[ this.m_sFrameName ] ) == undefined )
		return;

	var pVideoFrame = document.frames[ this.m_sFrameName ];

	if ( ( typeof( pVideoFrame.pVideo ) == undefined ) ||
		 ( pVideoFrame.pVideo == null ) )
		return;

	pVideoFrame.pVideo.SetVisible( bVisible );
//	document.frames[ this.m_sFrameName ].pVideo.SetVisible( bVisible );
}

ACG_MediaMPHack.prototype.Load = function( sFile )
{
	var pVideoFrame = document.getElementById( this.m_sFrameName );

	if ( ( typeof( pVideoFrame ) == undefined ) ||
		 ( pVideoFrame == null ) )
		return;

	parent._sCurrentFile = sFile;

	pVideoFrame.src = "video.html";
//	document.getElementById( this.m_sFrameName ).src = "video.html?file=" + sFile;
}

ACG_MediaMPHack.prototype.Play = function()
{
	if ( typeof( document.frames[ this.m_sFrameName ] ) == undefined )
		return;

	var pVideoFrame = document.frames[ this.m_sFrameName ];

	if ( ( typeof( pVideoFrame.pVideo ) == undefined ) ||
		 ( pVideoFrame.pVideo == null ) )
		return;

	pVideoFrame.pVideo.Play();
//	document.frames[ this.m_sFrameName ].pVideo.Play();
}

ACG_MediaMPHack.prototype.Pause = function()
{
	if ( typeof( document.frames[ this.m_sFrameName ] ) == undefined )
		return;

	var pVideoFrame = document.frames[ this.m_sFrameName ];

	if ( ( typeof( pVideoFrame.pVideo ) == undefined ) ||
		 ( pVideoFrame.pVideo == null ) )
		return;

	pVideoFrame.pVideo.Pause();
//	document.frames[ this.m_sFrameName ].pVideo.Pause();
}

ACG_MediaMPHack.prototype.GetState = function()
{
	if ( typeof( document.frames[ this.m_sFrameName ] ) == undefined )
		return;

	var pVideoFrame = document.frames[ this.m_sFrameName ];

	if ( ( typeof( pVideoFrame.pVideo ) == undefined ) ||
		 ( pVideoFrame.pVideo == null ) )
		return;

	return pVideoFrame.pVideo.GetState();
//	return document.frames[ this.m_sFrameName ].pVideo.GetState();
}

ACG_MediaMPHack.prototype.GetMediaPosition = function()
{
	if ( typeof( document.frames[ this.m_sFrameName ] ) == undefined )
		return;

	var pVideoFrame = document.frames[ this.m_sFrameName ];

	if ( ( typeof( pVideoFrame.pVideo ) == undefined ) ||
		 ( pVideoFrame.pVideo == null ) )
		return;

	return pVideoFrame.pVideo.GetMediaPosition();
//	return document.frames[ this.m_sFrameName ].pVideo.GetMediaPosition();
}

ACG_MediaMPHack.prototype.GetLength = function()
{
	if ( typeof( document.frames[ this.m_sFrameName ] ) == undefined )
		return;

	var pVideoFrame = document.frames[ this.m_sFrameName ];

	if ( ( typeof( pVideoFrame.pVideo ) == undefined ) ||
		 ( pVideoFrame.pVideo == null ) )
		return;

	return pVideoFrame.pVideo.GetLength();
//	return document.frames[ this.m_sFrameName ].pVideo.GetLength();
}

ACG_MediaMPHack.prototype.SetMute = function( bMute )
{
	if ( typeof( document.frames[ this.m_sFrameName ] ) == undefined )
		return;

	var pVideoFrame = document.frames[ this.m_sFrameName ];

	if ( ( typeof( pVideoFrame.pVideo ) == undefined ) ||
		 ( pVideoFrame.pVideo == null ) )
		return;

	return pVideoFrame.pVideo.SetMute( bMute );
//	return document.frames[ this.m_sFrameName ].pVideo.SetMute( bMute );
}

ACG_MediaMPHack.prototype.GetPlayerObject = function()
{
	if ( typeof( document.frames[ this.m_sFrameName ] ) == undefined )
		return null;

	var pVideoFrame = document.frames[ this.m_sFrameName ];

	if ( ( typeof( pVideoFrame.pVideo ) == undefined ) ||
		 ( pVideoFrame.pVideo == null ) )
		return null;

	return pVideoFrame.pVideo.GetPlayerObject();
//	return document.frames[ this.m_sFrameName ].pVideo.GetPlayerObject();
}
