var JQ=jQuery.noConflict();
var sso_username = '';
	var docurl="";
	var docname="";

JQ(document).ready(function(){

	GetUser();//获取用户是否登录
	if(sso_username=="")
	{		
		JQ("#conts").val("文明上网，登录评论！");		
		JQ("#conts").bind("click",unlogintext);
	}
//顶踩
JQ.getScript("http://survey.news.ifeng.com/getaccumulator_ext.php?key="+videoinfo.id+"ding&format=js",GetDingCount); 		
JQ.getScript("http://survey.news.ifeng.com/getaccumulator_ext.php?key="+videoinfo.id+"cai&format=js",GetCaiCount); 	
//浮动窗开启
JQ(".takein").show();
closewin();

})

//未登录点击留言框
function unlogintext()
{
	if(sso_username=="")
	{
		JQ("#conts").css({"background":"#F7F4CC"})
		JQ("#conts").val("登陆后才能评论,请登录！");	
		JQ("#txtname").focus();	
	}
}


//查看用户是否已经登录cookie
function GetUser()
{	
	var sid = getCookie_comment("sid");
	if( sid && sid.length > 32)
	{	
		sso_username = decodeURIComponent(sid.substr(32));
		var msg = '<font color="#000000"><b>'+ sso_username +'</b> 凤凰网欢迎您</font>'; 
		JQ("#Login").html(msg);
		JQ("#conts").val("");	
		JQ("#conts").css({"background":"#fff"})	
	}
}

//获取用户
function getCookie_comment(name){
	var arr=document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr!=null) return arr[2];
	return null;
}



//点击登录
function CheckInfo2()
{
 CheckInfo();
}

function CheckInfo(){
	var cookieEnabled=(navigator.cookieEnabled)?true:false;
	if(!cookieEnabled){
		alert("请开启浏览器COOKIE功能！");
		return false;
	}

	var uname=JQ("#txtname").val();
	var upwd=JQ("#txtpwd").val();

	if(uname=="")
	{
		alert("请输入用户名");
		JQ("#txtname").focus();
		return false;

	}
	if(upwd=="")
	{
		alert("请输入密码");
		JQ("#txtpwd").focus();
		return false;
	}
var parms = "username=" + encodeURIComponent(uname);
 parms += "&password=" + encodeURIComponent(upwd);	
JQ.getScript("http://itv.ifeng.com/interface/_getuserlogindetail_.aspx?"+parms,getLogin); 		
	
}

function getLogin()
{
	if(typeof(userloginmsg)!="undefined")
	{
		switch(userloginmsg.errnum)
		{
			case "0":				
				GetUser();//登陆成功
				break;
			default:
				alert("登陆失败,请检查用户名密码 "+userloginmsg.errnum);
				break;
		}			
	}	
}


var votetime=0;
function timestamp()//评论间隔时间戳
{
   var timestamp = Date.parse(new Date())/1000;
   return timestamp;
}
//回复1--本页提交，弹出总评论页
function ifrcheck()
{
	if(sso_username=="")
	{
		alert('登陆后才能评论,请登录！')
		return;
	}

	if(votetime==0 || (timestamp()-votetime)>10)
	{
		document.getElementById('userName').value=sso_username;	
		document.getElementById('docName').value=docname;
		document.getElementById('docUrl').value=docurl;
		document.getElementById('content').value=document.getElementById("conts").value;
		document.getElementById('formcomment').submit();	
		//alert("回复成功,等待审核!!");
		document.getElementById('conts').value="";
		votetime=timestamp();
	}
	else
	{
		alert("悟空啊，10秒后才能再调皮！！")
	}		
}

//--------------牛视专题vip调用
function LoadMsgvip(title,pageurl)
{
docurl=pageurl;
docname=title;				
JQ.getScript('http://comment.ifeng.com/get.php?format=js&job=1&docurl='+docurl+'&p=1&pagesize=1&field=comment_id',getcommentnum);

}
//获得评论数
function getcommentnum()
{
	var pingluncount=0;
	if(typeof(commentJsonVarStr___)!="undefined" && commentJsonVarStr___.count!=null)
	{	
		pingluncount=commentJsonVarStr___.count;
	}
	JQ("#spcommentnum").html("共有评论"+pingluncount+"条&nbsp;&nbsp;<a href='http://comment.ifeng.com/view.php?docName="+encodeURIComponent(docname)+"&docUrl="+docurl+"' target='_blank'>点击查看</a>");//总记录数
}
//---------------滚动条脚本-----------------------
function ShowItemScoll()
{
	var currposition=2;//始终保持第几条为选中状态
	var shownum=6;//展示条数
	var currid=videoinfo.id;
	var item;

	this.init=function()
	{			
                JQ("#"+currid).addClass("cur");
		item=JQ("#photolist ul li");
		for(var i=0;i<item.length;i++)
		{			
			if(item[i].id==currid)	
			{
				if(i>currposition)
					this.showitem(i-currposition);
				else
					this.showitem(0);
			}
					
		}
	
	},
	this.showitem=function(index)
	{		
		var itemcount=item.length;//总视频数			
                if(itemcount>shownum)
		{
			JQ('#leftbtn').unbind('click');
			JQ('#rightbtn').unbind('click');

	                if(index>0 && index<(itemcount-shownum))//右侧不到最后一个，左侧不到第一个
			{
				JQ('#leftbtn').bind('click',function(){s.showitem(index-1)});//上一个
				JQ('#leftbtn img').attr("src","http://vimg.ifeng.com/v/2010/player/Lpic5.jpg");
				JQ('#rightbtn img').attr("src","http://vimg.ifeng.com/v/2010/player/Lpic6.jpg");
			}				
			else if(index>0)//右侧已经到达最后一个
			{
				JQ('#leftbtn').bind('click',function(){s.showitem(itemcount-shownum-1)});//上一	
                                     JQ('#leftbtn img').attr("src","http://vimg.ifeng.com/v/2010/player/Lpic5.jpg");
				JQ('#rightbtn img').attr("src","http://vimg.ifeng.com/v/2010/player/Lpic6a.jpg");
			}	
			else//左侧已到达第一个
                            {
				JQ('#leftbtn img').attr("src","http://vimg.ifeng.com/v/2010/player/Lpic5a.jpg");
                                JQ('#rightbtn img').attr("src","http://vimg.ifeng.com/v/2010/player/Lpic6.jpg");
                         }

			if((index+shownum)<itemcount)
				JQ('#rightbtn').bind('click',function(){s.showitem(index+1)});//下一个	

			if((index+shownum)>itemcount) 
				index=itemcount-shownum;	

                      JQ("#photolist").animate({left:(-index*150)},"fast");//偏移多少个item的宽度	
		}		
		else
		{
			JQ('#rightbtn img').attr("src","http://vimg.ifeng.com/v/2010/player/Lpic6a.jpg");
			JQ('#leftbtn img').attr("src","http://vimg.ifeng.com/v/2010/player/Lpic5a.jpg");
			return;
		}
		
	},
	this.gotopage=function()
	{
		for(var i=0;i<item.length;i++)
		{			
			if(item[i].id==currid && i==item.length-1 && item.length!=1)//最后一条
				window.location.href=JQ(item[0]).find("span a").attr("href");
			else if(item[i].id==currid && item.length!=1)	
				window.location.href=JQ(item[i+1]).find("span a").attr("href");
		}
	}	
}
var s;
JQ(document).ready(function(){
s=new ShowItemScoll();
s.init();})
function swfplay(swfindex){s.gotopage();}//swf调用的js
//----------------右侧浮层脚本
	  function ck_closewinhot()
	  {
		JQ("#winhot").hide();
		JQ("#wintopborder").css({position:"absolute",top:"311px"});
	  }
	  function ck_openwinhot()
	  {			  
		//JQ("#winWeather").hide();	
		if(JQ("#winhot").css("display")=="none")
		{
			JQ("#wintopborder").css({position:"static",top:"0px"});
			JQ("#winhot").show();
		}
		else
			ck_closewinhot();
	  }
          /*天气预报注释
	  function ck_openwinWeather()
	  {		
		JQ("#winhot").hide();
		if(JQ("#winWeather").css("display")=="none")
		{
			JQ("#wintopborder").css({position:"static",top:"0"});
			JQ("#winWeather").show();
		}
		else
			ck_closewinWeather();
	  }

	  function ck_closewinWeather()
	  {	
		JQ("#winWeather").hide();
		JQ("#wintopborder").css({position:"absolute",top:"311"});//.animate({top:"311"},"1000"); 
	  }*/
	  function closewin()
	  {
		if(JQ("#videoRight").css("display")=="block")
		{
			JQ(".takein").css({"background":"url(http://vimg.ifeng.com/v/2010/player/takein_0428.gif)"});
			JQ("#videoRight").hide();
		}			
		else
		{
			JQ(".takein").css({"background":"url(http://vimg.ifeng.com/v/2010/player/takein_0427.gif)"});
			JQ("#videoRight").show();	
		}					
	  }
//---------顶踩------
//获取顶
function GetDingCount()
{
	if(typeof(surveyJsonVarStr___)!="undefined")
	JQ("#spding").text("顶("+surveyJsonVarStr___.browse+")");
}
function SetDingCount()
{
	JQ.getScript("http://survey.news.ifeng.com/accumulator_ext.php?key="+videoinfo.id+"ding&format=js",GetDingCount); 
}
//获取踩
function GetCaiCount()
{
	if(typeof(surveyJsonVarStr___)!="undefined")
	JQ("#spcai").text("("+surveyJsonVarStr___.browse+")");
}
function SetCaiCount()
{
	JQ.getScript("http://survey.news.ifeng.com/accumulator_ext.php?key="+videoinfo.id+"cai&format=js",GetCaiCount);
}
//视频分享与手机视频下载
//var JQ=jQuery.noConflict();
//下载到手机
function DownForPhone()//选中
{
	var videoname=document.title.replace("-视频--凤凰宽频--凤凰网","");
	var videoid=videoinfo.id;
	var wapstatus=videoinfo.wapstatus==undefined?0:videoinfo.wapstatus;

	var mheight="180px";
	var	mwidth="435px";
	if(!window.XMLHttpRequest)//ie6
	{
		mheight="205px";
	 	mwidth="440px";		
	}

	if(wapstatus=='0')
		window.open("http://vip.v.ifeng.com/phone/");
	else if(wapstatus=='1')
		window.showModalDialog("http://vip.itv.ifeng.com/WapPay/Order.aspx?Con="+encodeURIComponent(videoname)+"&Orderid="+videoid,"","dialogWidth="+mwidth+";dialogHeight="+mheight+";status:no;scroll:no;");
}


function openurldiv()
{
	JQ("#copyurl").show();
	var vid=videoinfo.id;
	//html地址
	var sflashpath='<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="400" height="325">';
	sflashpath+='<param name="movie" value="http://v.ifeng.com/include/exterior.swf?guid='+vid+'&pageurl=http://www.ifeng.com&fromweb=other" />';
	sflashpath+='<param name="quality" value="high" />';
	sflashpath+='<param name="AutoPlay" value="false" />';
	sflashpath+='<embed src="http://v.ifeng.com/include/exterior.swf?guid='+vid+'&pageurl=http://www.ifeng.com&fromweb=other"  AutoPlay="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="325"></embed>';
	sflashpath+='</object>';			
	//复制flash地址	
	JQ("#txtHpath").val(sflashpath);	
	JQ("#txtFpath").val('http://v.ifeng.com/include/exterior.swf?guid='+vid);
	JQ("#txtPpath").val(location.href);	
}
function closeurldiv()
{	
	JQ("#copyurl").hide();		
}
//复制
function copyAddress(obj)
{
  var txt=document.getElementById(obj).value;
  if(window.clipboardData) {    
		 window.clipboardData.clearData();    
		 window.clipboardData.setData("Text", txt);    
 } else if(navigator.userAgent.indexOf("Opera") != -1) {    
	  window.location = txt;    
 } else if (window.netscape) {    
	  try {    
		   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    
	  } catch (e) {    
		   alert("您的firefox安全限制 限制您进行剪贴板操作！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");    
	  }    
	  var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);    
	  if (!clip)    
		   return;    
	  var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);    
	  if (!trans)    
		   return;    
	  trans.addDataFlavor('text/unicode');    
	  var str = new Object();    
	  var len = new Object();    
	  var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);    
	  var copytext = txt;    
	  str.data = copytext;    
	  trans.setTransferData("text/unicode",str,copytext.length*2);    
	  var clipid = Components.interfaces.nsIClipboard;    
	  if (!clip)    
		   return false;    
	  clip.setData(trans,null,clipid.kGlobalClipboard);    
	 
 }    
	 alert("复制成功！") ;   
}
