function alertUp(lVer)
{	

	var cfm = confirm("Your SopCast "+ detectPlugin() +" is older than the lastest version "+lVer+"!\nRecommend you update to lastest version strongly! \nBefore install, CLOSE running SopCast and the web browser first!"); 
	if (cfm == true) { 
	location='http://www.sopcast.com/download/'; 
	}


}

function init(authURL,chURL,lVer)
{	
	var nowV=detectPlugin();
	if (nowV!="" && nowV<lVer) {
		alertUp(lVer);
	}
	if (nowV!="" && nowV<'1.1.2') {
		document.getElementById('SopPlayer').SetAuthUrl(authURL);
		document.getElementById('SopPlayer').SetCookieString(document.cookie)
		document.getElementById('SopPlayer').InitPlayer();
	}
}

function init1(lVer)
{	
	var nowV=detectPlugin();
	if (nowV!="" && nowV<lVer) {
		alertUp(lVer);
	}
	if (nowV!="" && nowV<'1.1.2') {
		document.getElementById('SopPlayer').InitPlayer();
	}
}

function InitPlayer()
{			
	if (detectPlugin()!=null && detectPlugin()!="" ) 
	{

		document.getElementById('SopPlayer').InitPlayer();
	}	
}

function OnPlay(channelUrl, channelName)
{
	if(document.getElementById('SopPlayer').GetState(1) == 0)
	{
		alert("Player hasn't been initialized!");
		return;
	}
	document.getElementById('SopPlayer').SetSopAddress(channelUrl);
	document.getElementById('SopPlayer').SetChannelName(channelName);

	document.getElementById('SopPlayer').Play();
	//alert(channelUrl);
}

function OnPause()
{
	document.getElementById('SopPlayer').Pause();
}

function OnRestart()
{
	document.getElementById('SopPlayer').RestartPlayer();
}
				
function OnStop()
{
	document.getElementById('SopPlayer').Stop();			
}

function OnGetChannelList()
{
	SopPlayer.SetPlayerName("ESopCast 0.9.0");
	var inHtml = SopPlayer.GetChannelList(1);
	document.getElementById('chlist').innerHTML = inHtml;		
}

var started = 0;
function StartPlayer(chURL,chName)
{
		if(started == 0)
		{  
			if(document.getElementById('SopPlayer').GetState(1) == 1)
			{
				OnPlay(chURL, chName);
				started = 1;
			}	else 
			{
				setTimeout("StartPlayer('"+chURL+"','"+chName+"')", 300);
			}
			
		}
}


function detectPlugin()
{
    var pVersion;
    try
    {
        pVersion = document.getElementById('SopPlayer').GetVersion();  
        return pVersion;
       //return true;
    }
    catch (e)
    {
        return "";
    }
}
