
function showEl(id){
	try{
		document.getElementById(id).style.display="block";
		return true;
	}catch(e){
		return false;
	}
}
function hideEl(id){
	try{
		document.getElementById(id).style.display="none";
		//document.getElementById(id).style.visibility="visible";
		return true;
	}catch(e){
		return false;
	}
}
function showVis(id){
	try{
		document.getElementById(id).style.display="block";
		return true;
	}catch(e){
		return false;
	}
}
function hideVis(id){
	try{
		document.getElementById(id).style.display="none";
		//document.getElementById(id).style.visibility="visible";
		return true;
	}catch(e){
		return false;
	}
}
var pageControlDivID="voxpageControlDivID";
var pageControlFlashID="voxpageControlFlashID";
function loadPageControlFlash(){

}
function preLoadLangStudy(){

}

function preLoadPronuStudy(userName,lessonId,subId,scoreLine,isPass){

}

function hideStudy(){
	
}

function showStudy(){
	showEl(studyID);
	showEl(studyControlID);
}

function preview(){
	pageControl.preview();
	try{
		document.getElementById(pageControlFlashID).compulsiveGo(2);
	}catch(e){
		
	}
} 
var userInfoID="voxuserInfoID";
var progressID="voxprogressID";
var studyID="voxstudyID";

var studyControlID="voxstudyControlID";
var scoreID="voxscoreID";
var studyControlImg="voxstudyControlImg";

var previewDivID="voxpreviewDivID";
var langStudyDivID="voxlangStudyDivID";
var langStudyFlashID="voxlangStudyFlashID";
var pronuStudyDivID="voxpronuStudyDivID";
var reviewDivID="voxreviewDivID";

var pronuStudyFlashID="voxpronuStudyFlashID";
var pronuStudyDivID="voxpronuStudyDivID";

var notSubState={
    beginStudy:function(){
    	clickPageControlFlash(2);
    },
	preview:function(){
		showEl(userInfoID);
		hideEl(studyID);
		hideEl(studyControlID);
		hideEl(studyID);
	},
	langStudy:function(){
		showEl(userInfoID);
		hideEl(progressID);
		hideEl(studyID);
		hideEl(studyControlID);
	},
	pronuStudy:function(){
		showEl(userInfoID);
		hideEl(progressID);
		showEl(studyID);
		hideEl(studyControlID);
	},
	review:function(){
		showEl(userInfoID);
		hideEl(progressID);
		hideEl(studyID);
		hideEl(studyControlID);
	}
}

var subState={
    beginStudy:function(){
    	pageControl.pronuStudy();
    },
	preview:function(){
		showEl(userInfoID);
		showEl(progressID);
		hideEl(studyID);
		hideEl(studyControlID);
	},
	langStudy:function(){
		showEl(userInfoID);
		showEl(progressID);
		hideEl(studyID);
		hideEl(studyControlID);
	},
	pronuStudy:function(){
		showEl(userInfoID);
		showEl(progressID);
		showEl(studyID);
		showEl(studyControlID);
	},
	review:function(){
		showEl(userInfoID);
		showEl(progressID);
		hideEl(studyID);
		hideEl(studyControlID);
	}
}
var pageState={
	step1:1,
	step2:0
}
var pronuStudyState={
	step1:0,
	step2:0,
	step3:0
}
var isSub=false;
/************************
 * 给最上端控制逻辑的flash的方法
 */
function jumpCheck(fromPos,toPos){
	//playerTips layer
	tips(fromPos,toPos);
	
	if(!isSub){
		return new Array(1,"");
	}
	//从后往前，不提示
	if(toPos<fromPos){
		return new Array(1,"");
	}
	if(pageState.step1==1&&pageState.step2==1){
		return new Array(1,"");
	}
	if(fromPos==1){
		if(pageState.step1!=1){
			return new Array(0,"您还未完整学习课程内容，朗酷不建议您跳跃学习步骤，这样会影响您的学习效果，并且朗酷可能无法保存您的学习历史!");
		}else{
			if(toPos==3&&pageState.step2!=1){
				return new Array(0,"朗酷不建议您跳跃学习步骤，建议您先开始语音练习。否则这样会影响您的学习效果!");
			}else{
				return new Array(1,"");
			}
		}
	}
	if(fromPos==2){
		if(pageState.step2!=1){
			return new Array(0,"您还未完整学习课程内容，朗酷不建议您跳跃学习步骤，这样会影响您的学习效果，并且朗酷可能无法保存您的学习历史!");
		}
	}
}
function switchStep(step){
	try{
		var flashObj=document.getElementById(pronuStudyFlashID);
		flashObj.stopLesson();
	}catch(e){
		
	}
	if(step==1){
		pageControl.langStudy();
	}else if(step==2){
		pageControl.pronuStudy();
	}else{
		preLoadWorstSent(2);
		pageControl.review();
	}
}
var pageControl={
	currentState:notSubState,
	beginStudy:function(){
    	this.currentState.beginStudy();
    },
	setState:function(state){
		this.currentState=state;
	},
	preview:function(){
		this.currentState.preview();
		showVis(previewDivID);
		hideVis(langStudyDivID);
		hideVis(pronuStudyDivID);
		hideVis(reviewDivID);
	},
	langStudy:function(){
		this.currentState.langStudy();
		hideVis(previewDivID);
		showVis(langStudyDivID);
		hideVis(pronuStudyDivID);
		hideVis(reviewDivID);
	},
	pronuStudy:function(){
		this.currentState.pronuStudy();
		hideVis(previewDivID);
		hideVis(langStudyDivID);
		showVis(pronuStudyDivID);
		hideVis(reviewDivID);
		setTimeout(function(){
			pronuStudyControl.initData();
			var flashObj=document.getElementById(pronuStudyFlashID);
			flashObj.setLanguageState(pageState.step1);
		},1500);
	},
	review:function(){
		this.currentState.review();
		hideVis(previewDivID);
		hideVis(langStudyDivID);
		hideVis(pronuStudyDivID);
		var innerReview=document.getElementById("reviewContentID").innerHTML;	
		var lessonId=document.getElementById("hideLessonId").value;
		showVis(reviewDivID);
		if(innerReview.length==0){
			document.getElementById("reviewContentID").innerHTML="<iframe marginwidth=\"0\" marginheight=\"0\"  name=\"reviewFrame\"  id=\"reviewFrame\" scrolling=\"no\" width=\"622\" height=\"496\"  frameborder=\"0\" src=\""+relativePath+"/review/loadReview.action?lessonId="+lessonId+"\"></iframe>";
		}else{
			window.frames["reviewFrame"].loadWorstSentence();	
		}
	}
}
function changeImg(imgName,tip,height,event){
	var originHtml="<img id=\"studyControlImg\" style=\"cursor:hand;\" src=\""+relativePath+"/images/newplayer/"+imgName+"\" width=\"178\""
			+"	height=\""+height+"\" alt=\""+tip+"\" onclick=\""+event+"\">";
	var parentTR=document.getElementById(studyControlID);
	parentTR.childNodes(0).innerHTML=originHtml;
}

function addHotPoint(){
	var mapHtml="<table width=\"177\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
		+"  <tr> "
		+"    <td colspan=\"4\" class=\"ziti12huise\"><img src=\""+relativePath+"/images/newplayer/gxgg_01.gif\" width=\"178\" height=\"30\"></td>"
		+"  </tr>"
		+"  <tr class=\"ziti12huise\"> "
		+"    <td width=\"16\" align=\"left\"><img src=\""+relativePath+"/images/newplayer//gxgg_02.gif\" width=\"17\" height=\"23\"></td>"
		+"    <td width=\"79\" align=\"left\"><a href=\"#\" onclick=\"pronuStudyControl.go2Step(3)\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image6','','"+relativePath+"/images/newplayer/gxgg_03_1.gif',1)\"><img src=\""+relativePath+"/images/newplayer/gxgg_03.gif\" name=\"Image6\" width=\"79\" height=\"23\" border=\"0\"></a></td>"
		+"    <td width=\"64\" align=\"left\"><a href=\"#\" onclick=\"clickPageControlFlash(3)\" onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('Image7','','"+relativePath+"/images/newplayer/gxgg_04_1.gif',1)\"><img src=\""+relativePath+"/images/newplayer/gxgg_04.gif\" name=\"Image7\" width=\"64\" height=\"23\" border=\"0\"></a></td>"
		+"    <td width=\"18\"><img src=\""+relativePath+"/images/newplayer/gxgg_05.GIF\" width=\"18\" height=\"23\"></td>"
		+"  </tr>"
		+"  <tr class=\"ziti12huise\"> "
		+"    <td colspan=\"4\"><img src=\""+relativePath+"/images/newplayer/gxgg_06.GIF\" width=\"178\" height=\"8\"></td>"
		+"  </tr>"
		+"</table>";
	var parentTR=document.getElementById(studyControlID);
	parentTR.childNodes(0).innerHTML=mapHtml;
}
// 参数 1 2 3 分别代表语言页，语音页，复习页
function clickPageControlFlash(pos){
	try{
		document.getElementById(pageControlFlashID).go(pos);
	}catch(e){
		alert(e.message);
	}
}
function canNotClick(){
	return true;
}
var pronuStudyControl={
	isFirstInit:true,
	initData:function(){
		if(this.isFirstInit){
			var flashObj=document.getElementById(pronuStudyFlashID);
			flashObj.loadLesson();
			this.loadStep1Button();
			this.isFirstInit=false;
		}
	},
	go2Step:function(step){
		var flashObj=document.getElementById(pronuStudyFlashID);
		flashObj.gotoStep(step-1);
	},
	loadStep1Button:function(){
		if(pronuStudyState.step1==1){
			changeImg("step1ok.gif","恭喜，您可以进入单句语音练习了。",32,"pronuStudyControl.go2Step(2)");
		}else{
			changeImg("step1no.gif","请先完成全文跟读课程练习。",32,"canNotClick()");
		}
	},
	loadStep2Button:function(){
		if(pronuStudyState.step2==1){
			addHotPoint();
		}else{
			changeImg("step2no.gif","请通过单句练习提高您的口语发音。",32,"canNotClick()");
		}
	},
	loadStep3Button:function(){
		if(pronuStudyState.step2==1){
			changeImg("step3ok.gif","您的全文挑战练习已经完成。",32,"clickPageControlFlash(3)");
		}else{
			changeImg("step3no.gif","全文挑战每句跟读只有2次机会。",32,"canNotClick()");
		}
	}
}
function updateScore(score){
	var realScore=parseInt(score);
	if(isNaN(realScore)){
		realScore=0;
	}
	try{
		document.getElementById(scoreID).innerText=realScore;
		updateBackgroundImg(realScore);
		return true;
	}catch(e){
		return false;
	}
}
function updateBackgroundImg(realScore){
	var scoreLine=document.getElementById("scoreLineTd").scoreline;
	//alert(scoreLine+":"+realScore);
	if(scoreLine==0){
		return true;
	}else{
		if(scoreLine==realScore){
			//alert("=");
			document.getElementById("scoreImgTd").background=relativePath+"/images/newplayer/ggfs_dt2.gif";
		}else if(scoreLine<realScore){
			document.getElementById("scoreImgTd").background=relativePath+"/images/newplayer/ggfs_dt3.gif";
		}else{
			document.getElementById("scoreImgTd").background=relativePath+"/images/newplayer/ggfs_dt.gif";
		}
	}
}
 // 预览跟读完成时候调用并将本次预览跟读的分数传入
   // 注意：用户有可能进行多次预览跟读，此方法会被多次调用
   //@Param
   //  lessonScore: 预览跟读的分数
   //  isPass: 当前课程的达标状态
   //      true: 达标， false：不达标
   //      此参数为当前课程的达标状态，只要有一次达标，那么此参数将固定为true
   //@Return
   //  无
 function previewFinished(lessonScore, isPass){
 	//alert(lessonScore+":"+isPass);
 	updateScore(lessonScore);
 	if(isPass==true){
	 	pronuStudyState.step1=1;
	 	pronuStudyState.step2=1;
	 	pageState.step2=1;
 	}else{
 		pronuStudyState.step1=1;
 	}
 	pronuStudyControl.loadStep1Button();
 }
    
   // 单句跟读完毕后会被调用并将读完此句后重新计算的分数传入
   // 注意：单句模式下，每读完一句此方法就会被调用，传入的分数为增量分数
   //@Param
   //  lessonScore: 课程的分数
   //  isPass: 当前课程的达标状态
   //      true: 达标， false：不达标
   //      此参数为当前课程的达标状态，只要有一次达标，那么此参数将固定为true
   //@Return
   //  无
function singleFinished(lessonScore, isPass){
	// alert(lessonScore+":"+isPass);
 	 updateScore(lessonScore);
 	 if(isPass==true){
	 	pronuStudyState.step1=1;
	 	pronuStudyState.step2=1;
	 	pageState.step2=1;
 	}
 	pronuStudyControl.loadStep2Button();
}
		
   // 挑战跟读完毕后会被调用将读完此句后重新计算的分数传入
   //@Param
   // lessonScore: 挑战跟读的分数
   //@Return
   //  无
function challengeFinished(lessonScore){
	 //alert(lessonScore+":"+isPass);
 	 updateScore(lessonScore);
 	 pronuStudyState.step3=1;
 	 pronuStudyControl.loadStep3Button();
 	 var count = 3;
 	 var iId = setInterval(function(){
 	 	updateChallengeBoard();
 	 	count++;
 	 	if (count > 10) clearInterval(iId);
 	 }, 500);
 	 
 }
 
function usrGetChallengeTop1(){
	// 调用PlayerRight中的方法刷新挑战分数面板
	updateChallengeBoard();
}

function updateChallengeBoard(){
	try {
		refreshChallengeBoard();
	}catch(e){
		
	}
}
   // 用户进入不同的场景后会调用此方法
   //@Param
   //  step: 
   //     0: 预览跟读
   //     1：单句跟读
   //     2: 挑战跟读
function stepChanged(step){
     if(step==0){
     	pronuStudyControl.loadStep1Button();
     }else if(step==1){
     	pronuStudyControl.loadStep2Button();
     }else if(step==2){
     	pronuStudyControl.loadStep3Button();
     }
}
// 进入复习页
function gotoReviewPage(){
	clickPageControlFlash(3);
}
				
// 进入语言学习
function gotoLanguagePage(){
	clickPageControlFlash(1);
}
//更新成绩单的接口
function updateReportCard(excellent, good, pass, pronsErr, noFluent, volumeErr){
	updateInner("voxMaxScore",excellent);
	updateInner("voxGoodScore",good);
	updateInner("voxPassScore",pass);
	updateInner("voxPronuErrorScore",pronsErr);
	updateInner("voxNotFluentScore",noFluent);
	updateInner("voxBelowScore",volumeErr);	
}
function updateInner(id,score){
	var realScore=parseInt(score);
	if(isNaN(realScore)){
		realScore=0;
	}
	try{
		document.getElementById(id).innerText=realScore;
			return true;
	}catch(e){
		return false;
	}	
}
var worstSentences;
function preLoadWorstSent(num){
	var flashObj=document.getElementById(pronuStudyFlashID);
	try{
		worstSentences=flashObj.getWorstSentences(num);
	}catch(e){
		worstSentences=null;
	}
}
function getWorstSent(num){
	return worstSentences;
}
function playUserVoice(){
	clickPageControlFlash(2);
	var flashObj=document.getElementById(pronuStudyFlashID);
	setTimeout(function(){
		flashObj.startWholeLessonReplay();
	}, 500);
}
function playTeacherVoice(){
	clickPageControlFlash(2);
	var flashObj=document.getElementById(pronuStudyFlashID);
	setTimeout(function(){
		flashObj.startWholeReplayTeacher();
	}, 500);
}
