var file;
var ffile=file;
var islogin;
var ml;
var width = 758;
var height = 528;
	//width = 618;
	//height = 435;
	width = 628;
	height = 450;
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://www.41717.com/upload_file/'];
//servers[0]=['默 认', 'http://117.25.129.168/upload_file/'];
//servers[1]=['厦 门', 'http://www.41717.com/upload_file/'];
//servers[2]=['上 海', 'http://117.135.140.57:8080/NCT/'];
//servers[3]=['网 通', 'http://117.25.129.168/upload_file/'];
var currentserver = getCookie('currentserver');
var serverid = (currentserver!=null) ? currentserver:Math.floor(Math.random()*servers.length);
var servername = servers[serverid][0];
var server     = servers[serverid][1];
var lad = "<div id='load_flash' style='padding-top:30px;height:428px;font-size:14px;font-weight:bold;color:#fff;'><a href='javascript:window.external.AddFavorite(\"http://www.guangla.com/?Favorite\", \"逛啦小游戏\")' style='text-decoration:none;'><font style='font-family:\"Verdana\", \"Arial\";color:#79E80B;font-size:18px;'>www.guangla.com</font></a>&nbsp;&nbsp;&nbsp;游戏载入中，请稍候...<br><br><iframe name=click src='/templates/js_inc/gg.htm' width='336' height='280' marginwidth=0 scrolling=no border=0 frameborder=0></iframe></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=='2144.cc')?'':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("#play","")+"?f";
	window.external.AddFavorite(pageurl, title+' - 逛啦小游戏');
}
function copyurl()
{
//var clipBoardContent=document.location.href.replace('#best',''); 
	var clipBoardContent=document.location; 
	clipBoardContent+='\n我正在玩《' + title + '》小游戏，特别好玩，你也来试试，和我比比!';
	window.clipboardData.setData("Text",clipBoardContent);
	alert("耶！复制成功喽！你可以粘贴在QQ消息里送给你的好朋友呀！再次感谢您对本站的支持哦！");
	}
function urltoqq()
{
	var qq = prompt("请输入您的QQ号","");
	
	if (qq.match(/^[0-9]\d{4,10}$/))
	{
	window.open('/go_url.php?action=qzone&id='+id+'&qq='+qq+'');
	}
		else
		{
			alert("对不起!您输入的QQ号不正确");
			return false;
		}
	}
function copyToClipBoard(){
document.write("&nbsp;<img src='/images/copyurl.gif' width='94' height='25' onclick=\"return copyurl()\" style=\"cursor:hand;\" />&nbsp;&nbsp;");
document.write("<img src='/images/urltoqq.gif' width='124' height='25' onclick=\"return urltoqq()\" style=\"cursor:hand;\" />&nbsp;");
}
function Replay() {
	if(Type=="swf" && document.all){
		document.getElementById('flash').movie=" ";
		document.getElementById('flash').movie=server+ffile;
	} else {
		document.location.reload();
	}
}
function startgame(){
	document.getElementById('play_site').innerHTML=gamehtml;
	if(Type=="swf") loaded();
}
function stopgame(){
	if(loadingbar) loadingbar.style.display='none';
	document.getElementById('play_site').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),"","fullscreen");
}
function MaxPlay() {
	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),"","");
}
function changeserver(sid){
	for (var i=0; i<servers.length; i++){
		document.getElementById('s'+i).className=(sid==i)?'current':'';
	}
	servername = servers[sid][0];
	server = servers[sid][1];
	if((ffile.slice(0,7)!="http://") && (ffile.slice(1,2)!=":")){
		if(Type=="swf"){
			document.getElementById('flash').movie=server+ffile;
			loaded();
		}
		if(Type=="htm")	igame.location=server+ffile+"?width="+width+"&height="+height;
	}
	setCookie('currentserver', sid, '/');
}
function makeFlashPlayer(src, id, width, height){
	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 + "><PARAM NAME=src VALUE='"+ src +"'><PARAM NAME=quality VALUE=\"high\"><EMBED src='" + src + "' id='" + id + "' loop=false menu=false WIDTH=" + width + " HEIGHT=" + height + " TYPE='application/x-shockwave-flash' PLUGINSPAGE='=http://www.macromedia.com/shockwave/download/index.cgi?P1_Pro d_Version=ShockwaveFlash'></EMBED></OBJECT>");
}
function makeDcrPlayer(src, id, width, height){
	document.write("<object classid=\"clsid:166B1BCA-3F9C-11CF-8075-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0\" id=\"" + id + "\" width=\"" + width + "\" height=\"" + height + "\"><param name=\"src\" VALUE=\""+ src +"\"><param name=\"swStretchStyle\" value=\"fill\">\
<param name=\"swRemote\" value=\"swSaveEnabled='true' swVolume='true' swRestart='true' swPausePlay='true' swFastForward='true' swContextMenu='true' \"><param name=\"bgColor\" value=\"#000000\"><embed src=src='" + src + "' WIDTH=" + width + " HEIGHT=" + height + " swRemote=\"swSaveEnabled='true' swVolume='true' swRestart='true' swPausePlay='true' swFastForward='true' swContextMenu='true'\" swStretchStyle=\"none\" type=\"application/x-director\" 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,13)=="/gamelink.htm")?src:src+"?width="+width+"&height="+height;
	}
	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 makeMediaPlayer(src, width, height){
	document.write("<embed src=\""+ src +"\" autostart=\"1\" showcontrol=\"1\" showdisplay=\"0\" showstatusbar=\"1\" width=\""+ width +"\" height=\""+ height +"\">\n");
}
function makeMovPlayer(src, width, height){
	document.write("<embed src=\""+ src +"\" border=\"0\" controller=\"true\" target=\"myself\" pluginspage=\"http://www.apple.com/quicktime/download/\" loop=\"FALSE\" autoplay=\"true\" width=\""+ width +"\" height=\""+ height +"\">\n");
}
var file;
function makeMp3Player(src,width, height){
	document.write("<embed src=\""+ src +"\" width=\""+ width +"\" height=\""+ height +"\" autostart=\"1\" showcontrol=\"1\" showdisplay=\"0\" showstatusbar=\"1\"></embed>\n");
}
function loaded(){
	tt = tt+30;
	if(loadingbar){
		loadingbar.style.display='';
		bg = document.getElementById('bar');
		bb = document.getElementById('percent');
	}
	if(document.getElementById('flash').PercentLoaded()<0) {
		hid();
	} else {
		if(loadingbar){
			bg.style.width=5 * document.getElementById('flash').PercentLoaded();
			bb.innerHTML=document.getElementById('flash').PercentLoaded() + '%';
		}
	}
	if(document.getElementById('flash').PercentLoaded()<100) {
		if(tt>3000) hid();
		var timeout = window.setTimeout(loaded,120);
	} else {
		if(loadingbar) loadingbar.style.display='none';
		if(tt<1500){
			var timeout = window.setTimeout(loaded,120);
		} else {
			tt = 0;
			clearTimeout(timeout);
			hid();
		}
	}
}
function hid(){
	if(document.getElementById('load_flash')!=null) document.getElementById('load_flash').style.display='none';
	sflash('s');
}
function sflash(s){
	var fs=document.getElementById('flash').style;if(s){fs.width=width;fs.height=height;}else{fs.width=fs.height=0;}
	document.getElementById('flash').style.display = '';
}
function play(){
	fuck();
	if(document.getElementById('loadingdiv')!=null) loadingbar = document.getElementById('loadingdiv');
	Type = getType();
	if(!fullplay){
		var s_html="";
		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 qqsq = "<font color=\"#fc470f\" size=\"3\"><b>   请选择最快的游戏服务器 →</b></font>";
	}

		if(document.getElementById('servers')!=null)
		document.getElementById('servers').innerHTML="<div class=\"help\"><a href=\"http:\/\/www.guangla.com\/help\/\" target=\"_blank\">无法播放？点击这里</a></div><div class=\"right\">"+s_html+"</div>&nbsp;&nbsp;<a href=\"/?pt\" target=\"_blank\"><font color=\"#4C892E\" size=\"2\">返回小游戏首页</font></a>&nbsp;&nbsp;"+qqsq+"</div><div class=\"clear\"></div>";

	if(loadingbar) loadingbar.style.display='none';
	switch(Type){
	case "dcr":
	case "dir":
		makeDcrPlayer(file, "flash", width, height);
		break;
	case "htm":
	case "html":
		makeIframe(file, "flash", width, height);
		break;
	case "mp3":
                makeMp3Player(file, '300', '70');
		break;
	case "mov":
		makeMovPlayer(file, '400', '300');
		break;
	case "wav":
	case "wmv":
	case "mpg":
	case "mpeg":
	case "asf":
		makeMediaPlayer(file, '628', '450');
		break;
	default: 
		if(document.all && ml!=false){
			if(loadingbar) loadingbar.style.display='';
			document.write(lad);
       			makeFlashPlayer(file, "flash", width, height);
			sflash();
			loaded();
		} else {
       			makeFlashPlayer("/images/1.swf", "load_flash", width, height);
       			makeFlashPlayer(file, "flash", width, height);
			document.getElementById('flash').style.display='none';
		}
		break;
	}
	if(!fullplay) gamehtml=document.getElementById('play').innerHTML;
}
