
var pocoZinePlayer = {
	_lastVersion : "20060720",
	debug : false,
	_zinePlayer : null,
	_flashPlayer : null,
	_installed : false,
	loadingSwf	: "http://read.poco.cn/images/pz_loading.swf",//"http://www.poco.cn/download/loading.swf",
	installSwf	: "http://www1.poco.cn/order/web/swf/download.swf",
	playZineUrl : "",
	version : "",
	_ie_flag : true,
	_att : new Array(),
	_flash8Installed : false,

	setAttribute : function(name, value){
		this[name] = value;
		var is_set = false;
		for(i=0; i<this._att.length; i++){
			if(this._att[i]==name){
				is_set = true;
			}
		}
		if(!is_set){
			//this._att.push(name);
			this._att[this._att.length] = name;
		}
	},
	init : function(isFull){
		/*
		if(navigator.userAgent.indexOf('MSIE')<0){
			alert("为了能正常阅读杂志,请使用Internet Explorer浏览器浏览");
			return;
		}
		*/
		var full = (isFull==null) ? false : isFull;
		var flashVer = 0;
		this._flash8Installed = true;
		/*
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			flashVer = flash.flashVersion().toString(16).substr(0,1);
			flash = null;
		}catch(e){}
		if(flashVer>=8){
			this._flash8Installed = true;
		}else{
			this._flash8Installed = false;
			return;
		}*/
		document.write('<div id="____PocoZinePlayerDiv">');
		document.write('<object id="____PocoZinePlayer" classid="clsid:eb1ff50f-908f-4c25-8c41-bc8f660db089" width="0" height="0"></object>');
		if(full){
			document.write('<object id="____flashplayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" style="display:none"></object>');
		}
		/*
		if(this.debug){
			document.write('<p id="____PocoZinePlayerInfo"></p><p id="____PocoZinePlayerVersion"></p>');
		}*/
		document.write('</div>');
		this._zinePlayer = document.getElementById("____PocoZinePlayer");
		this._flashPlayer = document.getElementById("____FlashPlayer");
		this._installed = this._zinePlayer.GetVersion ? true : false;
		if(this._installed){
			/*
			if(this.debug){
				document.getElementById("____PocoZinePlayerVersion").innerHTML = "插件版本号:"+this._zinePlayer.GetVersion();
			}*/
			this.version = this._zinePlayer.GetVersion();
			var thisObj = this;
			this._zinePlayer.attachEvent("Flash_FSCommand", function(command,args){thisObj._flash_fscommand(command,args)});
		}/*else{
			this._flashPlayer.style.display = "block";
			this._flashPlayer.width		= "100%";
			this._flashPlayer.height	= "100%";
			this._flashPlayer.Movie		= this.installSwf;
		}*/
	},
	_flash_fscommand : function(command,args){
		switch(command){
			case "setTitle":
				if(args!="setTitle"){
					document.title = args+"--插件版本号:" + this.version;
				}
				break;
			case "fullscreen":
			case "fullwindow":
				if(!this._ie_flag){
					args="false";
				}
				if(args=="true"){
					this._flashPlayer.style.display = "none";
					try{
						window.moveTo(0,0);
						window.resizeTo(screen.availWidth, screen.availHeight);
					}catch(e){}
					this._zinePlayer.width = "100%";
					this._zinePlayer.height = "100%";
					if( !(screen.width<=800 || screen.height<=600) && document.body.offsetHeight<=650 ){
						this._flash_fscommand("fullscreen", "false");
						this._ie_flag = false;
						return;
					}
					if(screen.width<=800 || screen.height<=600 || document.body.offsetHeight<=650 ){
						this._zinePlayer.height = screen.height;
					}
					else{
						this._zinePlayer.height = document.body.offsetHeight;	
					}
				}
				else if(args=="false"){
					if(screen.width<=800 || screen.height<=600){
						return;
					}
					var size = this._zinePlayer.GetVariable("FLASH SIZE");
					this._resizeZine(size);
				}
				break;
			case "resize":
				this._resizeZine(args);
				break;
			case "quit"://quite?
				window.close();
				break;
		}
	},
	_resizeZine : function(size){
		var pos = size.indexOf(",");
		var width = parseInt(size.substr(0,pos));
		var height = parseInt(size.substr(pos+1));

		var wWidth = width+10;
		var wHeight = height+30;
		//window.resizeTo(wWidth, wHeight);
		window.resizeBy(width-this._zinePlayer.offsetWidth,height-this._zinePlayer.offsetHeight);
		try{
			if(screen.width<=800 || screen.height<=600){
				window.moveTo(0,0);
			}else{
				window.moveTo((screen.availWidth-wWidth)/2,(screen.availHeight-wHeight)/2);
			}
		}catch(e){}
		this._zinePlayer.width = "100%";
		this._zinePlayer.height = "100%";
		if(screen.width<=800 || screen.height<=600 || (screen.height-document.body.offsetHeight)>=100 ){
			this._zinePlayer.height = height;
		}
		else{
			this._zinePlayer.height = document.body.offsetHeight;	
		}
	},
	save : function(){
		if(!this._installed){
			alert("请先安装PocoZinePlayer插件.");
			return;
		}
		this._zinePlayer.Export();
	},
	zPlay: function(zine, vol){
		var js = document.createElement("script");
		js.src = "http://read.poco.cn/js/online_zine_data/"+zine+"/"+vol+".js";
		document.body.appendChild(js);
	},
	play : function(url){
		if(navigator.userAgent.indexOf('MSIE')<0){
			alert("为了能正常阅读杂志,请使用Internet Explorer浏览");
			return;
		}
		if(!this._flash8Installed){
			if(confirm("必须安装Flash8.0及以上版本才能正常运行!是否立刻下载Flash8.0?")){
				//window.open("http://www.adobe.com/shockwave/download/triggerpages_mmcom/flash.html");
				//window.opne("http://www.poco.cn/download/flash8_update.htm");
				var a = document.createElement("a");
				a.href = "http://www.poco.cn/download/flash8_update.htm";
				a.target = "_blank";
				document.body.appendChild(a);
				a.click();
			}
			return;
		}
		if(!this._installed){
			alert("请先安装PocoZinePlayer插件再点击播放.");
			//window.open("http://read.poco.cn/download.php");
			var a = document.createElement("a");
			a.href = "http://read.poco.cn/freeservice/pocoreader.html";
			a.target = "_blank";
			document.body.appendChild(a);
			a.click();
			/*
			var player_window = window.open("http://read.poco.cn/download.php", "_zine_paly");
			player_window.focus();
			*/
			//window.top.location.href = "http://read.poco.cn/download.php";
			return;
		}
		if(this._zinePlayer.GetVersion() < parseInt(this._lastVersion) ){
			this._zinePlayer.LiveUpdate("",this._lastVersion);
			return;
		}
		this.setAttribute("playZineUrl", url);
		var args = "";
		for(i=0; i<this._att.length; i++){
			args += this._att[i]+"="+this[this._att[i]]+"&";
		}
		if(args.length>0){
			args = args.substr(0, args.length-1);
		}
		args = escape(args);

		var width = 800;
		var height = 600;
		var top = (screen.availHeight-height)/2;
		var left = (screen.availWidth-width)/2;
		var windowArg = "left="+left+",top="+top+",width="+width+",height="+height;
		windowArg += "toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no";
		var player_window = window.open("http://read.poco.cn/js/zine_player.htm?"+args, "_zine_play", windowArg);
		player_window.focus();
		//var pzurl='var player_window=window.open("http://read.poco.cn/js/zine_player.htm?'+args+'", "_zine_play", "'+windowArg+'");';
		//window.showModelessDialog('http://read.poco.cn/js/player.htm?'+pzurl,'windlg','status:true;dialogWidth:300px;dialogHeight:300px;help:no;scroll:no;status:no;resizable:no;dialogLeft:'+(parseInt(screen.width)-300)/2+';dialogTop:101;');

		//this.wPlay();
	},
	wPlay : function(){
		if(!this._flash8Installed){
			if(confirm("必须安装Flash8.0及以上版本才能正常运行!是否立刻下载Flash8.0?")){
				//window.open("http://www.adobe.com/shockwave/download/triggerpages_mmcom/flash.html");
				//window.open("http://www.poco.cn/download/flash8_update.htm");
				var a = document.createElement("a");
				a.href = "http://www.poco.cn/download/flash8_update.htm";
				a.target = "_blank";
				document.body.appendChild(a);
				a.click();
			}
			return;
		}
		if(!this._installed){
			alert("请先安装PocoZinePlayer插件再点击播放");
			var a = document.createElement("a");
			a.href = "http://read.poco.cn/freeservice/pocoreader.html";
			a.target = "_blank";
			document.body.appendChild(a);
			a.click();
			return;
		}
		var thisObj = this;
		setInterval(function(){
						if(screen.availHeight-document.body.offsetHeight<60){
							thisObj._flashPlayer.height = document.body.offsetHeight;
							thisObj._zinePlayer.height = document.body.offsetHeight;
						}
					},1000);
		var width = 800;
		var height = 600;

		try{
			window.resizeTo(width, height);
			window.moveTo((screen.availWidth-width)/2,(screen.availHeight-height)/2);
			if(screen.width<=800 || screen.height<=600){
				window.moveTo(0,0);
			}
		}catch(e){}

		this._zinePlayer.style.display = "block";
		this._zinePlayer.UrlPlay(this.playZineUrl);
		this._flashPlayer.style.display = "block";
		this._flashPlayer.width		= "100%";
		this._flashPlayer.height	= "100%";
		this._flashPlayer.width	 = document.body.offsetWidth;
		this._flashPlayer.height = document.body.offsetHeight-2;
		this._flashPlayer.Movie = this.loadingSwf;

		if(this.debug){
			var debugWin = window.open("about:blank", "_blank", "width=580,height=180,left=0,top=0,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
			//debugWin.document.title = "调试窗口";
			//debugWin.document.body.style.fontSize = "14px";
			setInterval(function(){
							//document.getElementById("____PocoZinePlayerInfo").innerHTML = thisObj._zinePlayer.GetVariable("TRANSFER INFOMATION");
							debugWin.document.body.innerHTML = thisObj._zinePlayer.GetVariable("TRANSFER INFOMATION");
						},1000);
		}
	}
}

//Flash调用获得进度
function returnPercent() 
{
	var pre = pocoZinePlayer._zinePlayer.GetVariable("PRELOADING");
	return pre;
}
//setInterval(returnPercent, 1000);