function $(item){
	return document.getElementById(item);
}
//document.domain='xunlei.com';
function c_getCookie(sName){
	var sSearch = sName + "=";
	var iOffset = document.cookie.indexOf(sSearch);
	if (iOffset != -1) {
		iOffset += sSearch.length;
		var iEnd = document.cookie.indexOf(";", iOffset);
		if (iEnd == -1)
			iEnd = document.cookie.length;
		return unescape(document.cookie.substring(iOffset, iEnd));
	}else 
		return "";
}
function c_setCookie(sName,sValue,sHours){
	if(arguments.length>2){
		var expireDate=new Date(new Date().getTime()+sHours*3600000);
		document.cookie = sName + "=" + escape(sValue) + "; path=/; domain=xunlei.com; expires=" + expireDate.toGMTString();
	}else
		document.cookie = sName + "=" + escape(sValue) + "; path=/; domain=xunlei.com"; 
}
function c_login(u){
	top.location='http://i.xunlei.com/account/login.html?url='+encodeURIComponent(u);
}
function c_logout(o){
	c_setCookie("sessionid","");
	o.innerHTML='<a href="javascript:c_login(top.location);"> 登录 </a><a href="javascript:c_regist(top.location);"> 注册 </a>';
}
function c_regist(u){
	top.location='http://i.xunlei.com/account/signup2.shtml?url='+encodeURIComponent(u);
}
function c_verfySession(o){
	if(c_getCookie('sessionid')!=''){
		o.innerHTML='<a href="javascript:;">'+c_getCookie('nickname')+'('+c_getCookie('usrname')+')</a><a  href="javascript:c_logout('+o.id+');" >退出  </a>';
	}
}
//页面登录信息初始化
function initLogininfo()
{
	 var headDiv = $("div_userinfo");
	 if(headDiv){
		c_verfySession(headDiv);
	 }
}
function doLoginOut(){
	 var headDiv = $("div_userinfo");
	 if(headDiv){
		c_logout(headDiv);
	 }
}
//向左滚动
ScrollCrossLeft={interval:0,count:0,duration:0,step:0,srcObj:null,callback:null};
ScrollCrossLeft.doit=function(obj,b,c,d){
	var s=ScrollCrossLeft;
	obj.style.marginLeft=cpu(s.count,b,c,d)+'px';
	s.count++;
	if(s.count==d){
		clearInterval(s.interval);
		s.count=0;
		obj.style.marginLeft=b+c+'px';
		s.callback();
	}
	function cpu(t,b,c,d) {return c*((t=t/d-1)*t*t+1)+b;};
}
ScrollCrossLeft.scroll=function(obj,step,span,beign,callback,duration){
	var s=ScrollCrossLeft;
	s.duration=duration;
	s.callback=callback;
	s.interval=setInterval(function(){s.doit(obj,beign,step*span,duration)},10);
}
