//实例化
var tryOut = null;
//load
Event.observe(window,'load',function(){
	if(!tryOut){
		tryOut = new TryOut();
	}
	
});
var TryOut = Class.create({
	initialize : function(){
		this.activeXInstalledStr = "您安装ActiveX语音插件成功，下面请进行麦克风检测。";
		this.micTestedStr = "恭喜！您现在可以进行您的朗酷学习之旅。";
	},
	//页面显示
	showDiv : function() {
		var activeXInstalled = false,micTested = false;
		if (checkActivexInstall()) { // 如果已经安装了activex
			this.gotoState(1);
			activeXInstalled = true;
		} else { // 如果没有安装activex
			this.gotoState(0);
		}
		
		if (checkMicTest(true) && activeXInstalled) { // 如果已经检测了麦克风
			this.gotoState(3);
			micTested = true;
		} else { // 如果没有检测过麦克风
			this.gotoState(2);
		}
		
		if(micTested && activeXInstalled){
			this.gotoState(4);
		}else if(activeXInstalled){
			this.gotoState(5);
		}
	},
	// 状态检测
	stateCheck : function() {
		setInterval("tryOut.showDiv()", 1000);
	},
	// 进入某一状态
	// 0 : 未安装插件时状态
	// 1 : 已安装插件时状态
	// 2 : 没有检测过麦克风
	// 3 : 已经检测了麦克风
	// 4 : 语音插件和麦克风检测都做完了
	// 5 : 语音插件安装完成时
	gotoState : function (state) {
		var activeXInstalledStr = "您安装ActiveX语音插件成功，下面请进行麦克风检测。";
		var micTestedStr = "恭喜！您现在可以进行您的朗酷学习之旅。";
		var activeXDivObj = $("activeXDiv"); // 安装ActiveX背景
		var activeNoInstallStateObj = $("activeNoInstallState"); // 未安装ActiveX状态
		var activeInstalledStateObj = $("activeXInstalledState"); // 已安装ActiveX状态
		var activeXUpdateStateObj = $("activeXUpdateState"); // 已安装ActiveX状态但版本不对
		var micNoTestStateDivObj = $("micNoTestStateDiv"); // 麦克风未检测状态
		var micTestedStateDivObj = $("micTestedStateDiv"); // 麦克风已检测状态
		//var installTipObj = $("installTip"); // ActiveX插件安装提示
		var loadingDiv = $("loading"); 	//载入进行中的提示
		// 返回上一页按钮
		
		loadingDiv.setStyle({'display':'none'});
		switch (state) {
		// 如果没有安装activex
		case 0:
			//installTipObj.style["display"] = "block";
			activeNoInstallStateObj.style["display"] = "block";
			activeXUpdateStateObj.style["display"] = "none";
			activeInstalledStateObj.style["display"] = "none";
			//$("loadingActiveX").style.display = "block";
			break;
		// 如果安装activex
		case 1:
			activeNoInstallStateObj.style["display"] = "none";
			if (checkActivexVersion()) {
				//installTipObj.style["display"] = "none";
				activeInstalledStateObj.style["display"] = "block";
				activeXUpdateStateObj.style["display"] = "none";
				//$("loadingActiveX").style.display = "none";
			} else {
				//installTipObj.style["display"] = "block";
				activeInstalledStateObj.style["display"] = "none";
				activeXUpdateStateObj.style["display"] = "block";
				//$("loadingActiveX").style.display = "block";
			}
			break;
		// 如果没有检测过麦克风
		case 2:
			micNoTestStateDivObj.style["display"] = "block";
			micTestedStateDivObj.style["display"] = "none";
			break;
		// 如果已经检测了麦克风
		case 3:
			micNoTestStateDivObj.style["display"] = "none";
			micTestedStateDivObj.style["display"] = "block";
			break;
		case 4:
			this.insertEle();
			break;
		case 5:
			//this.insertEle(activeXInstalledStr);
			break;
		}
		
	},
	//插入元素
	insertEle : function(tip){
		if($("achieve")){
			$("achieve").remove();
		}
		if(!!tip){
			new Insertion.After("toc_step_2","<div id=\"achieve\">" + tip + "</div>");
		}else{
			var imgEle = "<img src='" + constants.url() + "/v3_view/common/image/tryOut/img_ActiveX_18.gif' />";
			new Insertion.After("toc_step_2","<div id=\"achieve\">" + imgEle + "</div>");
		}
		
	},
	//填充ActiveX对象
	fillActiveX : function(){
		var innerHtml = "<OBJECT CLASSID='clsid:7F8F20F2-B9C6-43A0-A830-7D6BF66D622D' CODEBASE='"
			+ constants.url()
			+ "/VoxLearning.cab#Version=" + serverVersion + "'></OBJECT>".unescapeHTML();
		$("voxActiveXContainer").innerHTML = innerHtml;
	},
	//麦克测试
	micTestClicked : function() {
		if(!checkActivexInstall()){
			alert("请先安装插件再测试麦克风");
		}else{
			prepearMask();
			prepearContainer(450, 300).src = constants.url() + "/common/micTest.action";
		}
	},
	//下载ActiveX插件
	downActivex : function() {
		window.open(constants.url() + "/InstallLangKooActiveX.exe");
	},
	//onLoad
	onPageLoad : function() {
		this.showDiv();
		this.stateCheck();
		this.fillActiveX();
	}
	
});



function recordFinished(reason) {
	tryOut.gotoState(2);
}

function toRegister() {
	history.go(-1);
}
function checkActivex() {
	// 覆盖原来的方法,因为在tryout页不需要再转向
	return checkActivexInstall();
}
function closeTest(){
	$("mask").style["display"] = "none";
	$("testContainer").style["display"] = "none";
	var tfObj = $("testFrame");
	tfObj.src = "";
	currentStep = 1;
	window.onresize = null;
}
