var isPlayer = "";
var isList = "";
var isSetup = false;
var isTimeOut = 5000;
var codeUrl = "http://download.pplive.com/webinstall/install.CAB#version=";
var thisVersion = "1.2.33.1108";
var codeVer = "1,2,36";
var isReload = 0;
var ppliveurl = false;  //如果需要启动后自动播放节目，请在后面写节目链接
//指定加载Player的页面位置
var pplPlayer = "hiflyliveplayer";
//不显示播放列表
var pplList = "";
//值为true时为自动加载控件，值为false时手动加载，需要在加载页面位置，写入触发加载事件
//如<a href="javascript:getPPLive();">点击加载控件</a>
var loadMethod = true;


function ocxstatus(){
	var SynaObj;
	try{
		SynaObj = new ActiveXObject("Synacast.EWA");
		var thisVers = SynaObj.version;
		if(thisVers){
				isSetup = true;
				getPPLive();
		}
		else{setTimeout(ocxstatus,isTimeOut);}
	}catch(e){
		if(!isSetup && loadMethod){
			isSetup = true;
			getPPLive();
		}
		setTimeout(ocxstatus,isTimeOut);
	}
}

function getPPLive(){
	try{
		$("player").Destroy();
		$("list").Destroy();
	}catch(e){}
	var pplive = '<object id="player" style="width: 100%; height: 100%;" classid="CLSID:18226BF8-DC0B-4D81-80E9-A41AE37BB73A" '
				+'codebase="'+codeUrl+codeVer+'">'
				+ isPlayer + '</object>';
	$(pplPlayer).innerHTML = pplive;
	if(pplList && $("player").PlayerHWnd){
		var listArea = '<object id="list" style="width: 100%; height: 100%;" classid="CLSID:70CACCCA-8B83-4BCB-B2D1-188E9A495527">'
						+ isList +'</object>';
		$(pplList).innerHTML = listArea;
		$("list").PlayerHWnd = $("player").PlayerHWnd;
	}
	if(ppliveurl){
		try{$("player").URL = ppliveurl;}catch(e){}
	}
}
function addMode(ModeName,ModeValue,ModeObj){
	var modestyle = '<param name="'+ ModeName +'" value="'+ ModeValue +'" />';
	if (ModeObj == 1){
		isPlayer += modestyle;
	}else if(ModeObj == 2){
		isList += modestyle;
	}
}
function parentSize(obj,method){
	if(method == "wid"){
		return $(obj).offsetWidth;
	}else if(method == "high"){
		return $(obj).offsetHeight;
	}	
}
window.onunload = function(){
	$("player").Destroy();
	$("list").Destroy();
}

//音量
function initCtlPlane() 
{
	var VDrg = document.getElementById('VDrg');//volume
	var VBox = document.getElementById('VBox');//volume box
	VBox.style.width = 42;
	VDrg.style.width = 7;
	if(VDrg != null)
	{
		var evtObj = false, O_x, N_x;
		var MaxBound = parseInt(VBox.style.width) - parseInt(VDrg.style.width);
		//alert(VBox.style.width);
		window.document.ondragstart = function() {return false;}
		window.document.onmousemove = function() 
		{
			if(evtObj) {
				N_x = event.clientX;
				var MovePels = evtObj.style.pixelLeft + N_x - O_x;
				if(MovePels <= MaxBound && MovePels >= 0) {
					evtObj.style.pixelLeft = MovePels;
					player.Volume = (evtObj.style.pixelLeft)*100/MaxBound;
					O_x = N_x;
				}
			}
		}
		window.document.onmouseup = function() {if(evtObj) {evtObj = false;}}
		window.document.onmousedown = function() {if(event.srcElement.id=='VDrg') {evtObj = event.srcElement;O_x = event.clientX;}}
	}
}

document.onkeydown = function() {
    switch( event.keyCode )
    {
      case 100:
      case 52:   //数字键4
        document.getElementById("player").FullScreen = true;
        break;
      case 27:   //Esc
        document.getElementById("player").FullScreen = false; 
        break;
     default: 
        break;
    }
}

//加载创建控件函数
window.onload = function(){
	//添加PLAYER功能
	addMode("LogoFileName","http://jx163.pplive.net/hifly/pplive.htm",1);
	addMode("ShowGall",0,1);
	addMode("ShowPlayCtrl",0,1);
	addMode("ShowMenu",0,1);
	//载入控件，检测安装情况
	ocxstatus();
	window.status = '金鹰网直播';
}