﻿//detect plugin
var detectableWithVB = false;
var pluginFound = false;
function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    return pluginFound;
}
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');
	document.writeln('</scr' + 'ipt>');
}
function detectPlugin() {
    var daPlugins = detectPlugin.arguments;
    var pluginFound = false;
    if (navigator.plugins && navigator.plugins.length > 0) {
		var pluginsArrayLength = navigator.plugins.length;
		for (var pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
		    var numFound = 0;
		    for(var namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
				if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
				    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
				    numFound++;
				}   
		    }
		    if(numFound == daPlugins.length) {pluginFound = true;break;}
		}
    }
    return pluginFound;
}
function RePlay(){location.href = document.URL;}
//createflash
var QP = new Object();
QP.drawIframe = function (p_Src, p_id, p_width, p_height){
	return "<iframe src=\""+p_Src+"\" frameborder=\"0\" name=\""+p_id+"\" id=\""+p_id+"\" height=\""+p_height+"\" width=\""+p_width+"\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" border=\"0\"></iframe>";
};
QP.drawSWF = function (p_Src, p_Var, p_id, p_width, p_height, p_script, p_net){
	var str='<object id="'+p_id+'" width="'+p_width+'" height="'+p_height+'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"><param name="movie" value="'+p_Src+'"/><param name="flashvars" value="'+p_Var+'"/><param name="quality" value="high"/><param name="bgcolor" value="#000"/>';
	if(p_script==1){str+='<param name="allowScriptAccess" value="always"/>';}
	if(p_net==0){str+='<param name="allowNetworking" value="internal"/>';}
	str+='<embed id="'+p_id+'_em" name="'+p_id+'" width="'+p_width+'" height="'+p_height+'" src="'+p_Src+'" flashvars="'+p_Var+'"';
	if(p_script==1){str+=' allowScriptAccess="always"';}
	if(p_net==0){str+=' allowNetworking="internal"';}
	str+=' quality="high" bgcolor="#000" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" /></object>';
	return str;
};
QP.drawDCR = function(p_Src, p_id, p_width, p_height){
	var str = "";
	if(detectFlash()){
		str = '<object id="'+p_id+'" width="'+p_width+'" height="'+p_height+'" classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=10,0,0,0"><param name="background" value="#000"><param name="swStretchStyle" value="fill"><param name="logo" value="false"><param name="menu" value="false"><param name="src" value="'+p_Src+'"><embed id="'+p_id+'_em" name="'+p_id+'" src="'+p_Src+'" background="#000" logo="false" menu="false" width="'+p_width+'" height="'+p_height+'" pluginspage="http://www.macromedia.com/shockwave/download/"></embed></object>';
	}
	else{
		str = '<div><iframe src="http://www.7k7k.com/scripts/shockwaveplayer.html" height="120" width="450" marginheight="0" marginwidth="0" scrolling="no" frameborder="0"></iframe></div>';
	}
	return str;
}
QP.drawXAP = function(p_Src, p_id, p_width, p_height){
	var str='<object id="'+p_id+'" width="'+p_width+'" height="'+p_height+'" data="data:application/x-silverlight," type="application/x-silverlight-2-b2"><param name="source" value="'+p_Src+'"/><param name="onerror" value="onSilverlightError" /><param name="background" value="black" /><a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;"><img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/></a></object>';
	return str;
}
//变量调节
var _v,_w,_h,_p,_e;//变量,宽,高,路径,扩展名
var _playmode=_gamemark.split('|')[0];
var _playscript=_gamemark.split('|')[1];
var _playnet=_gamemark.split('|')[2];
var _loadad = false
//if(_gamemark.split('|')[6] == 1) _loadad = false;
var _fw = 640;
var _fh = 480;
if(_gamewidth==0){_gamewidth=550;}
if(_gameheight==0){_gameheight=400;}
_w = _gamewidth;
_h = _gameheight;
_v = _gamevar;
_p = _gamepath;
//server
function readcookie(name){var cookieValue = "";var search = name + "=";if(document.cookie.length > 0){offset = document.cookie.indexOf(search);if (offset != -1){offset += search.length;end = document.cookie.indexOf(";", offset);if (end == -1) end = document.cookie.length;cookieValue = unescape(document.cookie.substring(offset, end));}}return cookieValue;};
function setcookie(name,value,expirehours){var expiration = new Date((new Date()).getTime() +expirehours*3600000);document.cookie = name+ "=" + value + ";expires=" + expiration.toGMTString()+";domain=www.7k7k.com;path=/;";};
if(_gamemark.split('|')[5]==0 && _p.indexOf('http://flash.7k7k.com/')>=0){
	var _serv = readcookie('server');
	if(_serv==""){
		_serv = Math.floor(Math.random()*5)+1;
		setcookie('server',_serv,24*7);
	}
	_p = _p.replace('flash.7k7k.com','flash'+_serv+'.7k7k.com');
}
//
_e = _p.replace(/^(.+?)(\.([^\.\?]+?))(\?.+?)?$/g, "$2");
if(_e == '.swf'){
	_playmode = 1;
}else if(_e == '.dcr'){
	_playmode = 2;
}else if(_e == '.xap'){
	_playmode = 3;
}else if(_e == '.htm' || _e == '.html'){
	_playmode = 4;
}else{
	_playmode = 0;
}
//函数
QP.drawA = function(){
	return '<iframe src="/scripts/v2/loading.htm" height="400" width="550" marginheight="0" marginwidth="0" scrolling="no" frameborder="0"></iframe><div style="height:17px;color:#0f0;font-size:14px;margin-top:3px;">游戏加载中，请稍后......</div>';
}
QP.Player = function(w,h,$){
	var str = new Array();
	switch(_playmode){
		case 1 :
			str.push(QP.drawSWF(_p, _v, "gameobj", "100%", "100%", _playscript, _playnet));
			break;
		case 2 :
			str.push(QP.drawDCR(_p, "gameobj",  "100%", "100%"));break;
		case 3 :
			str.push(QP.drawXAP(_p, "gameobj",  "100%", "100%"));break;
		case 4 :
			str.push(QP.drawIframe(_p + '?w='+w+'&h='+h+'&v='+ _v, "gameobj", w, h));break;
		default :
			str.push('<div style="height:50px;background:color:#000;"><a href="'+ _p +'" target="_blank" style="#fff">下载该文件</a></div>');break;
	}
	if($) document.getElementById("wait").innerHTML = QP.drawA();
	document.getElementById("play").innerHTML =  str.join("");
};
QP.Replay = function(){
	document.getElementById("play").innerHTML = document.getElementById("play").innerHTML;
};
var player = function(){
	var $ = function(id){return id ? document.getElementById(id) : null;},
	consts = {"referW" : 932, "plusW" : 38, "plusH" : 120, "leftW" : 640, "rightW" : 292, "rplusH" : 17, "zoom" : 150},
	div = {"bgswf" : $("bgswf"), "container" : $("container"), "leftBox" : $("left_box"), "rightBox" : $("right_box"), "playBox" : $("play_box"), "play" : $("play")},
	swf = {"w" : _gamewidth,"h" : _gameheight, "mode" : _playmode},
	iswait = _loadad,
	waittime = 0,
	waitout = null,
	wmode = 0,
	get_scrheight = function(){
		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;}
	},
	get_realsize = function(o){return{"w":o.clientWidth,"h":o.clientHeight};},
	get_wishsize = function(o, d){
		var cur = get_realsize(o);
		return swf.w > swf.h ? {"w": cur.w + consts.zoom*d, "h": Math.floor((cur.w + consts.zoom*d) * swf.h/swf.w)} : {"w": Math.floor((cur.h + consts.zoom*d)*swf.w/swf.h), "h": cur.h + consts.zoom*d};
	},
	get_sizebasewidth = function(w){return {"w":w,"h":Math.floor(w*(swf.h/swf.w))};},
	set_size = function(size, o){o.style.width = size.w + "px";if(size.h) o.style.height = size.h + "px";},
	set_nmode = function(size){
		var bgh = size.h < 480 ? 480 : size.h;
		set_size({"w":parseInt(consts.referW + consts.plusW), "h":parseInt(bgh + consts.plusH)}, div.bgswf);
		window.document.swf1.style.height = parseInt(bgh + consts.plusH) + "px";
		set_size({"w":consts.referW, "h":bgh}, div.container);
		set_size({"w":parseInt(consts.referW - consts.rightW), "h":bgh}, div.leftBox);
		if(size.w > parseInt(consts.referW - consts.rightW)){
			size = get_sizebasewidth(parseInt(consts.referW - consts.rightW));
		}
		$("slide_game").style.display = "block";
		div.rightBox.style.height = size.h < 480 ? "463px" : parseInt(size.h - consts.rplusH) + "px";
		div.rightBox.style.display = "block";
		if(!iswait){
			set_size(size, div.playBox);
		}
		else{
			set_size({"w":550,"h":420}, div.playBox);
		}
		set_size(size, div.play);
		wmode = 0;
	},
	set_wmode = function(size){
		var bgh = size.h < 480 ? 480 : size.h;
		$("slide_game").style.display = "none";
		div.rightBox.style.display = "none";
		if(size.w <= consts.referW){
			set_size({"w":parseInt(consts.referW + consts.plusW), "h":parseInt(bgh + consts.plusH)}, div.bgswf);
			window.document.swf1.style.height = parseInt(bgh + consts.plusH) + "px";
			set_size({"w":consts.referW, "h":bgh}, div.container);
			set_size({"w":consts.referW, "h":bgh}, div.leftBox);
		}
		else{
			set_size({"w":parseInt(size.w + consts.plusW), "h":parseInt(bgh + consts.plusH)}, div.bgswf);
			window.document.swf1.style.height = parseInt(bgh + consts.plusH) + "px";
			set_size({"w":size.w, "h":bgh}, div.container);
			set_size({"w":size.w, "h":bgh}, div.leftBox);
		}
		if(!iswait){
			set_size(size, div.playBox);
		}
		else{
			set_size({"w":550,"h":420}, div.playBox);
		}
		//设置play 层
		set_size(size, div.play);
	};
	return {
		init:function(){
			if(get_scrheight() < 720){
				window.scroll(0,60);
			}
			if(swf.w > consts.leftW){
				consts.referW = parseInt(swf.w + consts.rightW);
			}
			set_nmode(swf);
			QP.Player(swf.w, swf.h, iswait);
			if(iswait) this.wait();
		},
		zoom:function(d){
			var size = get_wishsize(div.play, d);
			if(size.w*size.h < 60000 && d<0){size=null;return;}
			
			if(wmode || size.w > parseInt(consts.referW - consts.rightW)){
				set_wmode(size);
			}
			else{
				set_nmode(size);
			}
			if(swf.mode == 4){
				document.getElementById("gameobj").style.width= size.w + "px";
				document.getElementById("gameobj").style.height = size.h + "px";
				document.getElementById("gameobj").src=_p + '?w='+size.w+'&h='+size.h+'&v='+ _v;
				//QP.Player(size.w, size.h, false);
			}
		},
		setbestsize:function(){
			set_nmode({"w":swf.w, "h":swf.h});
			if(swf.mode == 4){
				document.getElementById("gameobj").style.width= swf.w + "px";
				document.getElementById("gameobj").style.height = swf.h + "px";
				document.getElementById("gameobj").src=_p + '?w='+swf.w+'&h='+swf.h+'&v='+ _v;
				//QP.Player(swf.w, swf.h, false);
			}
			if(get_scrheight() < 720){
				window.scroll(0,60);
			}
			else{
				window.scroll(0,0);
			}
		},
		wait:function(){
			var loaded = 0;
			try{loaded = window.document.gameobj.PercentLoaded();}
			catch(e){loaded = 100;}
			$("wait").style.display = "block";
			$("load").style.display = "block";
			if(loaded === 100){
				if(waittime >= 6000){
					iswait = false;
					set_size(get_realsize(div.play), div.playBox);
					clearTimeout(waitout);
					$("wait").style.display = "none";
					$("load").style.display = "none";
				}
				else{
					iswait = true;
					waittime += 300;
					var that = this;
					$("load").style.display = "none";
					waitout = setTimeout(function(){that.wait()},300);
				}
			}
			else{
				$("load").style.display = "block";
				$("bar").style.width =loaded + "%";
				$("txt").innerHTML = "Load " + loaded + "%";
				if (waittime >= 6000) {
					iswait = false;
					set_size(get_realsize(div.play), div.playBox);
					$("wait").style.display = "none";
				}
				var that = this;
				waittime += 300;
				waitout = setTimeout(function(){that.wait()},300);
			}
		}
	};
}();
player.init();
//skin
(function(){var htmlstr=[];for(var i=0;i<6;i++){htmlstr.push("<span class=\"s"+i+"\" onclick=\"setskin("+i+");\"></span>");}document.getElementById("skbtn").innerHTML = htmlstr.join("");})();
