var g_playState = 0; //0=stop,1=pause,2=playing
var g_movieTimeScale = 0;
var g_MP_FileName = "";
var g_pausedAt = -1;
var g_lastPause  = null;

function MP_FileName(streamName)//!!check if movie name is correct
{
	oMP.SetResetPropertiesOnReload(false);
	g_MP_FileName = streamName;
	oMP.SetURL(streamName);
	setTimeout("TPause()",0);	
}

function MP_ContextMenu(x)
{
	oMP.SetKioskMode(x);
}

function MP_Mute(bMute)
{
	if (""+bMute=="true")
		oMP.SetMute(true);
	else
		oMP.SetMute(false);
	
}

function MP_Volume(x)
{
	oMP.SetVolume(x);
}

function MP_SelectionEnd()
{
	totalTime=oMP.GetEndTime()-oMP.GetStartTime();
	return totalTime;
}


function MP_CanSeek()//##investigate hints
{
	return true;
}

function MP_SetCurrentPos(x) //x is seconds
{
	oMP.SetTime(Math.floor(x*oMP.GetTimeScale()));
}

function TGetErrorCode() //##check if returns the errorCode as string or number
{
	status = oMP.GetPluginStatus();
	errorCode = "0";
	if (status.substr(0,7) == "Error: ")
	{
		errorCode = status.substring(7,status.length()-1);
	}
	return errorCode;
}

function TGetErrorDescription() //##
{
	return "";
}

function TCanPlay()
{
	if (oMP.GetPluginStatus() == "Playable" ||
	    oMP.GetPluginStatus() == "Complete")
	    return true;
	return false;

}

function TGetStatus() 
{
	if (g_loadok == 0)
		return 5;

	if (TGetErrorCode() != 0)
	{
		g_playok  = 0;
		return 4;
	}
	
	stat = oMP.GetPluginStatus();
	if (stat == "Waiting")
	{
		g_playok  = 0;
		return 5;
	}
	
	//else, the stat is Loading,Playable or Complete
	if (g_playok == 0)
	{
		g_playok  = 1;
		TGetPosition(); 
	}
	return g_playState; 

}


function MP_CurrentPos() 
{
	curTime = Math.floor((oMP.GetTime()/oMP.GetTimeScale())*1000);
	return curTime;
}


function TGetPosition()
{
	if (g_playok != 1 || g_exiting == 1)
		return;

	if (g_playState == 2) //playing
	{
		CurrentTime = MP_CurrentPos();
		if ( (TegStop != -1) && (CurrentTime >= TegStop) )
			TStop();

	}	
	setTimeout("TGetPosition()", 1000);
}

function TGetMPFileName() //!!
{
	return oMP.GetURL();
}

function TBuffering() 
{
	isBufferring = "1";
	stat = oMP.GetPluginStatus();
	if (stat == "Playable" ||
	    stat == "Complete" ||
	    TGetErrorCode() != 0)
	    isBufferring = "0";
	return isBufferring;
}

function MP_HasErr()
{
	return (TGetErrorCode() != 0);
}

function HideLink(bShowSR)
{
	if (window.nl1)
		nl1.visibility="hidden";

	document.wul.visibility = "visible";
}
 
function ShowLink (src)
{
	if (!window.nl2)
	{
		nl2 = new Layer(640);
		nl2.clip.bottom = 480;
		nl2.visibility="visible";
	}
 
	HideLink();

	nl1 = new Layer(640);
	nl1.clip.bottom = 480;
	nl1.pageX=(mpW+aM);
	nl1.pageY=0;
	nl1.src=src;
	nl1.visibility="visible";
	nl2.zIndex=1;

	document.wul.visibility = "hidden";
}

function setQT()
{
	qtH = mpH;
	if (window.__AsxFileType__ == 1) qtH = 0;
	
 	d='<EMBED width="'+mpW+'" height="'+qtH+'" ';
 	
 //	d+='autoplay="true" ';
 	d+='bgcolor="BLACK" ';
 	d+='controller="false" ';
 	d+='kioskmode="true" ';
 //	d+='loop="true" ';
 	d+='volume=100 ';
 	d+='pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" ';
	d+='name="NSPlay" ';
	d+='enablejavascript="true"'
	
	d+='> ';
	d+='</EMBED> ';
	

	return d;
}

function getPlayerID() //## need a way to get a unique ID from QT
{
	return "XXX";
}

function TPlay()
{
	if (!restoreStreamConnection())
	{
		oMP.Play();
		g_playState = 2;
	}
}

function restoreStreamConnection()
{
	if (g_lastPause != null &&
	   ((new Date()) - g_lastPause) > 58000) //connection is reset by the server after a min.
	{
		oMP.SetURL("");
		oMP.SetURL(g_MP_FileName);
		if (g_pausedAt != 0)
			oMP.SetTime(g_pausedAt);
		g_lastPause = null;
		g_playState = 2;
		setTimeout("oMP.Play()",500);
		return true;
			
	}
	g_lastPause = null;
	return false;
}

function TStop()
{
	oMP.Rewind();
	g_playState = 0;
	g_lastPause = new Date();
	g_pausedAt = 0;
}

function TPause()
{
	oMP.Stop()
	g_playState = 1;
	g_lastPause = new Date();
	g_pausedAt = oMP.GetTime();
}

function TMoveMpl(yPos){}
