// Ver 0.9.1 05/09/2006
//////////////////////////////////////////////////////////////
//
//	Copyright 2006 SopCast
//	Free for public non-commercial use and modification
//	as long as this header is kept intact and unmodified.
//	Please see http://www.sopcast.com for more information
//	or email bug@sopcast.org with questions/suggestions.
//
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//////////	 SopCast WebPlayer 	 //////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////


function InitPlayer()
{			
	if (detectPlugin())
	{
		document.getElementById('SopPlayer').InitPlayer();
	}	
}
		
function OnPlay(channelUrl, channelName)
{
	if (detectPlugin())
	{
		if(document.getElementById('SopPlayer').GetState(1) == 0) //
		{
			alert("Player hasn't been initialized!");
			return;
		}
		document.getElementById('SopPlayer').SetChannelName(channelName);	
		document.getElementById('SopPlayer').SetSopAddress(channelUrl);
		document.getElementById('SopPlayer').Play();
	}
	else
	{
		alert("use Internet Explorer!");
	}
}
		
function OnPause()
{
	if (detectPlugin())
	{
		document.getElementById('SopPlayer').Pause();
	}
}
		
function OnRestart()
{
	if (detectPlugin())
	{
		document.getElementById('SopPlayer').RestartPlayer();
	}
}
						
function OnStop()
{
	if (detectPlugin())
	{
		document.getElementById('SopPlayer').Stop();
	}
}

var accountSet = 0;
function SetAccount(username, password)
{
	if (detectPlugin())
	{
		accountSet = 1;
		document.getElementById('SopPlayer').SetUserAndPasswd(username, password);
	}
}

var autoChannelAddr;
var autoChannelName;
var started = 0;
var autoTimeID = 0;

function AutoPlay(channelAddress, channelName)
{

	autoChannelAddr = channelAddress;
	autoChannelName = channelName;
	if (detectPlugin())
	{
		autoTimeID = setInterval("StartPlayer();", 1000);
	}
} 	


function StartPlayer()
{
	if(started == 0)
	{
		if(document.getElementById('SopPlayer').GetState(1) == 1)
		{
			started = 1;
			OnPlay(autoChannelAddr, autoChannelName);
			clearInterval(autoTimeID);
		}		
	}
}



var noinstallerr=0;
function detectPlugin()
{
    var pVersion;
    try
    {
        pVersion = document.getElementById('SopPlayer').GetVersion();
	return true;
    }
    catch (e)
    {
	if (noinstallerr==0) {
	alert("use Internet Explorer!");
	}
	noinstallerr=1;
        return false;
    }
}












