var isListReady = false;
var isPlayerReady = false;
var timerIdList = 0;
var timerIdPlayer = 0;
var bCodebase = false;
var isChinese = true;
var showControlBar = true;
var showStatusBar = true;
var sVendor = "";
var sDownloadUrl = "http://www.ppmate.com/search/download.jsp";

function UseCodebase(b){
    bCodebase = b;	
}
function SetDownloadUrl(sUrl){
    sDownloadUrl = sUrl;	
}
function ChineseLanguage(b){
    isChinese = b;
}
function SetVendor(v){
    sVendor = v;
}
function Binding(){
	var objPpmList = document.getElementById("ppmlist");
	var objPpmPlayer = document.getElementById("ppmplayer");
	if(objPpmList != null){
		try{
			objPpmList.SetLanguage(isChinese);
		}catch(e){}
	}
	if(objPpmPlayer != null){
		try{
			objPpmPlayer.ChLanguage = isChinese;
			if(sVendor != "")
			    objPpmPlayer.strVender = sVendor;
		}catch(e){}
	}
	if(objPpmList == null || objPpmPlayer == null)
	    return;
	try{
		objPpmList.SetPlayer(objPpmPlayer.hwndMain);
	}catch(e){}
}
function ShowChannelList(){
	var objList = null;
	var divListCovering = document.getElementById('listCovering');
	var divList = document.getElementById('divList1');
	
	try{
		objList = new ActiveXObject("PPMList.PMChannel.1");
	}catch(e){}
	if(objList != null && !isListReady){
		objList = null;
		divListCovering.style.display = "none";
		divList.style.display = "";
		isListReady = true;
	}
	if(isListReady){
		if(timerIdList != 0){
			window.clearInterval(timerIdList);
			divList.innerHTML += " ";
		}
		window.setTimeout(Binding,2000);
	}else{
		if(timerIdList == 0)
			timerIdList = window.setInterval(ShowChannelList,5000);
	}
}

function ShowPPMatePlayer()
{
	var objPlayer = null;
	var divPlayerCovering = document.getElementById('playerCovering');
	var divPlayer = document.getElementById('divPlayer1');
	try{
		objPlayer = new ActiveXObject("PPMPlayer.PPMedia.1");
	}catch(e){}
	if(objPlayer != null && !isPlayerReady){
		objPlayer = null;
		divPlayerCovering.style.display = "none";
		divPlayer.style.display = "";
		isPlayerReady = true;
	}
	if(isPlayerReady){
		if(timerIdPlayer != 0){
			window.clearInterval(timerIdPlayer);
			divPlayer.innerHTML += " ";
		}
		window.setTimeout(Binding,2000);
	}else{
		if(timerIdPlayer == 0)
			timerIdPlayer = window.setInterval(ShowPPMatePlayer,5000);
	}
}

function ChannelList(pic,width,height)
{
document.write("<div> ");
document.write("<div id = \"divList1\" style=\"display:none\">");
document.write("<object classid=\'clsid:2be6a92d-d51c-4659-b372-bb18c99bc439\' id=\'ppmlist\' ");
if(!bCodebase){
	document.write(" codebase=\'http://www.ppmate.com/search/downcab.jsp#version=2,0,0,40\'");
	bCodebase = true;
}
if(width != null){
	document.write(" width=\"" + width + "\"");
}
if(height != null){
	document.write(" height=\"" + height + "\"");
}
document.write("></object>");
document.write("</div>");    
document.write("<div id = 'listCovering'>");
document.write("<img src=\'" + pic + "\'");
if(width != null){
	document.write(" width=\"" + width + "\"");
}
if(height != null){
	document.write(" height=\"" + height + "\"");
}
document.write("/></div>");
document.write("</div>");
ShowChannelList();
}

function PPMatePlayer(pic,width,height)
{
document.write("<div>");
document.write("<div id = \"divPlayer1\" style=\"display:none;\">");

document.write("<object classid=\'clsid:72b15b25-2ec8-4cdd-b284-c89a5f8e8d5f\' id=\'ppmplayer\'");
if(!bCodebase){
	document.write(" codebase=\'http://www.ppmate.com/search/downcab.jsp#version=2,0,0,40\'");
	bCodebase = true;
}
if(width != null){
	document.write(" width=\"" + width + "\"");
}
if(height != null){
	document.write(" height=\"" + height + "\"");
}
document.write("></object>");
document.write("</div>");
document.write("<div id = \'playerCovering\'>");
document.write("<a href=\'" + sDownloadUrl + "\'><img src=\"" + pic + "\" border=0");
if(width != null){
	document.write(" width=\"" + width + "\"");
}
if(height != null){
	document.write(" height=\"" + height + "\"");
}
document.write("/></a></div>");
document.write("</div>");
ShowPPMatePlayer();
}

