//---------------------------------------------------------
//鼠标悬停效果
//---------------------------------------------------------
var bookDetailObjArr = new Array();
function bookDetailLoadImgObj(){
	var imagObj = $$(".imgOn");
	for(var j = 0 ; j < imagObj.length ; j++){
		bookDetailObjArr[j] = new BookDetailImgObj(imagObj[j]);
		bookDetailObjArr[j].mouseOver();
		bookDetailObjArr[j].mouseOut();
		
	}
}
var BookDetailImgObj = Class.create({
	//初始化
	initialize: function(ctrl) {
		this.ctrl = ctrl;
		
		this.normalImgUrl = this.ctrl.src;
		this.deepImgUrl = this.ctrl.src.replace(/0\.gif/g,".gif");
	}, 
	//鼠标悬停
	mouseOver : function(){
		this.mouseOverE = this.MM_swapImage.bindAsEventListener(this);
		Event.observe(this.ctrl,'mouseover',this.mouseOverE);
	},
	//鼠标离开
	mouseOut : function(){
		this.mouseOutE = this.MM_swapImgRestore.bindAsEventListener(this);
		Event.observe(this.ctrl,'mouseout',this.mouseOutE);
	},
	//停止鼠标事件(包括悬停和离开事件)
	stopMouseEvent : function(){
		Event.stopObserving(this.ctrl, 'mouseover', this.mouseOverE);
		Event.stopObserving(this.ctrl, 'mouseout', this.mouseOutE); 
		
	},
	//鼠标离开
	MM_swapImgRestore : function() { 
		this.ctrl.src = this.normalImgUrl;
	},
	//鼠标悬停
	MM_swapImage : function() { 
		this.ctrl.src = this.deepImgUrl;
	}
});
/**
 * 切换标签
 * @Param 
 *	tabIndex (0 : 中文， 1 : 英文)
 */
function bg_changeTab(tabIndex){
	var cnTabObj = $("bg_tab1");
	var enTabObj = $("bg_tab2");
	
	if (tabIndex == 0) { // 切换到中文
		enTabObj.className="display02";
		cnTabObj.className="display01";
		
		// 更改所有的内容为中文内容
		var enObjs = getElementsByName("div","bd_en");
		for (var i=0; i<enObjs.length; i++){enObjs[i].style["display"] = "none";}
		var cnObjs = getElementsByName("div","bd_cn");
		for (var i=0; i<cnObjs.length; i++){cnObjs[i].style["display"] = "block";}
	} else { // 切换到英文
		enTabObj.className="display01";
		cnTabObj.className="display02";	
		
		// 更改所有的内容为英文内容
		var enObjs = getElementsByName("div","bd_en");
		for (var i=0; i<enObjs.length; i++){enObjs[i].style["display"] = "block";}
		var cnObjs = getElementsByName("div","bd_cn");
		for (var i=0; i<cnObjs.length; i++){cnObjs[i].style["display"] = "none";}	
	}
}

// 保存所有打开的Section
// 格式为unitId : obj
var openedSectionMap = {};
/**
 * 查看当前单元中的课程
 */
function bg_viewSection(thisObj, unitId){
	// 将除了当前的单元外所有的其他打开单元都关闭
	for (var unitIdTmp in openedSectionMap){
		if (unitIdTmp == unitId) continue;
		bg_handleSection(openedSectionMap[unitIdTmp], unitIdTmp, false);
		delete openedSectionMap[unitIdTmp];
	}
	
	if (typeof(openedSectionMap[unitId]) == "undefined") { // 如果当前单元没有打开
		bg_handleSection(thisObj, unitId, true);
		openedSectionMap[unitId] = thisObj;
	} else { // 如果当前单元已经打开
		bg_handleSection(thisObj, unitId, false);
		delete openedSectionMap[unitId];
	}
}

/**
 * 打开第一个section
 */
function bg_openFirstSection(){
	setTimeout(function(){
		var firstUnitIdObj = document.getElementById("bg_firstUnitId");
		bg_viewSection(firstUnitIdObj, "unitId_" + firstUnitIdObj.value);		
	}, 500);
}

/**
 * 重写'getElementsByName'方法
 */
var getElementsByName = function(tagName,name){
	var returns = document.getElementsByName(name);
	if(returns.length > 0) return returns;
	
	returns = new Array();
	var tags = document.getElementsByTagName(tagName);
	var v = [];
	for(var i = 0 ; i < tags.length ; i++ ){
		if(tags[i].getAttribute("name") == name){
			returns[returns.length] = tags[i];
			v[v.length] = 1;
		}
	}
	return returns;
} 
 
/**
 * 处理section的打开和闭合
 */
function bg_handleSection(sectionObj, unitId, is2Open){
	var lessonObjs = getElementsByName("div",unitId+"");
	//alert("lessonObjs.length = " + lessonObjs.length);
	for (var i=0; i<lessonObjs.length; i++){
		lessonObjs[i].style["display"] = is2Open?"block":"none";
		sectionObj.parentNode.className=is2Open?"li_san g_ke":"li_san02 g_ke";
	}
}

/** 
 * 关闭订阅
 */
function closeOrder(){
	document.getElementById("mask").style["display"] = "none";
	document.getElementById("testContainer").style["display"] = "none";
	var tfObj = document.getElementById("testFrame");
	tfObj.src = "";
	currentStep = 1;
}

/**
 * 打开订阅
 */
function startOrder(bookId){
	var mask = document.getElementById("mask");
	var bodyWidth = document.body.clientWidth;
	var bodyHeight = document.body.clientHeight;
	mask.style["position"] = "absolute";
	mask.style["left"] = 0;
	mask.style["top"] = 0;
	mask.style["width"] = bodyWidth;
	mask.style["height"] = bodyHeight;
	mask.style["display"] = "block";
	var container = document.getElementById("testContainer");
	container.style["left"] = (bodyWidth-645)/2;
	container.style["top"] = (bodyHeight-560)/2;
	container.style["display"] = "block";
	var tfObj = document.getElementById("testFrame");
	tfObj.width=490;
	tfObj.height=180;
	tfObj.src = getAbsolute()+getServName()+"/apps/books/bookOrder.action?bookId="+bookId+"&timestamp="+(new Date()).getTime();
}
