function $TAB(x){return document.getElementById(x);}
function tab_show(a,b,c,d){
	x=a,max_i=b,tn=c,tc=d;
	for(var i=1;i<=max_i;i++){
		if($TAB(tn+i))$TAB(tn+i).className=$TAB(tc+i).className="";
	}
	$TAB(tn+x).className=$TAB(tc+x).className="on";
}


function getCookie( name ) {     
	var start = document.cookie.indexOf( name + "=" );     
	var len = start + name.length + 1;     
	if (( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {         
		return null;     
	}    
	 if ( start == -1 ) return null;     
	 var end = document.cookie.indexOf( ';', len );     
	 if ( end == -1 ) end = document.cookie.length;     
	 return unescape( document.cookie.substring( len, end ) ); 
 }
function setCookie( name, value, expires, path, domain, secure ) {
     var today = new Date();
     today.setTime( today.getTime() );
     if ( expires ) {         
     	expires = expires * 1000 * 60 * 60 * 24;     
     }     
     var expires_date = new Date( today.getTime() + (expires) );     
     document.cookie = name+'='+escape( value ) + 
     (( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
     (( path ) ? ';path=' + path : '' ) +
     (( domain ) ? ';domain=' + domain : '' ) +
     (( secure ) ? ';secure' : '' ); 
}  
function deleteCookie( name, path, domain ) {
     	if (getCookie(name)) document.cookie = name + '=' +(( path ) ? ';path=' + path : '') +
     (( domain ) ? ';domain=' + domain : '' ) +';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 
     	
     }
function q_gk(){
	deleteCookie('_his','/','letv.com');
	var gkjl = '<p><a onclick="javascript:q_gk();" style="cursor:pointer;">清空记录</a>  |  <a onclick="javascript:	$(\'#gkjl\').hide();$(\'.hisbox>a\').attr(\'class\',\'\');" style="cursor:pointer;">关闭</a></p><ul class="lookedul" id="scrollContent"></ul>';	
	$('#gkjl').html(gkjl);
	

}     
function s_gk(){
$(".hisbox>a").attr('class','a_on');
var gkjl = '<p><a onclick="javascript:q_gk();" style="cursor:pointer;">清空记录</a>  |  <a onclick="javascript:	$(\'#gkjl\').hide();$(\'.hisbox>a\').attr(\'class\',\'\');" style="cursor:pointer;">关闭</a></p><ul class="lookedul" id="scrollContent">';

if(getCookie('_his')){
	var json  = eval(getCookie('_his'));
	if (json){
		for($i=0;$i<json.length;$i++){
			gkjl += '<li><a href="'+json[$i]['url']+'" class="Bclose"></a><span><i> <a href="'+json[$i]['url']+'?'+json[$i]['position']+'" title="'+json[$i]['title']+'" alt="'+json[$i]['title']+'">'+json[$i]['title'].substring(0,12)+'</a></i> <i>已看：0:'+json[$i]['position'].substr(0,2)+' <a href="'+json[$i]['url']+'?'+json[$i]['position']+'" class="red2">继续观看</a></i></span></li>';
		}

	}
}

gkjl += ' </ul>';	

$('#gkjl').html(gkjl);
$('#gkjl').show();



}
function h_gk(is_close){
	$(".hisbox>a").attr('class','');

	$('#gkjl').hide();
	
	
}
var html_str = '';
if(CookieTool.getValue("casflag")==1 && !CookieTool.chkCookies("u")){	//登录了vip 但没有产生u cookie;
	flag =1;
	$.getJSON('http://app.letv.com/ajax/logininfo_2nd.php?rand=' + Math.random()+"&jsonp=?",function(data){
		score = data.userScore;
		msg =  '('+data.newmsgcount+')';
	})
}


if(CookieTool.chkCookies("u")){
	var userInfo = eval('('+BaseCode.decode(CookieTool.getValue('u'))+')');
	var html_str = '<a href="http://www.letv.com/ptv/'+userInfo.uid+'" target="_blank">'+userInfo.nickname+'</a>,您好!| <a href="http://app.letv.com/user/my_video.php" title="管理播主" target="_blank">播主</a> | <a href="http://app.letv.com/user/login_out.php"  title="退出">退出</a> | <a href="http://app.letv.com/help/help.php" target="_blank" title="帮助">帮助</a>';
	
}else{
	var html_str = '<a href="http://app.letv.com/login" title="登录">登录</a> | <a href="http://app.letv.com/signup" target="_blank" title="注册">注册</a> | <a href="http://app.letv.com/help/help.php" target="_blank" title="帮助">帮助</a>';
}


$(document).ready(function(){
	
	$('#userlogin').html(html_str);
	
	$("#keyword").autocomplete({
		url: 'http://220.181.117.53/pTV/searchSo?rand=' + Math.random()+'&callback=?',
		sortFunction: function(a, b) {
			a = String(a.data[0]).toLowerCase();
			b = String(b.data[0]).toLowerCase();
			if (a > b) {
					return 1;
			}
			if (a < b) {
					return -1;
			}
			return 0;
		},
		showResult: function(value, data) {
			return '<span style="float:right; color:red;" >'+data+'视频</span><span >' + value + '</span>';
		}
	});
	if($.browser.iPad){
		$('#agkjl').bind('touchstart',function(){
			s_gk();
		
		}).bind('touchend',function(){
			h_gk();
			
		});
	}else{
		$('#agkjl').hover(function(){
			s_gk();
		
		},function(){	
			h_gk();
			
		});
	}
	if($('#wd').length>0){
		Focus.v=$('#wd').val();
		$('#wd').bind({focus:function(){
				Focus.inInp($(this));
			},
			blur:function(){
				Focus.outInp($(this));
			}})
	}
	
});


