(function($) {	
	$.httpData=function( r, type ) {
		var ct = r.getResponseHeader("content-type");
		var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0;
		var data = xml ? r.responseXML : r.responseText;
		if ((!$.browser.msie) && (xml))
		{
			data=new DOMParser().parseFromString(r.responseText,'text/xml');
		}
		else
		{	if ( xml && data.documentElement.tagName == "parsererror" )
				throw "parsererror";
		}

		// If the type is "script", eval it in global context
		if ( type == "script" )
			jQuery.globalEval( data );

		// Get the JavaScript object, if JSON is used.
		if ( type == "json" )
			data = eval("(" + data + ")");

		return data;
	}
	document.domain = "qq.com";	
	$.vs = new Object();
	$.vs.testpath = "http://dev.video.qq.com/new/bin";
	$.vs.domain = "http://video.qq.com";
	$.vs.path = "http://video.qq.com/v1"; 
	$.vs.static = "http://static.video.qq.com/v1";
	$.vs.vession = "v1";
	
	$.vs.VERIFY_IMG = "http://ptlogin2.qq.com/getimage?aid=3000501&";
	$.vs.ADD_QQ = "qq.com";
	$.vs.ADD_LOGIN = "http://ptlogin2.qq.com/login";
	
	String.prototype.UTF8Length = vs_str_UTF8Length;
	String.prototype.BLength = vs_str_BLength;
	String.prototype.UTF8Trunc = vs_str_UTF8Trunc;
	String.prototype.BTrunc = vs_str_BTrunc;
	String.prototype.format = vs_str_format;

	// Error Messages
	var ERR_UNKNOW="服务器忙";
	var err_xmlErrorCode = new Array();
	err_xmlErrorCode["401"]="您还没有登录，请先登录";
	err_xmlErrorCode["501"]="验证码错误";
	err_xmlErrorCode["601"]="您的操作过于频繁，请稍候再试";
	
	err_xmlErrorCode["30"]="非法的ID";
	err_xmlErrorCode["31"]="您输入的内容中含有非法字符";
	err_xmlErrorCode["21"]="长度不正确";
	err_xmlErrorCode["22"]="长度不正确";
	err_xmlErrorCode["23"]="长度不正确";
	err_xmlErrorCode["24"]="长度不正确";
	
	err_xmlErrorCode["50"]="您没有权限";
	err_xmlErrorCode["60"]="不存在的ID";
	err_xmlErrorCode["70"]="服务器忙，请稍候再试";
	
	err_xmlErrorCode["102"]="ID不存在";
	
	err_xmlErrorCode["1001"]="该用户不存在";
	err_xmlErrorCode["1002"]="该视频不存在";
	err_xmlErrorCode["1003"]="该V吧不存在";
	err_xmlErrorCode["1004"]="没有话题";
	err_xmlErrorCode["1005"]="该V吧没有话题";
	err_xmlErrorCode["1020"]="提高评论质量,请不要连续发相同的评论";
	
	
	err_xmlErrorCode["2001"]="已添加";
	err_xmlErrorCode["2002"]="该用户已经是您的好友";
	err_xmlErrorCode["2003"]="成员已满";
	err_xmlErrorCode["2004"]="该V吧已存在";
	
	err_xmlErrorCode["3000"]="生成视频ID失败，请稍候再试";
	err_xmlErrorCode["3001"]="您已经上传过该视频";
	err_xmlErrorCode["3005"]="删除视频失败";
	
	err_xmlErrorCode["3008"]="您所选择的视频分类无效，请重新选择";
	err_xmlErrorCode["3009"]="您输入的视频标题中含有不合法字符，请重新输入";
	err_xmlErrorCode["3010"]="您输入的视频标签中中含有不合法字符，请重新输入";
	err_xmlErrorCode["3011"]="您输入的视频描述中含有不合法字符，请重新输入";

	
	err_xmlErrorCode["5008"]="该视频已加入V吧";
	err_xmlErrorCode["5010"]="该V吧名已经存在，请更换一个V吧名称";
	err_xmlErrorCode["5011"]="您已没有创建V吧的名额";
	err_xmlErrorCode["100001"]="您的登录已过期，请重新登录";
	

	$.vs.xmlErrorCode=err_xmlErrorCode;
	
	$.vs.channels=new Array("所有","原创","电视剧","娱乐","搞笑","电影","音乐","自拍","广告","动物","生活","旅游","社会","动漫","校园","体育","游戏","科技","汽车","其他");
	$.vs.pinlunWarn = "注意：您的评论会经过人工审核。请不要发送色情、暴力及危害国家安全的信息。一旦发现将会永久封号！";

	$.vs.checkXml = function(xml,Rem){
		var root;
		var em;
		//var s;
		if(!(xml&&(root=xml.selectSingleNode("//root"))))
		{
			alert("格式错误");
			return false;
		}
		else if($.vs.getValue(root,"s")=="f")
		{
			em=$.vs.getValue(root,"em");
			if(err_xmlErrorCode[em])
			{
				alert(err_xmlErrorCode[em]);
			}
			else
			{
				alert(ERR_UNKNOW);
			}
			if(Rem)
			{
				return em;
			}
			return false;
		}
		else if($.vs.getValue(root,"s")=="o")
		{
			if(Rem)
			{
				return "o";
			}
			return true;
		}
		else
		{
			alert(ERR_UNKNOW);
			return false;
		}
	};
		
	$.vs.userRank = new Array("龙套仔","路人甲","替身","配角","主角","明星","编剧","制片","导演","名导");
	
	$.vs.getValue = function(node, name){
		var value = "";
		var n = node.selectSingleNode(name);
		
		if(n)
		{
			value = n.text;
		}
		
		return value;
	};

	$.vs.getSafeHTML = function(s){
		var html = "";
		var safeNode = $.safeNode;
		
		if(!safeNode)
		{
			safeNode = document.createElement("TEXTAREA");
		}
	
		if(safeNode)
		{
		 	var el = $(safeNode);
			el.text(s);
			html=el.html();
			el.text("");

			$.safeNode = safeNode;
		}
		
		return html;
	};
	
	$.vs.encodeURLValue = function(s){
		if(typeof(s) != "string")
		{
			return "";
		}
		try
		{
			if(typeof(encodeURIComponent) != "undefined")
			{
				return encodeURIComponent(s);
			}
			
			if(typeof(encodeURI) != "undefined")
			{
				return encodeURI(s).replace(/&/g, "%26").replace(/=/g, "%3D");
			}
		}
		catch(e)
		{
			return escape(s).replace(/&/g, "%26").replace(/=/g, "%3D");
		}
		return escape(s).replace(/&/g, "%26").replace(/=/g, "%3D");
	};
	
	$.vs.decodeURLValue = function(s){
		
		if(typeof(s) != "string")
		{
			return "";
		}
		try
		{
			if(typeof(decodeURIComponent) != "undefined")
			{
				return decodeURIComponent(s);
			}
			
			if(typeof(decodeURI) != "undefined")
			{
				return decodeURI(s.replace(/%3D/g, "=").replace(/%26/g, "&"));
			}
		}
		catch(e)
		{
			return unescape(s.replace(/%3D/g, "=").replace(/%26/g, "&"));
		}
		return unescape(s.replace(/%3D/g, "=").replace(/%26/g, "&"));
	};

	$.vs.query = function(q) {
		q = q || window.location.search;
		q = q.replace("/^\?/", "");
		q = q.replace("/\&$/", "");

		var ret = {};

		$.each(q.split("/&/"), function(){
			var arr = this.split("/=/");
			var key = "", val = "";
			if (arr.length > 0)	
				key = $.vs.decodeURLValue(arr[0]);
			if (arr.length > 1)
				val = $.vs.decodeURLValue(arr[1]);
			if (!ret[key])
				ret[key] = val;
		});

		return ret;
	};
	
	$.vs.parseParams = function (){
		var params = new Object();
		var s = window.location.search;
		var vArr;
		var i;
		var nameValue;
		
		if(params && typeof(s) == "string")
		{
			s = s.substr(1);
			vArr = s.split("&") || [];
			
			if(vArr)
			{
				for(i = 0; i < vArr.length; i++)
				{
					if(typeof(vArr[i]) == "string")
					{
						nameValue = vArr[i].split("=");
						if(nameValue.length > 1)
						{
							params[nameValue[0]] = $.vs.decodeURLValue(nameValue[1]);
						}
						else
						{
							params[nameValue[0]] = "";
						}
					}
				}
			}
		}
		
		return params;
	};

	$.vs.params=$.vs.parseParams();

	/// unix时间戳转换为文字描述
	$.vs.time2str = function(time) {
		var t = parseInt(time);
		var year = Math.floor((t/(24*60*60*30*12)), 10); 
		var mon = Math.floor((t/(24*60*60*30)), 10);
		var day =  Math.floor((t/(24*60*60)), 10);
		var hour = Math.floor((t/(60*60)), 10);
		var minu = Math.floor((t/60), 10);

		var str = "";
		if (year>0) 
			str = year + "年";
		else if (mon>0)
			str = mon + "个月";
		else if (day>0)
			str = day + "天";
		else if (hour>0)
			str = hour + "个小时";
		else
		{
			if(minu<1)
				minu = 1;
			str = minu + "分钟";
		}

		return str;	
	};

	/// 根据vid生成对应视频播放页面url
	$.vs.vid2url = function(vid, id) {
		var url = $.vs.path+"/videopl?v=" + vid;
		if(id) url+="&i="+id;
		return url;
	};

	$.vs.getHash = function(vid) {
		var nhash = 0;
		var uint_max = 0x00ffffffff + 1;
		var hash_bucket = 10000*10000;
		for( var inx=0; inx<vid.length; inx++) {
			var nchar = vid.charCodeAt(inx); 
			nhash = (nhash*32) + nhash + nchar;
			if( nhash >= uint_max )
			  nhash = nhash % uint_max;
		}
		return nhash % hash_bucket;
	};

	$.vs.getVideoPicUrl = function(vid, type) {
		if(!vid)
		{
			return $.vs.static+"/img/default.gif";
		}
		var st = "_1";
		if (type==1)
			st = "";
		else if (type==2)
			st = "_2";
		return "http://vpic.video.qq.com/" + $.vs.getHash(vid) + "/" + vid + st + ".jpg";
	};

	// jquery.cookie.js
	$.cookie = function(name, value, options) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			}
			var path = options.path ? '; path=' + options.path : '';
			var domain = options.domain ? '; domain=' + options.domain : '';
			var secure = options.secure ? '; secure' : '';
			if(name == "skey" || name == "skey2")
			{
				document.cookie = [name, '=', escape(value), expires, path, domain, secure].join('');
			}
			else
			{
				document.cookie = [name, '=', $.vs.encodeURLValue(value), expires, path, domain, secure].join('');
			}
		} else { // only name given, get cookie
			var cookieValue = "";
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						if(name == "skey" || name == "skey2")
						{
							cookieValue = unescape(cookie.substring(name.length + 1));
						}
						else
						{
							cookieValue =  $.vs.decodeURLValue(cookie.substring(name.length + 1));
						}
						break;
					}
				}
			}
			return cookieValue;
			
		}
	};

	$.vs.uin2pic = function(uin, refresh) {
		var t = $.cookie("ut");
		if (!t || refresh) {
			t = Math.random().toString(10).substring(2, 7);
			$.cookie("ut", t);
		}
		return "http://p.video.qq.com/i/" + uin + ".jpg?t=" + t; 
	};

	$.vs.gid2pic = function(gid, refresh) {
		var t = $.cookie("gt");
		if (!t || refresh) {
			t = Math.random().toString(10).substring(2, 7);
			$.cookie("gt", t);
		}
		return "http://p.video.qq.com/i/" + gid + ".jpg?t=" + t; 
	};

	$.vs.uin2url = function(uin) {
		return $.vs.path+"/user/userinfo?u=" + uin;
	};
	
	$.vs.key2url = function(key) {
		return $.vs.path+"/search?" + $.param({"k":key});
	};

	$.vs.gid2url = function(gid) {
		return $.vs.path+"/group?g=" + gid;
	};

	$.vs.tag2url = function(tag, flag) {
		var s = 2;
		if (tag == "c")  s = 1;
		return $.vs.path+"/search?" + $.param({"k":tag});
	};
	
	$.vs.cat2url = function(cat){
		var i=0
		for(i=0;i<$.vs.channels.length;i++)
		{
			if($.vs.channels[i]==cat)
			{
				break;
			}
		}
		if(i<$.vs.channels.length)
		{
			return $.vs.path+"/view?" + $.param({"c":i});
		}
		else
		{
			return $.vs.path+"/view";
		}
	}

	$.vs.checkUin = function(uin) { 
		var j = 0;
		while (j<uin.length) {
			var ch = uin.charAt(j);
			if( ch!='o' && ch != '0' )
				break;
			j++;
		}
		if(j < uin.length) {
			var re = new RegExp("[^0-9]", "g");
			uin = uin.substring(j, uin.length);
			if(uin.search(re) < 0 )
				return uin;
		}
		return false;
	};

	$.vs.getUserNameFromCookie = function() {
		return $.cookie("name");
	};

	$.vs.s2r = function(score) {
		if(typeof(score) == "string")
			score = parseInt(score);
		if(isNaN(score)) 
			return 0;

		for(var i=0,num=300;i<10;i++,num*=3) {
			if(score<num) return i;
		}
		return 0;
	};

	$.vs.score2rank = function(score) {
		var i = $.vs.s2r(score);
		return userRank[i];
	};

	$.vs.rank2img = function(i, el) {
		if(!el) return;

		var imgs=new Array(0,0,0);
		if(i>=9)
		{
			imgs[0]=3;
		}
		else if(i>=3)
		{
			imgs[0]=2;
			if(i>=6)
			{
				imgs[1]=2;
				if(i==7) imgs[2]=1;
				else if(i==8) imgs[2]=2;
			}
			else if(i>=4)
			{
				imgs[1]=1;
				if(i==5) imgs[2]=1;
			}
		}
		else
		{
			imgs[0]=1;
			if(i>=1)
			{
				imgs[1]=1;
				if(i==2) imgs[2]=1;
			}
		}
		
		$.each(imgs, function() {
			if (this > 0 && this <= 3)	
				$("<img src='"+$.vs.static+"/img/r" + this + ".gif' alt='"+$.vs.userRank[i]+"'/>").appendTo(el);
		});
	};

	$.fn.score2img = function(score) {
		var rank = vs_s2r(score);
		return this.each(function() {
			$.vs.rank2img(rank, this);
		});
	};

	$.vs.uscore2img = function() {
		var rank = vs_s2r(score);
		return this.each(function() {
			$.vs.rank2img(rank, this);
		});
	};
	
	$.vs.uscore2img = function(pid) {
		var pre="";
		if(pid)
		{
			pre="#"+pid+" ";
		}
		
		$(pre+".uscore").each(userScore2img);
	};
	
	function userScore2img()
	{
		var me = $(this);
		var score=me.attr("score");		
		var rank = vs_s2r(score);
		
		$.vs.rank2img(rank, this);		
	}
	
	function vs_s2r(score)
	{
		var num;
		var i=0;
		if(typeof(score)=="string")
		{
			score=parseInt(score);
		}
		if(!isNaN(score))
		{
			for(i=0,num=300;i<10;i++,num*=3)
			{
				if(score<num)
				{
					break;
				}
			}
		}
		return i;
	}
	///////////// Image and Anchor setting

	///修改这个变量的某一项可更改链接打开方式
	$.anchorTargets = {
		user	: "_blank",
		group	: "_blank",
		video	: "_blank",
		vbarpl  : "_blank",
		tag		: "_blank",
		cat		: "_blank",
		search	: "_blank"
	};

	$.vs.setAnchorTarget = function(name, target) {
		if (name == "*") {
			$.anchorTargets.user = target;
			$.anchorTargets.group = target;
			$.anchorTargets.video = target;
			$.anchorTargets.vbarpl = target;
			$.anchorTargets.tag = target;
			$.anchorTargets.cat = target;
			$.anchorTargets.search = target;
		} else {
			$.anchorTargets[name] = target;
		}
	};

	function set_img(src, err) {
		this.get(0).onerror=function(){this.onerror=null; this.src=err;};
		this.attr("src",src);
	}

	function set_link(url, type) {
		var target = $.anchorTargets[type] || "_blank";
		var text="";
		var bt=this.attr("bt");
		if(bt==1)
		{
			text=this.text();
		}
		
		if (target == "_self")
			this.attr("href", url);
		else
			this.attr({"target":target, "href":url});
			
		if(bt==1)
		{
			this.text(text);
		}
	}

	function setUserPic() {
		var $this = $(this);
		var uin = $this.attr("uin");
		var fresh=$this.attr("fresh");
		set_img.apply($this, [ $.vs.uin2pic(uin,fresh), $.vs.static+"/img/uu0.jpg"]);
	}

	function setVideoPic() {
		var $this = $(this);
		var vid = $this.attr("vid");
		var t=$this.attr("t");
		set_img.apply($this, [ $.vs.getVideoPicUrl(vid,t), $.vs.static+"/img/default.gif"]);
	}

	function setGroupPic() {
		var $this = $(this);
		var gid = $this.attr("gid");
		var vid = $this.attr("vid");
		var fresh=$this.attr("fresh");
		set_img.apply($this, [ $.vs.gid2pic(gid,fresh), $.vs.getVideoPicUrl(vid) ]);
	}

	function setUserUrl() {
		var $this = $(this);
		var uin = $this.attr("uin");
		set_link.apply($this, [$.vs.uin2url(uin), "user"]);
	}

	function setCatUrl() {
		var $this = $(this);
		var cat = $this.attr("cat");
		set_link.apply($this, [$.vs.cat2url(cat), "cat"]);
	};

	function setTagUrl() {
		var $this = $(this);
		var tag = $this.attr("tag");
		set_link.apply($this, [$.vs.tag2url(tag), "tag"]);
	};

	function setVideoUrl() {
		var $this = $(this);
		var vid = $this.attr("vid");
		var url=$.vs.path+"/videopl?v=" + vid;
		var plt=$this.attr("plt");
		
		if(plt)
		{
			url+="&plt="+plt;
		}
		set_link.apply($this, [ url, "video"]);
	}
	
	function setVbarplUrl() {
		var $this = $(this);
		var vid = $this.attr("vid");
		var gid = $this.attr("gid");
		var url = $.vs.path+"/videopl/vbar?g="+gid;
		if(vid)
		{
			url+="&v="+vid;
		}
		set_link.apply($this, [ url, "vbarpl"]);
	}

	function setGroupUrl() {
		var $this = $(this);
		var gid = $this.attr("gid");
		set_link.apply($this, [ $.vs.gid2url(gid), "group" ]);
	}


	function setSearchUrl() {
		var $this = $(this);
		var key = $this.attr("key");
		set_link.apply($this, [$.vs.key2url(key), "search"]);
	}

	$.applyPicsAndUrls = function(pid) {
		var pre="";
		if(pid)
		{
			pre="#"+pid+" ";
		}
		$(pre+"img.upic").each(setUserPic);
		$(pre+"img.vpic").each(setVideoPic);
		$(pre+"img.gpic").each(setGroupPic);

		$(pre+"a.uinfo").each(setUserUrl);
		$(pre+"a.ginfo").each(setGroupUrl);
		$(pre+"a.videopl").each(setVideoUrl);
		$(pre+"a.vbarpl").each(setVbarplUrl);
		$(pre+"a.vcat").each(setCatUrl);
		$(pre+"a.vtag").each(setTagUrl);
		$(pre+"a.gcat").each(setCatUrl);
		$(pre+"a.gtag").each(setTagUrl);
		$(pre+"a.tosh").each(setSearchUrl);
	};
	window.setTimeout('head_floatWinProcess();',400);

})(jQuery);

var vs_pgvTry = 0;
var vs_nrs_code="var _rsCI=\"cn-tencent\";var _rsCG=\"0\";var _rsDT=0;var _rsDU=0; var _rsDO=0; var _rsX6=0;  var _rsSI=escape(window.location);var _rsLP=location.protocol.indexOf('https')>-1?'https:':'http:';var _rsRP=escape(document.referrer);var _rsND=_rsLP+'//secure-cn.imrworldwide.com/';if (parseInt(navigator.appVersion)>=4){var _rsRD=(new Date()).getTime();var _rsSE=1; var _rsSV=\"\";var _rsSM=0.01;_rsCL='<scr'+'ipt language=\"JavaScript\" type=\"text/javascript\" src=\"'+_rsND+'v51.js\"><\/scr'+'ipt>'; vs_addScript(_rsND+'v51.js');}else{_rsCL='<img src=\"'+_rsND+'cgi-bin/m?ci='+_rsCI+'&cg='+_rsCG+'&si='+_rsSI+'&rp='+_rsRP+'\">';document.body.insertAdjacentHTML('beforeEnd', _rsCL);}";
function pv_init()
{
	window.setTimeout("vs_ping();", 1000);
	window.setTimeout("vs_pgv();", 1000);
}

function qqping_url_build()
{
	return "http://csa.qq.com/p?ref=" + document.referrer + "&domain=VIDEO.QQ.COM";
}

function vs_ping()
{
	//$("<img src='" + qqping_url_build() + "' style='display:none;'>").appendTo(document.body);
	//document.body.appendChild(img);
}

function vs_pgv()
{
	if(vs_pgvTry == 0)
	{
		vs_addScript("http://www.qq.com/js/ping0410.js");
	}
	
	vs_pgvTry++;

	if(typeof(pgvMain) == "function")
	{
		pgvMain();
	}
	else
	{
		if(vs_pgvTry <= 10)
		{
			window.setTimeout("vs_pgv();", 1000);
		}
	}
}

function vs_addScript(url, script, lang)
{
	var scr = document.createElement("SCRIPT");
	if(scr)
	{
		if(!lang)
		{
			lang = "javascript";
		}
		
		scr.language = lang;
		
		if(url)
		{
			scr.src = url;
		}
		
		if(script)
		{
			scr.text = script;
		}
		
		document.body.appendChild(scr);
	}

	return scr;
}

function vs_vsinit()
{
	if(typeof(Array.prototype.push) == "undefined")
	{
		Array.prototype.push = vs_ar_push;
		Array.prototype.pop = vs_ar_pop;
	}
	
	if (!($.browser.msie))
	{
		//for event
		Window.prototype.__defineGetter__("event", ff_win_event);
		
		XMLDocument.prototype.getAttributeOld = Element.prototype.getAttribute;
		XMLDocument.prototype.getAttribute = ff_xml_el_getAttribute;

		XMLDocument.prototype.selectNodes = ff_xml_el_selectNodes;
		XMLDocument.prototype.selectSingleNode = ff_xml_el_selectSingleNode;
	
		XMLDocument.prototype.__defineGetter__("text", ff_xml_el_get_text);
		
		Element.prototype.getAttributeOld = Element.prototype.getAttribute;
		Element.prototype.getAttribute = ff_xml_el_getAttribute;

		Element.prototype.selectNodes = ff_xml_el_selectNodes;
		Element.prototype.selectSingleNode = ff_xml_el_selectSingleNode;
	
		Element.prototype.__defineGetter__("text", ff_xml_el_get_text);
	}	
}

function ff_xml_el_selectNodes(xpath, maxNodes)
{
	if(xpath.substr(0, 2) == "//")
	{
		xpath = xpath.substr(2);
	}
	
	xpath = xpath.toLowerCase();

	if(!maxNodes)
	{
		maxNodes = 10000;
	}

	var arrXPath = xpath.split('/');
	var nodes = new Array();
	
	ff_xml_el_findNodes(this.childNodes, arrXPath, 0, nodes, maxNodes);
	
	nodes.i = 0;
	nodes.nextNode = ff_xml_node_nextNode;

	return nodes;
}

function ff_xml_el_findNodes(childNodes, arrXPath, deep, nodes, maxNodes)
{
	var node;
	var i;
	var name = arrXPath[deep];
	var s;
	
	for(i = 0; i < childNodes.length; i++)
	{
		if(nodes.length >= maxNodes)
		{
			break;
		}

		node = childNodes[i];
		if(node.nodeName.toLowerCase() == name)
		{
			if(deep < arrXPath.length - 1)
			{
				ff_xml_el_findNodes(node.childNodes, arrXPath, deep + 1, nodes, maxNodes);
			}
			else
			{
				nodes.push(node);
			}
		}
	}
}

function ff_xml_el_selectSingleNode(xpath)
{
	var nodes = this.selectNodes(xpath, 1);
	return nodes.nextNode();
}

function ff_xml_el_get_text()
{
	return this.textContent;
}

function ff_xml_node_nextNode()
{
	var node = null;
	if(this.i < this.length)
	{
		node = this[this.i];
		this.i++;
	}
	
	return node;
}

function ff_xml_el_getAttribute(name)
{
	name = name.toLowerCase();
	
	return this.getAttributeOld(name);
}

function ff_win_event()
{
	var caller = arguments.callee.caller;
	var e;

	while(caller)
	{
		e = caller.arguments[0];
		
		if(e && (e.constructor == MouseEvent || e.constructor == KeyboardEvent || e.constructor == Event))
		{
			if(!e.srcElement)
			{
				e.srcElement = e.target;
			}
			
			break;
		}
		else
		{
			e = new Object();
			caller = caller.caller;
		}
	}

	return e;
}


function vs_ar_push(v)
{
	this[this.length] = v;
	
	return this.length;
}

function vs_ar_pop()
{
	var v;

	if(this.length > 0)
	{
		v = this[this.length - 1];
		this.length--;
	}

	return v;
}
function vs_str_UTF8Length(maxlen)
{
	var i;
	var len = 0;
	var s = this;
	var ch;
	
	for(i = 0; i < s.length; i++)
	{
		ch = s.charAt(i);
		
		if(ch < String.fromCharCode(0x80))
		{
			len++;
		}
		else if(ch < String.fromCharCode(0x800))
		{
			len += 2;
		}
		else
		{
			len += 3;
		}
		
		if(maxlen)
		{
			if(len > maxlen)
			{
				len = i;
				break;
			}
		}
	}
	
	if(maxlen)
	{
		len = Math.min(i, len);
	}

	return len;
}

function vs_str_UTF8Trunc(maxlen)
{
	var s = this;
	var i = s.UTF8Length(maxlen);

	if(i >= 0)
	{
		s = s.substr(0, i);
	}
	
	return s;
}

function vs_str_BLength(maxlen)
{
	var i;
	var len = 0;
	var s = this;
	var ch;
	
	for(i = 0; i < s.length; i++)
	{
		ch = s.charAt(i);
		
		if(ch < String.fromCharCode(0x100))
		{
			len++;
		}
		else
		{
			len += 2;
		}

		if(maxlen)
		{
			if(len > maxlen)
			{
				len = i;
				break;
			}
		}
	}
	
	if(maxlen)
	{
		len = Math.min(i, len);
	}

	return len;
}

function vs_str_BTrunc(maxlen)
{
	var s = this;
	var i = s.BLength(maxlen);

	if(i >= 0)
	{
		s = s.substr(0, i);
	}
	
	return s;
}

function vs_str_format()
{
	var ar = this.split("?");
	var i;
	var s = "";
	var t;
	
	for(i = 0; i < ar.length; i++)
	{
		if(i < arguments.length && i != (ar.length - 1))
		{
			t = arguments[i];
		}
		else
		{
			t = "";
		}

		s += ar[i] + t;
	}
	
	return s;
}

pv_init();
vs_vsinit();

var home_hour=new Date().getHours();
var home_hour_index=parseInt(home_hour/6);

function head_search()
{
	var context = $("#context").val();
	var $link = $("#link");
	var dest;
	
	if((!context)||context=="请输入您要查找的关键词")
	{
		$link.attr("target", "");
		alert("您还没有输入搜索内容呢");
		return false;
	}
	$link.attr({
			   		target: "_blank",
					href: $.vs.key2url(context)
			   });
}

function head_setHeaderCookie()
{
	var suin = $.cookie("uin2");
	var uin = $.vs.checkUin(suin);
	var skey = $.cookie("skey2");
	var name;
	var qvkey = $.cookie("qvkey");
	if(uin&&skey)
	{
		$.cookie("uin",suin,{domain:"QQ.com",path:"/"});
		$.cookie("skey",skey,{domain:"QQ.com",path:"/"});
	}
	
	uin=$.vs.checkUin($.cookie("uin"));
	skey=$.cookie("skey");
	name=$.cookie("name");
	
	if(uin && skey && qvkey)
	{
		hd_showLogin();
	}
	else if(hd_qqlogin())
	{
		
		$.getJSON($.vs.path + "/account/tqqlogin2?otype=json&callback=?", function(data){
				var uin=$.vs.checkUin($.cookie("uin"));
				if (!data) 
				{
					return;
				}
				var r = data.s;
				//if(uin&&!!data&&(r=data.s&&(r=="o"))
				if(uin&&!!data&&r=="o")
				{
					//	hd_getUserNick(uin);
					hd_showLogin();
				}
		});
	}
}

function parseXML()
{
	var a;
	var ifr = document.getElementById("loginsript");
	if (ifr.document.readyState == "complete")
	{
		var xmldoc = ifr.contentWindow.document.XMLDocument;
		hd_checkQQVideoLogin(xmldoc);
		clearTimeout(a);
	}
	else
	{
		a = setTimeout("parseXML()", 500);
	}
}

/*
function parseXML()
{
	var a;
	var ifr = document.getElementById("loginsript");
	if (ifr.document.readyState == "complete")
	{
		var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
		xmldoc.async = false;
		xmldoc.load(ifr.contentWindow.document.XMLDocument);
		hd_checkQQVideoLogin(xmldoc);
		clearTimeout(a);
	}
	else
	{
		a = setTimeout("parseXML()", 500);
	}
}
*/

function hd_checkQQVideoLogin(xml)
{
	var uin=$.vs.checkUin($.cookie("uin"));
	var r;
	if(uin&&xml&&(r=xml.selectSingleNode("//root/s"))&&(r.text=="o"))
	{
	//	hd_getUserNick(uin);
		hd_showLogin();
	}
}

function hd_getUserNick(uin)
{
	$.post(
			   "/bin/unick",
			   {
				   uin:uin
			   },
			   hd_getUserNick_cb,
			   "xml"
		   );
}

function hd_getUserNick_cb(xml)
{
	var node;
	var n;
	if(xml)
	{
		node=xml.selectSingleNode("//root/ur");
		if(node)
		{
			n=$.vs.getValue(node,"n");
			if(n)
			{
				alert(n);
				$.cookie("name", n);
			}
		}
	}
	hd_showLogin();
}

function hd_qqlogin()
{
	var uin,skey;
	var zzpaneluin;
	var zzpanelkey;
	var mailuin;
	var mailkey;
	
	uin=$.vs.checkUin($.cookie("uin"));
	skey=$.cookie("skey");
	zzpaneluin=$.vs.checkUin($.cookie("zzpaneluin"));
	zzpanelkey=$.cookie("zzpanelkey");
	mailuin=$.vs.checkUin($.cookie("qqmail_username"));
	mailkey=$.cookie("qqmail_sid");
	
	if(uin&&(skey!=""))
	{		
		return uin;
	}
	else if(zzpaneluin&&(zzpanelkey!=""))
	{
		return zzpaneluin;
	}
	else if(mailuin&&(mailkey!=""))
	{
		return mailuin;
	}
	else
	{
		return false;
	}
}

function hd_showLogin()
{
	$("#hello").css("display","inline");
	$("#tNickSpan").css("display","inline");
	$("#logout").css("display","inline");
	$("#login").css("display","none");
	
	uin=$.vs.checkUin($.cookie("uin"));
	name=$.cookie("name");
	if(!name)
	{
		name=uin;
	}
	$("#tMyNick").text(name);
}

$.fn.addtoptips = function() {
	var tips=new Array("|　夜深了，请注意休息哦","|　早上好，祝您今天好心情","|　加油，加油，让今天多点收获","|　放松心情，享受下生活吧");
	$(this).text(tips[home_hour_index]);
}

$.fn.addbackground = function() {
	var bkpic=new Array("tbg0.jpg","tbg1.jpg","tbg2.jpg","tbg3.jpg");
	$(this).css("background","url("+$.vs.static+"/images/"+bkpic[home_hour_index]+") no-repeat top left");
}

$(function(){
	head_setHeaderCookie();
	
	$(".vtopbg").addbackground();
	$(".toptips").addtoptips();
	//$("#link").get(0).onclick=head_search;
	$("#link").click(head_search);
	$("#context").keydown(function(e){if(e.which == 13) $("#link").focus();	});	
});


function ptlogin2_onResize(width, height)
{	
	login_wnd = document.getElementById("login_div");
	if (login_wnd)
	{
		login_wnd.style.width = width + "px";
		login_wnd.style.height = height + "px";
		login_wnd.style.visibility = "hidden";
		login_wnd.style.visibility = "visible";
	}
}

function ptlogin2_onClose()
{
	login_wnd = document.getElementById("login_div");	
	login_wnd.style.display="none";
	var login_board = document.getElementById("login_board");
	login_board.style.display="none";
	shadow_wnd = document.getElementById("shadow_div");
	shadow_wnd.style.display = "none";
}

function openLogin(urlparam)
{
	var vSupportQLogin = false;
	var url = "http://ui.ptlogin2.qq.com/cgi-bin/login" + "?" + urlparam;
	
	shadow_wnd = document.getElementById("shadow_div");
	login_wnd = document.getElementById("login_div");
	var login_board = document.getElementById("login_board");
	if (login_wnd != null && shadow_wnd != null){
		login_board.style.display = "block";
		login_wnd.style.visible = "hidden"	;
		login_wnd.style.display = "block"	;
		shadow_wnd.style.height = document.documentElement.scrollHeight + "px";
		shadow_wnd.style.display = "block";
		
		if (0 != vSupportQLogin)
		{
			url += ("&qlogin_jumpname=qqshow"
				+ "&qlogin_param="
				+ escape("test1=1&test2=2&test3=4"));
		}
		url += "&style=0";
		url += "&appid=3000501&s_url=http%3A//static.video.qq.com/v1/suc.htm&target=self";
		
		login_frame.location.href = url;
	}
}

function head_logout(url)
{
	$.cookie("uin",null,{domain:"QQ.com",path:"/"});
	$.cookie("skey",null,{domain:"QQ.com",path:"/"});
	$.cookie("uin2",null,{domain:"video.qq.com",path:"/"});
	$.cookie("qvkey",null,{domain:"video.qq.com",path:"/"});
	$.cookie("skey2",null,{domain:"video.qq.com",path:"/"});
	$.cookie("name",null,{domain:"video.qq.com",path:"/"});
	
	document.location.href = url;

}
function head_floatWinProcess()
{
	$("#upload").click(head_upload);
	$("#myhm").click(head_myhm);
}

function head_upload()
{   
	if(head_checkUserLogin())
	{
		window.location = $.vs.path+"/upload";
	}
	return false;
}
function head_myhm()
{   
	if(head_checkUserLogin())
	{
		window.location = $.vs.path+"/user/myhome";
	}
	return false;
}
function head_checkUserLogin()
{   
	var uin=$.vs.checkUin($.cookie("uin"));
	var skey=$.cookie("skey");
	var qvkey=$.cookie("qvkey");
	if(uin&&(skey!="")&&(qvkey!=""))
	{          
		return uin;
	}       
	else
	{
		head_openLoginPage();
		return false;
	}
}
function head_openLoginPage()
{   
    openLogin('f_url=loginerroralert&low_login=0');
	window.scrollTo(0,0);
}

