// 兼容IE FF的ByName方法
function myGetElementsByName(tag,name){
	var elts=document.getElementsByTagName(tag);
	var count=0;
	var returns=[];
	for(var i=0;i<elts.length;i++){
		 if(elts[i].getAttribute("name")==name){
			returns[count++]=elts[i];
		 }
	}    
	return returns;
}

function gamectl(symbol){
	var boxs = myGetElementsByName("div","boxstyle");
	for(j=0;j<boxs.length;j++){
		if(symbol=="--b"){
			boxs[j].innerHTML = boxs[j].innerHTML.replace(/--b/g,"--w");
			for(var ii=1;ii<3;ii++){document.getElementById("cstyle"+ii).className = document.getElementById("cstyle"+ii).className.replace("--b","--w");}
			setCookie("box_style","--w");
		}else{
			boxs[j].innerHTML = boxs[j].innerHTML.replace(/--w/g,"--b");
			for(var ii=1;ii<3;ii++){document.getElementById("cstyle"+ii).className = document.getElementById("cstyle"+ii).className.replace("--w","--b");}
			setCookie("box_style","--b");
		}	
	}
	setAddFav();
}

function setpage(num){
	//相关游戏翻页
	for(i=1;i<6;i++){
		if(i==num){
			document.getElementById("pag"+i).className = "pagon";	
		}else{
			document.getElementById("pag"+i).className = "";	
		}
	}
	
	//滚动时替换该div中的lz_src成src
	var rightcontents = $("div.ga2:eq("+(num-1)+")").html();
	rightcont = rightcontents.replace(/lz_src/g,"src");
	$("div.ga2:eq("+(num-1)+")").html(rightcont);
	
	var prenum = num-1;
	var nextnum = num+1;
	if(prenum<1){prenum=5;}
	if(nextnum>5){nextnum=1;}
	document.getElementById("pagleft").innerHTML='<a class="pre" href="#" onclick="moniclick('+prenum+');return false;" title="上一页"></a>';
	document.getElementById("pagright").innerHTML='<a class="nex" href="#" onclick="moniclick('+nextnum+');return false;" title="下一页"></a></div>';
}


//模拟页码点击效果
function moniclick(num){
	$("#pag"+num).click();
	setpage(num);
}

function turnOff(){
	$("#shadow").css("height",10000).hide();
	$("#shadow").toggle();
	//document.getElementById("turnedOff").style.display = "none";
	document.getElementById("turnedOn").style.display = "block";
	if(document.getElementById("left_box").style.width=="660px"){//12-21修改
		document.getElementById("right_box").style.display = "none";
		document.getElementById("left_box").style.width = "979px";
	}
}

function turnOn(){
	//document.getElementById("turnedOff").style.display = "block";
	document.getElementById("turnedOn").style.display = "none";
	document.getElementById("shadow").style.display = "none";
	if(document.getElementById("left_box").style.width=="979px"){
		document.getElementById("right_box").style.display = "block";
		document.getElementById("left_box").style.width = "660px";//12-21修改
	}
}

function fix(){
	//取得客户分辨率
	lowhh = get_scrheight();
	if(lowhh<=720){
		GoToBestPosition();	
	}
}

//获取用户可视区域的高
function get_scrheight(){
	if(self.innerHeight){
		return self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight){
		return document.documentElement.clientHeight;
	}else if(document.body){
		return document.body.clientHeight;
	}
}


function morevideo(){
	document.getElementById("VideoList").style.height = "";	
	document.getElementById("VideoList").style.overflow = "visible";	
	document.getElementById("openandclose").style.display = "none";
}

function moreversion(){
	document.getElementById("VersionHtm2").style.height = "";	
	document.getElementById("VersionHtm2").style.overflow = "visible";	
	document.getElementById("openandclose2").innerHTML = "";
}

//在载入页面结构的时候优先初始化box
function initbox(){
	fix();
	var box_style = getCookie("box_style");
	if(box_style){
		if(box_style=="--b"){
			gamectl("--w");	
		}else{
			gamectl("--b");
		}
	}
}

//页面加载的时候从cookies读取原先设置的样式
function loadinit(){
	var styleid = parseInt(getCookie("gamestyle"));
	if(styleid){
		if(parseInt(styleid)<=15 && parseInt(styleid)>=1){
			document.getElementById("styleBackground").className = "b"+styleid+"_bg";
			//搜索页面里面的introd 样式
			ss = myGetElementsByName("div","introd");
			for(j=0;j<ss.length;j++){
				indexno = ss[j].className.split("_")[0].replace("common","");
				ss[j].className = ss[j].className.replace("common"+indexno,"common"+styleid);
			}
		}else{setStyle(11);}
	}else{
		setStyle(11);
	}
}

//风格切换函数
function setStyle(styleid){
	//更换页面背景
	document.getElementById("styleBackground").className = "b"+styleid+"_bg";
	for(i=1;i<=15;i++){
		if(styleid==i){
			buttonid = "hf_on";
		}else{
			buttonid = "";	
		}
		//改变按钮状态
		document.getElementById("bstyle"+i).className = buttonid;
	}
	//搜索页面里面的introd 样式
	ss = myGetElementsByName("div","introd");
	for(j=0;j<ss.length;j++){
		indexno = ss[j].className.split("_")[0].replace("common","");
		ss[j].className = ss[j].className.replace("common"+indexno,"common"+styleid);
	}
	//写cookies记录当前风格
	setCookie("gamestyle",styleid);
}

//新版皮肤切换
function openchgskin(){
	document.getElementById("pf_on").style.display = 'block';
}

function closechgskin(){
	document.getElementById("pf_on").style.display = "none";
}

//相关游戏和操作说明切换
function tabchg(num){
	if(num==1){
		document.getElementById("relationgames").style.display = "block";
		document.getElementById("turnpage").style.display = "block";
		document.getElementById("webgame").style.display = "none";
		document.getElementById("relationgamesclass").className = "tab_on";
		document.getElementById("webgameclass").className = "";	
		if(document.getElementById("optionnote")){
			document.getElementById("optionnoteclass").className = "";	
			document.getElementById("optionnote").style.display = "none";
		}
	}else if(num==2){
		document.getElementById("relationgames").style.display = "none";
		document.getElementById("turnpage").style.display = "none";
		document.getElementById("webgame").style.display = "none";
		document.getElementById("relationgamesclass").className = "";
		document.getElementById("webgameclass").className = "";	
		if(document.getElementById("optionnote")){
			document.getElementById("optionnote").style.display = "block";
			document.getElementById("optionnoteclass").className = "tab_on";
		}
	}else{
		document.getElementById("relationgames").style.display = "none";
		document.getElementById("turnpage").style.display = "none";
		document.getElementById("webgame").style.display = "block";	
		document.getElementById("relationgamesclass").className = "";
		document.getElementById("webgameclass").className = "tab_on";	
		if(document.getElementById("optionnote")){
			document.getElementById("optionnote").style.display = "none";
			document.getElementById("optionnoteclass").className = "";
		}
		document.getElementById("webgame").innerHTML = document.getElementById("webgame").innerHTML.replace(/lz_src/g,"src");
	}
}

//写cookies
function setCookie(name,value){var Days = 30;var exp = new Date();exp.setTime(exp.getTime() + Days*24*60*60*1000);document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();}
//读取cookies
function getCookie(name){var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");if(arr=document.cookie.match(reg)) return unescape(arr[2]);else return null;}