$(document).ready(function(){
		$(".video_jump").click(videojump);
		$(".comment_submit").click(submit);
		$(".jq_evaluate").click(evaluate);
		$(".sousuo").click(toSearch);
		getCdn();
		getCookie();
		});

function getCdn()
{
	var cdn = $(".cdn").attr("cdn");
	var cdn_id = $(".cdn_id").attr("cdn_id");

	var text1 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="539" height="481">'+
		'<param name="movie" value="http://img1.c0.ku6.cn/wcg/wcg1.1.1.swf" />'+
		'<param name="quality" value="high" />'+
		'<param name="allowScriptAccess" value="always" />'+
		'<param name="allowfullscreen" value="true" />'+
		'<param name="flashvars" value="vid='+ cdn_id + '&so=1&fv=1&zv=0&bv=1&color=FFFF00&pv=0" />' +		
		'<embed src="http://img1.c0.ku6.cn/wcg/wcg1.1.1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="456" height="410"  allowScriptAccess="always" allowfullscreen="true" flashvars="vid='+ cdn_id +'&so=1&fv=1&zv=0&bv=1&color=FFFF00&pv=0" ></embed></object>';

	var text2 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" type="application/x-shockwave-flash" data="http://js.tudouui.com/bin/hezuo/neotv/Neotv_0.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="456" height="400" id="neotv">' +
                    '<param name="movie" value="http://js.tudouui.com/bin/hezuo/neotv/Neotv_0.swf" />' +
		    '<param name="quality" value="high" />' +
		    '<param name="wmode" value="transparent">' +
     		    '<param name="flashvars" value="id='+ cdn_id +'">' +
		    '<param name="menu" value="false">' +
		    '<param name="scale" value="noscale">' +
		    '<param name="salign" value="tl">' +
		    '<param name="allowfullscreen" value="true">' +
		    '<param name="allowscriptaccess" value="always">' +
		    '<embed wmode="transparent" src="http://js.tudouui.com/bin/hezuo/neotv/Neotv_0.swf" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id='+ cdn_id +'" width="456" height="400"></embed>' +
		    '</object>';

	if(cdn == 1)
		$(".swf_object").html(text1);
	if(cdn == 2)
		$(".swf_object").html(text2);	
}

function getCookie() 
{    
	var vid = $(".vid").attr("vid");
       	name = "before";	
	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 ) 
	{
		setCookie(vid);
		return null;
	} 
    	var end = document.cookie.indexOf( ';', len );
     	if ( end == -1 ) end = document.cookie.length; 
	var str =  unescape(document.cookie.substring(len,end));

	var video = str.split(",");
	for(var i=0;i<video.length && i<6;i++)
	{
		if(video[i]==vid)
			break;
	}

	if(video.length<6 && i==video.length)
	{
		str = vid + "," +str;
	}
	else if(i==6 && video.length==6)
	{
		str = vid + "," + video[0] + "," + video[1] + "," + video[2] + "," + video[3] + "," + video[4];
	}
	setCookie(str);
} 

function setCookie(value, expires, path, domain, secure ) 
{
   	name = "before";
	var exp = new Date();
	expires = 30 * 1000 * 60 * 60 * 24;
   	exp.setTime( exp.getTime() + expires );
	
     	document.cookie = name+'='+escape( value ) + 
		( ( expires ) ? ';expires='+exp.toGMTString() : '' ) + 
		( ( path ) ? ';path=' + path : '' ) + 
		( ( domain ) ? ';domain=' + domain : '' ) + 
		( ( secure ) ? ';secure' : '' ); 
}

function evaluate()
{
	var vid = $(".vid").attr("vid");
	var evaluate = $(this).attr("evaluate");
	var gb = $(this).attr("gb");
	var val = $("."+gb).text() - 0;
	$.post("/videopl/evaluate",
	{
		vid:vid,
		evaluate:evaluate
	},		
	function(xml)
	{
		val = val + 1;
		$("."+gb).text(val);
	}
	);
	return false;
}

function submit()
{
	var cid = $(".cid").attr("cid");
	var uid = $(".uid").attr("uid");
	var vid = $(".vid").attr("vid");
	var comments;
	var content = $(".video_comment").text();
	if(uid)
		var username = $(".username").attr("username");
	else
	{
		uid = 0;
		var username = "NeoTV网友";
	}
	$.post("/videopl/comment",
		{
			cid:cid,
			uid:uid,
			vid:vid,
			username:username,
			content:content
		},
		function(xml){
			comments = $(xml).find("s").text();
			$(".jq_comments").text(comments);
			videojump2(0);
		}	
	);
	return false;
}

function videojump()
{
	var page = $(this).attr("page");
	videojump2(page);
	return false;
}

function videojump2(page)
{
	if(page == 0)
		page = 1;
	
	var cid = $(".cid").attr("cid");
	$.post("/videopl/page",
	{
		cid:cid,
		page:page
	},
	function(html)
	{
		$(".jq_video_content").html(html);
		$(".video_jump").click(videojump);
		$(".comment_submit").click(submit);
	}
	);	
	return false;
}

function set_video_info()
{
    var vh = document.getElementById("video_info_index");
    var btn = document.getElementById("video_info_btn");
    if(vh && btn)
    {
        if(vh.style.display == "none")
        {
            vh.style.display = "";
            btn.innerHTML = '<img src="images/p23.gif" width="12" height="13" />';
        }
        else
        {
            vh.style.display = "none";
            btn.innerHTML = '<img src="images/p25.gif" width="12" height="13" />';
        }
    }
    return false;
}

function set_video_before()
{
    var vh = document.getElementById("video_before_index");
    var btn = document.getElementById("video_before_btn");
    if(vh && btn)
    {
        if(vh.style.display == "none")
        {
            vh.style.display = "";
            btn.innerHTML = '<img src="images/p23.gif" width="12" height="13" />';
        }
        else
        {
            vh.style.display = "none";
            btn.innerHTML = '<img src="images/p25.gif" width="12" height="13" />';
        }
    }
    return false;
}



function set_video_hot()
{
    var vh = document.getElementById("video_hot_index");
    var btn = document.getElementById("video_hot_btn");
    if(vh && btn)
    {
        if(vh.style.display == "none")
        {
            vh.style.display = "";
            btn.innerHTML = '<img src="images/p23.gif" width="12" height="13" />';
        }
        else
        {
            vh.style.display = "none";
            btn.innerHTML = '<img src="images/p25.gif" width="12" height="13" />';
        }
    }
    return false;
}

function set_video_new()
{
    var vh = document.getElementById("video_new_index");
    var btn = document.getElementById("video_new_btn");
    if(vh && btn)
    {
        if(vh.style.display == "none")
        {
            vh.style.display = "";
            btn.innerHTML = '<img src="images/p23.gif" width="12" height="13" />';
        }
        else
        {
            vh.style.display = "none";
            btn.innerHTML = '<img src="images/p25.gif" width="12" height="13" />';
        }
    }
    return false;
}
