var $MH={
	id:'rendie_history',
	limit:10,
	width:960,
	height: 170,
	style: 'pic',
	page:0,
	setCookie: function(name, value) {
		var Days = 365;
		var exp = new Date;
		exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
		document.cookie = name + ("=" + (value) + ";expires=" + exp.toGMTString() + ";path=/;");
	},
	getCookie: function(name) {
		var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
		if (arr != null) {
			return (arr[2]);
		}
		return null;
	},
	getDc: function(){
		var x,y=document.getElementById($MH.id);
		return y;
	},
	piclist: function (){
		var a = $MH.getCookie($MH.id), c = 1,img_li = "";
		a = (a !='' && ''+a != 'null') ? $MH.tryjosn(a) : {video:[]};
		for(var i=0;i<a.video.length;i++){
			if(c>$MH.limit){break;}
			if(a.video[i].url && a.video[i].pic && a.video[i].name){
			img_li += "<li style=\"width:86px;height:142px;text-align:center;margin:3px 0 3px 9px !important;float:left;display:inline;overflow:hidden\"><div><a href=\"" + a.video[i].url + "\" target=\"_self\"><img width=\"86\" height=\"120\" src=\"" + a.video[i].pic + "\" alt=\"" + a.video[i].name + "\" border=\"0\"/></a></div>\
						<p style=\"margin:0;padding:0\"><a href=\"" + a.video[i].url + "\" target=\"_self\" style=\"font-size:12px;color:#000;line-height:24px;height:24px;text-decoration:none\">" + a.video[i].name + "</a></p></li>"
				c++;
			}
		}
		img_li = img_li != "" ? img_li : '<li style="width:100%;text-align:center;line-height:'+($MH.height-25)+'px;color:red">\u6CA1\u6709\u8BB0\u5F55</li>';
		return "<div id=\"mh-box\" style=\"border:1px solid #ccc;height:"+$MH.height+"px;overflow:hidden\"><div style=\"height:24px;line-height:24px\" id=\"mh-title\"><div style=\"float:right;margin-right:5px;display:inline\"><a href=\"javascript:void(0)\" onClick=\"$MH.showHistory(2);\" style=\"font-size:12px;color: #000000;line-height:24px;height:24px;text-decoration:none\">\u6E05\u7A7A</a>&nbsp;<a href=\"javascript:void(0)\" onClick=\"$MH.showHistory(1);\" style=\"font-size:12px;color: #000000;line-height:24px;height:24px;text-decoration:none\">\u9690\u85CF</a></div><strong style=\"padding-left:5px;font-size:14px\">\u6211\u7684\u89C2\u770B\u5386\u53F2</strong></div><div id=\"mh-ul\"><ul style=\"margin:0px;border:0px;padding:0\">" + img_li + "</ul><div style=\"clear:both\"></div></div></div>";
	},
	fontlist: function (){
		var a = $MH.getCookie($MH.id), c = 1,img_li = "";
		a = (a !='' && ''+a != 'null') ? $MH.tryjosn(a)  : {video:[]} ;
		for(var i=0;i<a.video.length;i++){
			if(c>$MH.limit){break;}
			if(a.video[i].url && a.video[i].pic && a.video[i].name){
			img_li += "<li style=\"list-style:none;margin:0 5px\"><small>"+c+".</small><a href=\"" + a.video[i].url + "\" target=\"_self\" style=\"font-size:12px;color:#000;text-decoration:none\">" + a.video[i].name + "</a></li>"
				c++;
			}
		}
		img_li = img_li != "" ? img_li : '<li style="width:100%;text-align:center;line-height:'+($MH.height-25)+'px;color:red;list-style:none">\u6CA1\u6709\u8BB0\u5F55</li>';
		return "<div id=\"mh-box\" style=\"border:1px solid #ccc;height:"+$MH.height+"px;overflow:hidden\"><div style=\"height:24px;line-height:24px\" id=\"mh-title\"><div style=\"float:right;margin-right:5px;display:inline\"><a href=\"javascript:void(0)\" onClick=\"$MH.showHistory(2);\" style=\"font-size:12px;color: #000000;line-height:24px;height:24px;text-decoration:none\">\u6E05\u7A7A</a>&nbsp;<a href=\"javascript:void(0)\" onClick=\"$MH.showHistory(1);\" style=\"font-size:12px;color: #000000;line-height:24px;height:24px;text-decoration:none\">\u9690\u85CF</a></div><strong style=\"padding-left:5px;font-size:14px\">\u6211\u7684\u89C2\u770B\u5386\u53F2</strong></div><div id=\"mh-ul\"><ul style=\"margin:0px;border:0px;padding:0\">" + img_li + "</ul><div style=\"clear:both\"></div></div></div>";
	},
	indexlist: function (){
		var a = $MH.getCookie($MH.id), c = 1,img_li = "";
		a = (a !='' && ''+a != 'null') ? $MH.tryjosn(a)  : {video:[]} ;
		for(var i=0;i<a.video.length;i++){
			if(c>$MH.limit){break;}
			if(a.video[i].url && a.video[i].pic && a.video[i].name){
			img_li += "<li style=\"list-style:none;margin:0 5px\"><small>"+c+".</small><a href=\"" + a.video[i].url + "\" target=\"_self\">" + a.video[i].name + "</a></li>"
				c++;
			}
		}
		img_li = img_li != "" ? img_li : '<li></li>';
		return "<ul>" + img_li + "</ul>";
	},
	playlist: function (){
		var a = $MH.getCookie($MH.id),current,img_li = "";
		a = (a !='' && ''+a != 'null') ? $MH.tryjosn(a)  : {video:[]} ;
		current=a.video.length
		if($MH.page+6<current){current=$MH.page+6;}
		for(var i=$MH.page;i<current;i++){
			if(a.video[i].url && a.video[i].pic && a.video[i].name)
			{
				img_li += "<li><p><a href='" + a.video[i].url + "' title='" + a.video[i].name + "' target='_self'>" + a.video[i].name + "</a></p></li>"
			}
		}
		img_li = img_li != "" ? img_li : '<li></li>';
		img_li = '<div class="assistant_tt"><strong>我看过的<span></span></strong><a href="javascript:void(0);"onClick="$MH.showHistory(1);" target="_self">关闭</a></div>\
				<div class="histroy_tt">\
					<span>共<strong>'+a.video.length+'</strong>条记录</span>\
					<a href="javascript:$MH.showHistory(2)" target="_self">清空记录</a>\
				</div>\
				<ul class="histroylist">'+ img_li + '</ul>\
				<div class="pageturn">\
					<span>'+eval($MH.page+1)+'-'+current+'</span>\
					<a href="javascript:" onClick="$MH.showHistory(3);" target="_self">上一页</a>|\
					<a href="javascript:" onClick="$MH.showHistory(4);" target="_self">下一页</a>\
				</div>';

		if(a.video.length<=$MH.page+6){if($MH.page-6>0)$MH.page=$MH.page-6;}
		return img_li
	},
	viewdigilist: function (){
		var a = $MH.getCookie($MH.id),current,img_li = "";
		a = (a !='' && ''+a != 'null') ? $MH.tryjosn(a)  : {video:[]} ;
		current=a.video.length
		if($MH.page+6<current){current=$MH.page+6;}
		for(var i=$MH.page;i<current;i++){
			if(a.video[i].url && a.video[i].pic && a.video[i].name)
			{
				img_li += "<div style=\"height: 10px;\"></div>\
				<div class=\"bordercss\" style=\"padding:5px;width:190px;overflow:hidden;\">\
				<center>\
				<a href=\"" + a.video[i].url + "\"><img src=\""+a.video[i].pic+"\"  class=\"catImg\"/></a>\
				<br/><br/> <a href=\"" + a.video[i].url + "\" title=\"" + a.video[i].name + "\">" + a.video[i].name + "</a>\
				</center></div>"
			}
		}
		return img_li
	},
	viewsoniclist: function (){
		var a = $MH.getCookie($MH.id),current,img_li = "";
		a = (a !='' && ''+a != 'null') ? $MH.tryjosn(a)  : {video:[]} ;
		current=a.video.length
		if($MH.page+6<current){current=$MH.page+6;}
		for(var i=$MH.page;i<current;i++){
			if(a.video[i].url && a.video[i].pic && a.video[i].name)
			{
				img_li += '<td width="66" align="center" valign="middle">\
				<table width="66" border="0" cellspacing="2">\
				<tr>\
				<td width="66" align="center" valign="middle">\
					<a target="_blank" href="'+a.video[i].url+'">\
					<img src="'+a.video[i].pic+'" width="50" class="producttime"title="'+a.video[i].name+'" /></a></td>\
				</tr>\
				<tr>\
				<td valign="middle" nowrap="nowrap"><a target="_blank" href="'+a.video[i].url+'" style="overflow:hidden;display:block;width:60px;"title="'+a.video[i].name+'">'+a.video[i].name+'</a></td>\
				</tr>\
				</table></td>'
				if((i+1)%2==0){img_li+='</tr><tr>'}
			}
		}
		img_li='<table width="190" border="0" cellspacing="0" cellpadding="0"><tr>'+img_li+'</tr></table>'
				
		return img_li
	},
	WriteHistoryBox: function(){
		this.showHistory(0);
	},
	showHistory: function(ac) {
		var a = $MH.getCookie($MH.id),dc=$MH.getDc();
		var ishistory = $MH.getCookie("ishistory");
		if(!dc) return;
		if (ac == 0){ishistory = 1;	}
		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($MH.id, 'null');
		}
		if (ac == 3){if($MH.page>4){$MH.page=$MH.page-6}}
		if (ac == 4){$MH.page=$MH.page+6}
		if(ishistory == 1){
			dc.innerHTML = $MH[$MH.style+'list']();
			dc.style.display = "";
		} else {
			dc.innerHTML = "";
			dc.style.display = "none";
		}
	},
	recordHistory: function(video){
		var a = $MH.getCookie($MH.id), b = new Array();
		if(a !='' && a != null && a != 'null'){
			a = $MH.tryjosn(a);
			for(var i=0;i<a.video.length;i++)
			{
				if(video.url != a.video[i].url && a.video[i].pic)
				{
					b.push('{"name":"'+ $MH.u8(a.video[i].name) +'","url":"'+ $MH.u8(a.video[i].url) +'","pic":"'+ $MH.u8(a.video[i].pic) +'"}');
				}
			}
		}
		b.unshift('{"name":"'+ $MH.u8(video.name) +'","url":"'+ $MH.u8(video.url) +'","pic":"'+ $MH.u8(video.pic) +'"}');
		$MH.setCookie($MH.id,'{video:['+ b.join(",") +']}');
		b = null;
		a=null;
	},
	u8: function (s){
		return unescape(escape(s).replace(/%u/ig,"\\u")).replace(/;/ig,"\\u003b");
	},
	tryjosn: function (json){
		try{
			return eval('('+ json +')');
		}catch(ig){
			return {video:[]};
		}
	}
}