var $MH={
	limit: 5,
	width:960,
	height: 170,
	setCookie: function(name, value) {
		var Days = 365;
		var exp = new Date;
		exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
		document.cookie = name + ("=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/;");
	},
	getCookie: function(name) {
		var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
		if (arr != null) {
			return unescape(arr[2]);
		}
		return null;
	},
	getDc: function(){
		var x,y=document.getElementById('MAX_HISTORY');
		return y;
	},
	WriteHistoryBox: function(w,h,c){
		//document.write('<div id="MAX_HISTORY" class="'+c+'"></div>');
		//$MH.height=h;
		this.showHistory();
	},
	showHistory: function(ac) {
		var a = $MH.getCookie("MAX_HISTORY"),dc=$MH.getDc(), c = 1;
		var ishistory = $MH.getCookie("ishistory");
		if(ishistory == null){
			$MH.setCookie("ishistory", 1);
			ishistory = 1;
		}
		var i, tmp_s;
		var img_li = "";
		//if(!dc) return;
		if (ac == 1) {
			if (ishistory != 1) {
				$MH.setCookie("ishistory", 1);
				ishistory = 1;
			} else {
				$MH.setCookie("ishistory", 0);
				ishistory = 0;
			}
		}
		if (ac == 2) {
			ishistory = 0;
			$MH.setCookie("ishistory", 0);
			$MH.setCookie("MAX_HISTORY", 'null');
		}
		
		if(ishistory == 1){
			a = (a !='' && ''+a != 'null') ? eval('('+ a +')')  : {video:[]} ;
			for(var i=0;i<a.video.length;i++){
				if(i>=5){break;}
				if(a.video[i].link && a.video[i].pic && a.video[i].name){
				//img_li += "<li style=\"width:86px;text-align:center;margin:3px 0 3px 9px !important;float:left;overflow:hidden\"><a href=\"" + a.video[i].link + "\" target=\"_self\">"+a.video[i].name+"</a>"
				img_li +="<a href='"+a.video[i].link+"' target='_blank'>"+a.video[i].name+"</a>  "
					c++;
				}
			}
			//img_li = img_li != "" ? img_li : '<li style="width:100%;text-align:center;line-height:'+($MH.height-40)+'px;color:red"></li>';
			img_li = img_li != "" ? img_li : "";
			//dc.innerHTML = "<div id=\"new\" style=\"border:1px solid #ccc;height:"+$MH.height+"px;overflow:hidden\"><div class=\"title\"><div class=\"more\" style=\"float:right;margin-right:5px;\"><a href=\"javascript:void(0)\" onClick=\"$MH.showHistory(2);\">\u6E05\u7A7A</a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:void(0)\" onClick=\"$MH.showHistory(1);\">\u9690\u85CF</a></div><b style=\"padding-left:5px;font-size:14px\">\u6211\u7684\u89C2\u770B\u5386\u53F2</b></div><div class=\"c bor\"><ul>" + img_li + "</ul></div><div style=\"clear:both\"></div></div>";
			//dc.style.display = "";
			document.write(img_li);
		} else {
			document.write(img_li);
			//dc.innerHTML = "";
			//dc.style.display = "none";
		}
	},
	recordHistory: function(video){
		if(video.link.indexOf('http://')==-1 || !window.max_Player_File) return;
		var a = $MH.getCookie('MAX_HISTORY'), b = new Array(), c = 1;
		if(a !='' && a != null && a != 'null'){
			a = eval('('+ a +')');
			for(var i=0;i<a.video.length;i++){
				if(c>$MH.limit){break;}
				if(video.link != a.video[i].link && a.video[i].pic){b.push('{"name":"'+ a.video[i].name +'","link":"'+ a.video[i].link +'","pic":"'+ a.video[i].pic +'"}');c++;}
			}
		}
		b.unshift('{"name":"'+ video.name +'","link":"'+ video.link +'","pic":"'+ video.pic +'"}');
		$MH.setCookie("MAX_HISTORY",'{video:['+ b.join(",") +']}');
		b = null;
		a=null;
	}
}