var servers = new Array();
servers[0]=['电信服务器', 'http://flash.15175.com/'];
servers[1]=['江苏电信',	  'http://js.15175.com/medias03300220/'];
servers[2]=['广东电信',	  'http://gd.15175.com/medias03300220/'];
servers[3]=['网通服务器', 'http://cnc.15175.com/medias03300220/'];
var currentserver=getCookie('currentserver');
var currentserver=0;
if(currentserver!=null && currentserver<servers.length){
serverid=currentserver;
}else{
var randserver=Math.floor(Math.random()*100);
var serverid=0;
if(randserver>=20) serverid=1;
if(randserver>=60) serverid=2;
}
var lnetshowtime=8001;
var minlnetshowtime=5001;
var servername = servers[serverid][0];
var server     = servers[serverid][1];
setCookie('currentserver',serverid,'/');
var file;
var ffile=file;
var islogin;
var ml;
var width = 640;
var height = 480;
var tt = 0;
if(screen.width<1024){
	width = 550;
	height = 400;
}
if(typeof(pwidth)!="undefined" && typeof(pheight)!="undefined"){
	if(pwidth<661 && pwidth>0 && pheight<501 && pheight>0){
		width=pwidth;
		height=pheight;
	}
}
var Type;
var loadingbar=false;
var fullplay = false;
var gamehtml;
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 s_html="<span style='font-weight:bold;float:left;font-size:14px;padding-top:4px;'>选择服务器→</span>";
for (var i=0; i<servers.length; i++){
	if(serverid==i){
		s_html+="<a hideFocus id='s"+i+"' class='current' href='javascript:changeserver("+i+");' title='当前所在服务器'>"+servers[i][0]+"</a>";
	} else {
		s_html+="<a hideFocus id='s"+i+"' href='javascript:changeserver("+i+");'>"+servers[i][0]+"</a>";
	}
}
var serverdivhtml=sleft+sright+"<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=='yx8.cn')?'':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 = document.location.href.replace("#best","")+"?f";
	window.external.AddFavorite(pageurl, title+' - 游戏吧小游戏');
}
function copyToClipBoard(){
	var clipBoardContent=document.location.href.replace('#best',''); 
	clipBoardContent+='\n这个是我很喜欢的小游戏，名字叫《' + title + '》，真诚向你推荐，希望你也会喜欢哦!';
	window.clipboardData.setData("Text",clipBoardContent);
	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(){
	if(loadingbar) loadingbar.style.display='none';
	$('game').innerHTML="<div style='background:#CCCCCC;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(file.replace(ft[0]+'?','')):"")+"&title="+encodeURIComponent(title)+"&anw="+anw,"","fullscreen");
}
function changeserver(sid){
	for (var i=0; i<servers.length; i++){
		$('s'+i).className=(sid==i)?'current':'';
	}
	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+"&anw="+anw;
	}
	setCookie('currentserver', sid, '/');
}
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=9,0,0,0' id='"+id+"' WIDTH='"+width+"' HEIGHT='"+height+"' allownetworking='"+allownetworking+"' allowscriptaccess='"+allowscriptaccess+"'><PARAM NAME=src VALUE='"+src+"'><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(anw)=="undefined") anw=0;
	if(typeof(fv)!="undefined") {
		src=src+"?"+fv;
	} else {
		src=(file.slice(0,13)=="/gamelink.htm")?src:src+"?width="+width+"&height="+height+"&anw="+anw;
	}
	document.write("<iframe name='igame' id='"+id+"' 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) || (navigator.userAgent.indexOf("Chrome")>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');
		tt = 0;
		clearTimeout(timeout);
		setCookie('visited'+id,'yes','/');
	}
}
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') loaded();
	if(!fullplay) gamehtml=$('game').innerHTML;
	if(getCookie('visited'+id)=='yes') lnetshowtime=minlnetshowtime;
	if(file.slice(0,1)=="/") closeloadnet();
	if(file.slice(0,13)=="/gamelink.htm") closeloadnet();
	if((navigator.userAgent.indexOf("Firefox")>0) || (navigator.userAgent.indexOf("Chrome")>0)) closeloadnet();
	if(lnetshowtime>0) window.setTimeout(closeloadnet,lnetshowtime);
}
