var lnetshowtime=12000;
var minlnetshowtime=7000;
var file;
var ffile=file;
var islogin;
var ml;
var width = 758;
var height = 528;
	width = 618;
	height = 449;
var tt = 0;
if(screen.width<1024){
	width = 550;
	height = 400;
}
var Type;
var loadingbar=false;
var fullplay = false;
var gamehtml;
var servers = new Array();
servers[0]=['主服务器', 'http://flash.2144.cn/qigongzhu/'];
var serverid=0;
var servername = servers[serverid][0];
var server     = servers[serverid][1];
setCookie('cutserver',serverid,'/');
var sleft="<div class='left'><a href='/help/' target='_blank'>不能播放看这里</a> <a href='javascript:addfav();' style='color:red'>收藏此游戏</a> <a href='/' target='_blank' style='color:#4c892e'>返回首页</a></div>";
var sright="";
var serverdivhtml=sleft+"<div class='servers'></div><div class='clear'></div>";
function getType(){
	var pattern = /(.*)\.(.*)$/gi;
	var fftt=file.split('?');
	var arr = pattern.exec(fftt[0]);
	return RegExp.$2;
}
function fuck(){
	if(!file) {
		sid = (sid=='yx99.com')?'':sid+'/';
		file = sid + s + f
	}
	ffile = file;
	if((file.slice(0,7)!="http://") && (file.slice(0,1)!="/")){
		if(server==undefined) server = servers[0][1];
		file=server+ffile;
	}
}
function addfav(){
	var pageurl = "http://"+self.location.host+self.location.pathname+"?fav";
	window.external.AddFavorite(pageurl, title+' - 游戏久久');
	var img = document.createElement('img');
	img.setAttribute("src", "/addfav.php?id="+id);
	body.appendChild(img);
}
function gotoqzone(){
	qq = prompt("请先登录QQ空间后在此输入你的QQ号码",checkCookieExist('qq')?unescape(getCookie('qq')):"");
	if(qq){
		if(qq.match(/^[1-9]\d{4,9}$/)==null){
			alert('请输入正确的QQ号码');
			return gotoqzone();
		}
		setCookie('qq', qq, '/');	
		$('qzonelink').href="http://www2.yx99.com/go.php?action=qzone&id="+id+"&qq="+qq;
		return true;
	}
	return false;
}
function copyToClipBoard(){
	var gamelink="http://"+self.location.host+self.location.pathname;
	gamelink+='\n这个是我很喜欢的小游戏，名字叫《'+title+'》，真诚向你推荐，希望你也会喜欢哦!';
	window.clipboardData.setData("Text",gamelink);
	alert("耶！复制成功喽！你可以粘贴在QQ消息里送给你的好朋友呀！再次感谢您对本站的支持哦！")
}
function Replay() {
	if(Type=="swf" && document.all){
		$('flash').movie=" ";
		$('flash').movie=server+ffile;
	} else {
		document.location.reload();
	}
}
function startgame(){
	$('game').innerHTML=gamehtml;
	if(Type=="swf") loaded();
	window.setTimeout(closeloadnet,lnetshowtime)
}
function stopgame(){
	$('percentdiv').style.display='none';
	$('game').innerHTML="<div style='width:"+width+"px;height:"+(height-200)+"px;padding-top:200px;'><a style='font-size:18px;font-weight:bold;color:red;' href='javascript:startgame();'>开始游戏</a></div>";
}
function FullPlay() {
	var ft = ffile.split("?");
	stopgame();
	playwin = window.open("/FullPlay.htm?id="+id+"&file="+ft[0]+((ft[1])?"&fv="+encodeURIComponent(ffile.replace(ft[0]+'?','')):"")+"&title="+encodeURIComponent(title),"","width="+screen.width+",height="+(screen.height-40)+"");
}
function FullScreen() {
	FullPlay();
}
function bestsize() {
	FullPlay();
}
function maxsize() {
	FullPlay();
}
function changeserver(sid){
	servername = servers[sid][0];
	server = servers[sid][1];
	if((ffile.slice(0,7)!="http://") && (ffile.slice(0,1)!="/")){
		if(Type=="swf"){
			$('flash').movie=server+ffile;
			loaded();
		}
		if(Type=="htm")	igame.location=server+ffile+"?width="+width+"&height="+height+"&loadingbar=1";
	}
}
function makeFlashPlayer(src, id, width, height){
	var wmode="window";
	if(navigator.userAgent.indexOf("Firefox")>0) wmode='opaque';
	if(typeof(anw)=="undefined") anw=0;
	var allownetworking=(anw==1)?"internal":"all";
	var allowscriptaccess=(anw==1)?"sameDomain":"always";
	if(typeof(fv)!="undefined") src=src+"?"+fv;
	document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' id='"+id+"' WIDTH='"+width+"' HEIGHT='"+height+"' allownetworking='"+allownetworking+"' allowscriptaccess='"+allowscriptaccess+"'><PARAM NAME=src VALUE='"+src+"'><param name='allowScriptAccess' value='sameDomain'><param name='base' value='.'><PARAM NAME='allowScriptAccess' VALUE='"+allowscriptaccess+"'><PARAM NAME='AllowNetworking' VALUE='"+allownetworking+"'><PARAM NAME=quality VALUE='high'><param name='wmode' value='"+wmode+"'><EMBED src='"+src+"' base='.' id='"+id+"' loop=false menu=true WIDTH="+width+" HEIGHT="+height+" TYPE='application/x-shockwave-flash' wmode='"+wmode+"' PLUGINSPAGE='=http://www.macromedia.com/shockwave/download/index.cgi?P1_Pro d_Version=ShockwaveFlash' allownetworking='"+allownetworking+"' allowscriptaccess='"+allowscriptaccess+"'></EMBED></OBJECT>");
}
function makeDcrPlayer(src, id, width, height){
	document.write('<span id="sfhelp" style="font-weight:bold;color:red;">如果这个游戏无法播放，请 <a href="/help/help.htm" target="_blank" style="color:#fff;">点这里安装插件！</a> <a href="javascript:$s(\'sfhelp\')" style="color:red">[关闭提示]</a></span><object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=11,0,0,465" width="'+width+'" height="'+height+'" id="'+id+'"><param name="src" value="'+src+'"><param name="logo" value="false"><param name="playerVersion" value="11"><param name="menu" value="false"><param name="bgColor" value="#000000"><embed src="'+src+'" id="'+id+'" logo="false" menu="false" pluginspage="http://www.macromedia.com/shockwave/download/" width="'+width+'" height="'+height+'"></embed></object>');
}
function makeIframe(src, id, width, height){
	if(typeof(fv)!="undefined") {
		src=src+"?"+fv;
	} else {
		src=(file.slice(0,20)=="/upload/gamelink.htm")?src:src+"?width="+width+"&height="+height+"&loadingbar=1";
	}
	document.write("<iframe id='"+id+"' name='igame' src='"+src+"' width='"+width+"' height='"+height+"' marginwidth=0 marginheight=0 scrolling=no border=0 frameborder=0></iframe>");	
}
function loaded(){
	if(navigator.userAgent.indexOf("Firefox")>0) return;
	tt = tt+30;
	$s('percentdiv',1);
	if(!$('flash'))return;
	Percentage=$('flash').PercentLoaded();
	if(Percentage<0)Percentage=100;
	$('bar').style.width=5*Percentage;
	$('percent').innerHTML=Percentage+'%';
	if($('flash').PercentLoaded()<100) {
		var timeout = window.setTimeout(loaded,30);
	} else {
		$s('percentdiv');
		if(tt>minlnetshowtime){
			tt = 0;
			closeloadnet();
			clearTimeout(timeout);
			setCookie('visited'+id,'yes','/');
		}else{
			var timeout = window.setTimeout(loaded,30);
		}
	}
}
function closeloadnet(){
	$('loadnet').style.display='none';
	lnetshowtime=0;
}
function play(){
	fuck();
	Type = getType();
	$('percentdiv').style.display='none';
	if(!fullplay) $('servers').innerHTML=serverdivhtml;
	switch(Type){
	case "dcr":
	case "dir":
		makeDcrPlayer(file, "flash", width, height);
		break;
	case "htm":
	case "html":
		makeIframe(file, "flash", width, height);
		break;
	default: 
  		makeFlashPlayer(file, "flash", width, height);
		break;
	}
	if(Type=='swf' && document.all) loaded();
	if(!fullplay) gamehtml=$('game').innerHTML;
	if(getCookie('visited'+id)=='yes') lnetshowtime=minlnetshowtime;
	if(file.slice(0,1)=="/") closeloadnet();
	if(file.slice(0,20)=="/upload/gamelink.htm") closeloadnet();
	if(lnetshowtime>0) window.setTimeout(closeloadnet,lnetshowtime);
	closeloadnet();
}
