/*****************************************************
MaxCms2.0
Web:http://www.bokecc.com   http://www.maxcms.net   
BBS:http://bbs.bokecc.com
2005-2009 Dreamwindows Inc. All rights reserved
Author:石头(ElapsedBloom)  2008-01-05 00:54
*****************************************************/
function PlayHistoryClass(){
	var cookieStr,nameArray,urlArray,allVideoArray;
	this.getPlayArray=function (){
		cookieStr = document.cookie;
		//alert(cookieStr)
		var start = cookieStr.indexOf("max_cms2_v=") + "max_cms2_v=".length,end = cookieStr.indexOf("_$_|",start),allCookieStr= unescape(cookieStr.substring(start,end))
		if(end==-1){allCookieStr="";return;}
		allVideoArray = allCookieStr.split("_$_");
		nameArray = new Array(),urlArray = new Array();
		for(var i = 0; i < allVideoArray.length; i++){
			var singleVideoArray = allVideoArray[i].split("^");
			nameArray[i] = singleVideoArray[0];urlArray[i] = singleVideoArray[1];
		}
	}
	this.viewPlayHistory=function (div){
		var tag = $(div),n = 16
		if(navigator.cookieEnabled){
			var innerStr = "";
			for(var i =nameArray.length - 1; i >= 0; i--){
				var textCount = nameArray[i].replace(/[^\x00-\xff]/g,"cc").length;
				if(textCount <= n*2){
					texts = nameArray[i];
				}else{
						texts = nameArray[i].substr(0,n)+"...";
				}
				innerStr += "<li><a href=\"" + urlArray[i] + "\"" + " title=\"" + nameArray[i] + "\" target=_blank>" + texts + "</a></li>"
			}
			if (innerStr.length>0){set(tag,innerStr)}
		}else{
			 set(tag,"您浏览器关闭了cookie功能，不能为您自动保存最近浏览过的网页。")
		}
	}
	this.addPlayHistory=function (name,url){
		var count = 5; //播放历史列表调用条数
		var code_name = escape(name) + "^",code_url = escape(url) + "_$_",expireTime = new Date(new Date().setDate(new Date().getDate() + 30)),timeAndPathStr = "|; expires=" + expireTime.toGMTString() + "; path=/";
		if(cookieStr.indexOf("max_cms2_v=") != -1 || cookieStr.indexOf("_$_|") != -1){
			var newCookieStr = "";
			if(allVideoArray.length < count){
				for(i in allVideoArray){
					if(nameArray[i] == name) continue;
					newCookieStr += escape(nameArray[i]) + "^" + escape(urlArray[i]) + "_$_" ;
				}
			}else{
				for(var i = 1; i < count; i++){
					if(nameArray[i] == name) continue;
					newCookieStr += escape(nameArray[i]) + "^" + escape(urlArray[i]) + "_$_" ;
				}
			}
			document.cookie = "max_cms2_v=" + newCookieStr + code_name + code_url + timeAndPathStr;
		}else{
			document.cookie = "max_cms2_v="+ code_name + code_url + timeAndPathStr;
		}
	}
}
var PlayHistoryObj=new PlayHistoryClass()
PlayHistoryObj.getPlayArray()