var file;
var ffile=file;
var islogin;
var ml;
var width = 670;
var 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.yxcity.com/upload_file/'];
servers[1]=['厦门', 'http://218.5.78.72/yxcity/'];
servers[2]=['网通', 'http://121.12.174.206:81/test/data/upload_file/yxcity/'];
servers[3]=['上海', 'http://117.135.140.57:8080/NCT/yxcity_data/yxcity/'];
servers[4]=['铁通', 'http://222.35.2.70:83/data/1/'];
var currentserver = getCookie('currentserver');
var serverid = (currentserver!=null) ? currentserver:Math.floor(Math.random()*(servers.length-1));
//var serverid = (currentserver!=null) ? currentserver:0;
var servername = servers[serverid][0];
var server     = servers[serverid][1];
var lad = "<div id='load_flash' style='background:#000;width:100%;height:450px;padding-top:0px;font-size:14px;font-weight:bold;color:#fff;'><br><br><iframe name=click src='/yxcity/load_flash.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=='yxcity.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 = document.location.href.replace("#play_start","")+"?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 delHtml(html)
{
var obj = html;
obj = obj.replace(/<\/?[^>]*>/g,''); //去除HTML tag
obj = obj.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
obj = obj.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
return obj;
	}

function urltoqq()
{
	var qq = prompt("请输入您的QQ号","");
	
	if (qq.match(/^[0-9]\d{4,10}$/))
	{
	var intro=delHtml(document.getElementById("introcontent").innerHTML);
	window.open('http://'+qq+'.qzone.qq.com/addNewBlog?content=[img]http://www.f1717.com'+pic+'[/img]%0A[url='+document.location.href+'][B]'+title+'[/B][/url][url=http://www.yxcity.com/][B]小游戏[/B][/url]%0A'+intro+'%0A[url='+document.location.href+'][ft=red,3,][点击开始游戏][/ft][/url]&title='+title+'小游戏&category=游戏城市');
	}
		else
		{
			alert("对不起!您输入的QQ号不正确");
			return false;
		}
	}
function copyToClipBoard(){
	qqtable();
document.write("<img src='/images/copyurl.gif' width='94' height='25' onclick=\"return copyurl()\" style=\"cursor:hand;\" />&nbsp;&nbsp;");
document.write("<a href='#' onclick=\"javascript:playfull();\"><img src='/images/urltoqq.gif' width='124' height='25' /></a>");

}
function Replay() {
	favorite();
	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>");
	document.write("<div id='load_ad'><script type=\"text/javascript\" src=\"/templates/ad/flash_bottom.js\"></script></div>");
}
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 + "' 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,100);  //这里是设定在加载时显示的时间长度
	} else {
		if(loadingbar) loadingbar.style.display='none';
		if(tt<1500){
			var timeout = window.setTimeout(loaded,100); //这里是设定在加载时显示的时间长度
		} else {
			tt = 0;
			clearTimeout(timeout);
			hid();
		}
	}
}
function hid(){
	//if(document.all && document.getElementById('flash').PercentLoaded()==100 && !fullplay) document.location.href="#play_site";
	if(document.getElementById('load_flash')!=null) document.getElementById('load_flash').style.display='none';
	if(document.all && document.getElementById('flash').PercentLoaded()==100 && !fullplay) document.getElementById('load_ad').style.display='block';
	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;}        
}
function play(){
	fuck();
	if(document.getElementById('percentdiv')!=null) loadingbar = document.getElementById('percentdiv');
	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 intro=delHtml(document.getElementById("introcontent").innerHTML);
		var introcontent=intro.length;
		if (introcontent > 150 )
		{
			intr=intro.slice(0,150)+"... ...";
			}else
		{
			intr=intro;
			}
		var shuqian = "<a href=\"javascript:window.open('http://shuqian.qq.com/post?from=3&title='+encodeURIComponent(document.title)+'&uri=\'+encodeURIComponent(document.location.href+'?qq')+'&jumpback=2&noui=1','favit','width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes');void(0)\"><font color=\"#fc470f\">收藏到QQ书签</font></a>&nbsp;&nbsp;<a href=\"http://cang.baidu.com/do/add?it="+title+"小游戏&iu=http://www.yxcity.com/html/"+sortid+"/"+id+"/&tn=休闲小游戏&dc="+intr+"&fr=ik#nw=1\" target=\"_blank\">百度搜藏</a>";

		if(document.getElementById('servers')!=null)
		document.getElementById('servers').innerHTML="<div class=\"help\"><a onclick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.yxcity.com/html/"+sortid+"/"+id+"/');\" href=\"#\" style=\"color:red;font-size:14px\">下次自动访问"+title+"小游戏</a></div><div class=\"right\">"+s_html+"</div>&nbsp;&nbsp;<a href=\"/help/\" target=\"_blank\"><font color=\"blue\">不能播放看这里</font></a>&nbsp;&nbsp;<a href=\"/?pt\" target=\"_blank\"><font color=\"#4C892E\">小游戏首页</font></a>&nbsp;&nbsp;"+shuqian+"</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, '680', '478');
		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_site').innerHTML;
}


//========FLASH转入QQ空间开始
function qqtable()
{
document.write('<div id="light" class="flash_qq"><table width="385" border="0" cellspacing="2" cellpadding="0"><form id="toqq" name="toqq" method="post" action="/gourl.php?action=qzone&id='+id+'" target="_blank" onsubmit="return check()"><tr><td style="height:30px; line-height:30px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>收藏<font color="#FF0000">'+title+'小游戏</font>到QQ空间</b></td></tr><tr><td height="30">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请输入你的QQ号码&nbsp;&nbsp;<input name="qq" type="text" id="qq" /></td></tr><tr><td height="20">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="Submit" value="收藏到QQ空间"/><b>&nbsp;&nbsp;[ <a href = "javascript:void(0)" onclick = "javascript:qqclose();">取消退出</a> ]</b></td></tr></form></table></div><div id="fade" class="black_qq"></div>');
}

function playfull()
{
	document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';
	}
function qqclose()
{
		document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'
}
function check()
{
	var qq=document.toqq.qq.value;
	if(qq=="")
	  {
		  alert("请您输入QQ号码");
		  return false;
		  }
	if (!qq.match(/^[0-9]\d{4,9}$/))
	{
		alert("您输入的QQ号不正确");
		return false;
     }
qqclose();
}
//======FLASH转入QQ空间结束

//function FullPlay()
//{
	//var w=document.body.clientWidth;
   // var h=document.body.clientHeight;
	//document.getElementById("flash").style.width="800";
    //document.getElementById("flash").style.height="600";
	//document.getElementById("play_site").style.width=w;
	//document.getElementById("play_site").style.height=h;
    //document.getElementById("play_site").className="flashAll";
	//document.getElementById("tools").style.display="block";
//}
function ex()
{
	document.getElementById("flash").style.width="660";
    document.getElementById("flash").style.height="440";
	document.getElementById("play_site").style.width="";
	document.getElementById("play_site").style.height="";
    document.getElementById("play_site").className="";
	document.getElementById("tools").style.display='none';
}
function sm()
{
	document.getElementById("flash").style.width="660";
    document.getElementById("flash").style.height="440";
}
function al()
{
	document.getElementById("flash").style.width="800";
    document.getElementById("flash").style.height="600";
}
function gametext()
{
	var games=document.getElementById("introcontent").innerHTML;
	alert(title+"小游戏说明:\n\n"+games);
	//document.write(games);
}
function tools()
{
		document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"  bgcolor="#FFFFFF"><tr><td width="49%" align="left" style="font-size:14px; padding-left:5px; height:30px; line-height:30px;"><b>'+title+'</b> [<a hideFocus href="javascript:gametext();" style="font-size:14px;">查看游戏说明</a>] [<a hideFocus href="javascript:Replay();" style="font-size:14px;">重新开始游戏</a>]</td><td width="51%"  style=" text-align:right"><input value="最佳画面"  id="flash_move" type="button" onclick="sm()">  <input value="最大画面"  id="all" type="button" onclick="al()">  <input value="退出全屏"  id="ex" type="button" onclick="ex()"></td></tr></table>');
}