jQuery.cookie = function(w, p, i) {
    if (typeof p != "undefined") {
        i = i || {};
        if (p === null) {
            p = "";
            i.expires = -1
        }
        var t = "";
        if (i.expires && (typeof i.expires == "number" || i.expires.toUTCString)) {
            var s;
            if (typeof i.expires == "number") {
                s = new Date();
                s.setTime(s.getTime() + (i.expires * 24 * 60 * 60 * 1000))
            } else {
                s = i.expires
            }
            t = "; expires=" + s.toUTCString()
        }
        var n = i.path ? "; path=" + (i.path) : "";
        var r = i.domain ? "; domain=" + (i.domain) : "";
        var x = i.secure ? "; secure": "";
        document.cookie = [w, "=", encodeURIComponent(p), t, n, r, x].join("")
    } else {
        var u = null;
        if (document.cookie && document.cookie != "") {
            var o = document.cookie.split(";");
            for (var q = 0; q < o.length; q++) {
                var v = jQuery.trim(o[q]);
                if (v.substring(0, w.length + 1) == (w + "=")) {
                    u = decodeURIComponent(v.substring(w.length + 1));
                    break
                }
            }
        }
        return u
    }
};
var slum = slum || {};
slum.score = {
	//texts:['超酷，好看极了','好看，不错的视频','很一般噢','很无聊，小娱乐','忒差劲了，不值一看'],
	texts:['很差','较差','凑合','好看','推荐'],
	data:{},
	get:function(){
		var myDate = new Date();
        var mytime=myDate.getTime();
		$.getJSON("/plus/ajax.php?action=videoscore&id="+video.vid+"&time="+mytime, function(ret){
		slum.score.data=ret;
		slum.score.format();
		});
	},
	send:function(s){
		$.get("/plus/ajax.php",{id:video.vid,action:'score',score:s},function(msg){if(msg==1){alert('评分已提交，非常感谢您的参与！'); slum.score.get();}else{alert('囧,-_-|||，您已经评过分了哦？明天再来吧……');}});
	},
	format:function(){
		var data = this.data;
		var s = data.s;
		var z = data.z;
		if(!z||z<1){

		$(".pingfen-total").hide();
		$(".star-box").hide();
		//$(".star-box").after('<div style="display:block; height:29px; width:400px line-height:29px; color:#f00; font-size:18px; float:left;" id="nopf">暂时没有人评分，赶快在左面打分吧！</div>');
$("#nopf").show();
		return true;
		}
		//alert (s);

$("#nopf").hide();
		$(".pingfen-total").show();
		$(".star-box").show();
		var Num=parseInt(s)/2;
		$(".score_avg em").html(s);
		$(".score_avg i").html(s);
		$("#pingfen").html(s);
		$("#pingfen2").html(s);		
		for(var i=0;i<Num;i++)
		{
			$("#starlist li a").eq(i).addClass("on")
		}
		$("#startips").html(slum.score.texts[Num-1]);
		$("#star-num").css("width",""+(s*10)+"%").attr("title","热度："+(s*10)+"%");
		$("#total").css("width",""+(s*10)+"%");	
	
	},
	hasSend:function(){
		var voted = $.cookie('kxlygmoviescore_'+video.vid);
		if(voted==null||voted=='')
			return false;
		else{
			return true;
		}
	},
	init:function(){
		this.get();
		var star_width = 26;
		$('#starlist > li').click(function(){
			var cookiecheck=1;			  //是否验证重复提交，1为验证， 其他为不验证				   
			if(cookiecheck==1){							   
			if(!slum.score.hasSend()){
				var i = $(this).attr('i');
				slum.score.send(i);
				slum.score.format();
			}else{
				alert('囧,-_-|||，您已经评过分了哦？明天再来吧……');
				}
			}
			else{
			
				var i = $(this).attr('i');
				slum.score.send(i);
				slum.score.format();			
			
			}
		});
		$('#starlist > li').hover(function(){
										$("#starlist li a").removeClass("on");
										var Num = $(this).attr('i');
										for(var i=0;i<6;i++)
										{
											if(i<Num)
											{
												$("#starlist li a").eq(i).addClass("is");
											}
											else{
												$("#starlist li a").eq(i).removeClass("is");
											}
											$("#starlist li a").eq(i).attr("title",slum.score.texts[5-i]);
											
										}
								$("#startips").html(slum.score.texts[Num-1]);
				}
		);
	}
};
slum.user = {
	Collect:function(){
		$.get("/user/class/ajax.php?action=addCollect&ajax=1&mid="+video.vid+"", function(ret){
			var num=parseInt(ret);
			if(num==0)
			{
				alert('囧,-_-||| 要先登陆会员后再收藏！');
			}
			else if(num==999)
			{
				alert('囧,-_-||| 你收藏的影片太多了，删除部分再操作吧！');
			}
			else if(num==2)
			{
				alert('囧,-_-||| 添加失败！');
			}
			else if(num==3)
			{
				alert('囧,-_-||| 你已经添加过了！');
			}
			else if(num==4)
			{
				alert('囧,-_-||| 你添加的影片有错误！');
			}			
			else
			{
				$("#pCollect").attr({"class":"pRss-yes","onclick":""});
				alert('收藏成功！');
			}
		});
	},
	Rss:function(){
		$.get("/user/class/ajax.php?action=addRss&mid="+video.vid+"", function(ret){
			var num=parseInt(ret);
			if(num==0)
			{
				alert('囧,-_-||| 要先登陆会员后再订阅！');
			}
			else if(num==2)
			{
				alert('囧,-_-||| 添加失败！');
			}
			else if(num==3)
			{
				alert('囧,-_-||| 你已经添加过了！');
			}
			else if(num==4)
			{
				alert('囧,-_-||| 你添加的影片有错误！');
			}	
			else if(num==999)
			{
				alert('囧,-_-||| 你订阅的影片太多了，删除部分再操作吧！');
			}
			else
			{
				$('#pRss').attr({"class":"pRss-yes","onclick":""});
				alert('订阅成功！');
			}
		});
	}
};