﻿document.write("<img id='hz_videofm_img' name='hz_videofm_img' width=0 height=0 border=0>");
document.write("<div id='hz_videofm_video' style='position:fixed; right:1px; bottom:1px; width:300px; height:245px; z-index:1001; border:1px solid #666;background:#fff;visibility:hidden;'><div  id='hz_videofm_video_box' style='position:absolute; right:0px; white-space:no-wrap; word-break:keep-all;'></div><div id='hz_videofm_cover' style='text-align:right;position:absolute;width:100%;z-index:1002;height:0;width:0;cursor:pointer;background:#fff;opacity:0;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);' onclick='if(typeof(hz_click_url)!=\"undefined\")window.open(hz_click_url);'></div><div style='text-align:right;position:absolute;width:100%;z-index:1003;'><img id='hz_videofm_close' src='http://sina.reliad.com.cn/gateway/static/close.gif' title='关闭' style='margin:2px;cursor:pointer;z-index:1003;' /></div></div>");

function flashPopup(flashUrl, logUrl, clickUrl, adID, width, height) {
	var hz_count_limit = 50;
	var hz_count_limit_cur = 0;
	var hz_view_limit = 50;
	var hz_logMilliseconds = 5000;//view超过5000ms log
	var hz_flash_player_button_width = "55";
	var countCookie = "reliad_" + adID + "_count", showCookie = "reliad_" + adID + "_show_count";
	var logPlayTimer;

	var sbrowser = navigator.userAgent;
	var isIE=false,isIE6 = false,isMoz = false,isSafa = false;
	if (sbrowser.indexOf("Safari") > -1 && sbrowser.indexOf("Chrome") == -1) {
		isSafa = true;
	}
	else if (sbrowser.indexOf("Mozilla") > -1 && sbrowser.indexOf("Gecko") > -1) {
		var reMoz = new RegExp("rv:(([0-9]+.[0-9]+)(?:.[0-9]+)?)");
		reMoz.test(sbrowser);
		if (RegExp["$2"] == '1.8') isMoz = true;
	}
	if (sbrowser.indexOf("MSIE") > -1) {
		isIE = true;
		if (sbrowser.indexOf("MSIE 6.0") > -1) {
			isIE6 = true;
		}
	}

	function hz_show_flash() {
		var flashStr = "";
		flashStr += '<OBJECT id="VideoPlayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" WIDTH="' + width + '" HEIGHT="' + height + '" ALIGN="">';
		flashStr += '<PARAM NAME="movie" VALUE="' + flashUrl + '">';
		flashStr += '<PARAM NAME="quality" VALUE="high">';
		flashStr += '<PARAM NAME="loop" VALUE="false">';
		flashStr += '<PARAM NAME="wmode" VALUE="transparent">';
		flashStr += '<PARAM NAME="allowscriptaccess" VALUE="always">';
		flashStr += '<PARAM NAME="bgcolor" VALUE="#FFFFFF">';
		flashStr += '<EMBED id="VideoPlayer" src="' + flashUrl + '" swLiveConnect="true" quality="high" loop="false" allowscriptaccess="always" wmode="transparent" bgcolor="#FFFFFF" WIDTH="' + width + '" HEIGHT="' + height + '" NAME="videofm" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>';
		flashStr += '</OBJECT>';

		if (clickUrl.indexOf("&url=&") == -1) {//has click url
			var cover = document.getElementById("hz_videofm_cover");
			cover.style.width = width + "px"; cover.style.height = height + "px";
			window.hz_click_url = clickUrl;
		}

		var box = document.getElementById("hz_videofm_video");
		box.style.width = (width + 2) + "px"; box.style.height = (height + 2) + "px";
		
		if (isIE6) {
			box.innerHTML += '<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);z-index:-1;"></iframe>';
		}
		if (isIE) {
			box.style.position = "absolute"; box.style.top = "10"; box.style.left = "10";
		}

		document.getElementById("hz_videofm_video_box").innerHTML = flashStr;
		
		document.getElementById("hz_videofm_close").onclick = function() {
			log("close");
			if (logPlayTimer) {
				window.clearTimeout(logPlayTimer);
				logPlayTimer = null;
			}
		};

		logPlayTimer = window.setTimeout(function() {
			log("open");
		}, hz_logMilliseconds);

		if (isIE) {
			hz_videofmResize();
			if (window.addEventListener) {
				window.addEventListener('resize', hz_videofmResize, false);
				window.addEventListener('scroll', hz_videofmResize, false);
			}
			else if (window.attachEvent) {
				window.attachEvent('onresize', hz_videofmResize);
				window.attachEvent('onscroll', hz_videofmResize);
			}
		}
		box.style.visibility = "visible";
	}

	function hz_videofmResize() {
		var box = document.getElementById("hz_videofm_video");
		if (!box) {
			return;
		}

		var hz_divHeight = box.offsetHeight;
		var hz_divWidth = box.offsetWidth;
		var hz_docWidth = 0;
		var hz_docHeight = 0;
		var hz_scrollLeft = 0;
		var hz_scrollTop = 0;

		if (window.pageXOffset) {
			hz_scrollLeft = window.pageXOffset;
		}
		else if (document.documentElement && document.documentElement.scrollLeft) {
			hz_scrollLeft = document.documentElement.scrollLeft;
		}
		else if (document.body) {
			hz_scrollLeft = document.body.scrollLeft;
		}

		if (window.pageYOffset) {
			hz_scrollTop = window.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop) {
			hz_scrollTop = document.documentElement.scrollTop;
		}
		else if (document.body) {
			hz_scrollTop = document.body.scrollTop;
		}

		if (window.innerWidth) {
			hz_docWidth = parseInt(window.innerWidth) - 17;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
			hz_docWidth = document.documentElement.clientWidth;
		}
		else if (document.body) {
			hz_docWidth = document.body.clientWidth;
		}

		if (window.innerHeight) {
			hz_docHeight = parseInt(window.innerHeight);
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			hz_docHeight = document.documentElement.clientHeight;
		}
		else if (document.body) {
			hz_docHeight = document.body.clientHeight;
		}

		var top = parseInt(hz_docHeight) - parseInt(hz_divHeight) + parseInt(hz_scrollTop) -1 ;
		var left = parseInt(hz_docWidth) - parseInt(hz_divWidth) + parseInt(hz_scrollLeft) -1;
		if (top < 0) {
			top = 0;
		}
		if (left < 0) {
			left = 0;
		}
		box.style.top = top + "px";
		box.style.left = left + "px";
		box.style.visibility = "visible";
	}

	function hz_videofmMoveLeft() {
		var hz_divLefts = parseInt(document.getElementById("hz_videofm_video").style.left);

		document.getElementById("hz_videofm_video").style.left = (hz_divLefts - parseInt(width)) + "px";
		document.getElementById("hz_videofm_video").style.width = width + "px";
	}

	function hz_videofmMoveRight() {
		var hz_divLefts = parseInt(document.getElementById("hz_videofm_video").style.left);

		document.getElementById("hz_videofm_video").style.left = (hz_divLefts + parseInt(width) - parseInt(hz_flash_player_button_width)) + "px";
		document.getElementById("hz_videofm_video").style.width = hz_flash_player_button_width + "px";
		hz_videofmResize();

	}

	function log(command, value) {
		function tracker(s) {
			if (!document.getElementById("hz_videofm_img")) {
				return;
			}
			if (hz_count_limit_cur <= hz_count_limit) {
				document.getElementById("hz_videofm_img").src = s;
			}
		}

		if (command == "open") {
			hz_count_limit_cur++;
			tracker(logUrl + "&ac=open");
		}
		else if (command == "close") {
			document.getElementById('hz_videofm_video').style.display = "none";
			document.getElementById('hz_videofm_video').innerHTML = "";
		}

		return 1;
	}
	//cookie控制
	function getCookie(name) {
		var start = document.cookie.indexOf(name + "=");
		var len = start + name.length + 1;
		if ((!start) && (name != document.cookie.substring(0, name.length))) {

			return null;
		}
		if (start == -1) return null;
		var end = document.cookie.indexOf(";", len);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	}

	function setCookie(name, value, expires, path, secure) {
		// set time, it's in milliseconds
		document.cookie = name + "=" + escape(value) +
	((expires) ? ";expires=" + expires.toGMTString() : "") + //expires.toGMTString()
	((path) ? ";path=" + path : "") +
	((secure) ? ";secure" : "");
	}

	var tdate = new Date();
	tdate.setHours(tdate.getHours() + 24);

	var show_tdate = new Date();
	show_tdate.setMinutes(show_tdate.getMinutes() + 0);


	var yoyi_focus_flv_count = getCookie(countCookie);
	if (yoyi_focus_flv_count == null) {
		setCookie(countCookie, "0", tdate, "/", "");
	}
	else {
		yoyi_focus_flv_count = Number(yoyi_focus_flv_count) + 1;
		setCookie(countCookie, yoyi_focus_flv_count, tdate, "/", "");
	}

	yoyi_focus_flv_count = getCookie(countCookie);

	var yoyi_focus_show_count = getCookie(showCookie);
	if (yoyi_focus_show_count == null) {
		setCookie(showCookie, "1", show_tdate, "/", "");
	}

	if ((hz_view_limit <= 0 || yoyi_focus_flv_count < hz_view_limit) && yoyi_focus_show_count == null) {
		if (isSafa == false) {
			window.setTimeout( hz_show_flash,3000 );
		}
	}
}
