/**
 * 视频播放页面JS
 */

function fullplayer(){
	document.getElementById("DisplaySize").value=3;
}


$(document).ready(function () {
/*
document.onclick = function() {
    $('#othersrm').hide();
}
var showSrc = ['othersrm', 'othersrmnums'];
var fc = function(event) {
	var e=window.event||event;
	$('#othersrm').show();
	e.cancelBubble=true;
}
for(var i=0,l=showSrc.length;i<l;i++) {
	if($("#"+showSrc[i]).length > 0) {
		document.getElementById(showSrc[i]).onclick = fc;
	}
}
*/
// 获取比赛
$(".matchdate").click(function () {
	$("#week .today").removeClass("today");
	$(this).parent().addClass("today");
	$("#matchbyday").html('<img src="'+API+'/images/loading.gif" />');
	var matchdate = $(this).attr("md");
	$.post(API+'/index.php?m=play&a=ajaxMatch', {matchdate: matchdate, league:'nba'}, function (data) {
		if(data == 'false') {
			alert("囧. 系统出错了！请稍后再试！");
			return false;
		}
		$("#matchbyday").html(data);
		return false;
	});
});

// 显示比赛视频
$("#showMatchVideo").click(function () {
	$(".tabs_header li").removeClass("selected");
	$(this).parent().addClass("selected");
	$(".videobox").hide();
	$("#matchvideo").show();
});
// 显示相关视频
$("#showNearlyVideo").click(function () {
	$(".tabs_header li").removeClass("selected");
	$(this).parent().addClass("selected");
	$(".videobox").hide();
	$("#nearlyvideo").show();
});
// 显示作者视频
$("#showUserVideo").click(function () {
	$(".tabs_header li").removeClass("selected");
	$(this).parent().addClass("selected");
	$(".videobox").hide();
	$("#uservideo").show();
});
if(isplay){
$.post(API+"/index.php?m=play&a=getPlayUrl", {vid:vid}, function (data) {
	flashurl = data;
    if(data.split("bokecc.com").length>1) {
        document.getElementById("flashcontent").innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="500" height="400" id="'+data+'"><param name="movie" value="'+data+'" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="opaque" /><embed src="'+data+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="500" height="400" name="'+data+'" allowFullscreen="true" allowScriptAccess="always"  wmode="opaque"></embed></object>';
    } else {
        document.getElementById("flashcontent").innerHTML = '<a href="javascript:;" onclick="normal();" class="close"></a><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" align="absmiddle" class="play" id="videoobj" width="100%" height="100%"><param name="MOVIE" value="'+data+'"><param name="PLAY" value="TRUE"><param name="LOOP" value="TRUE"><param name="DisplaySize" value="3"><param name="QUALITY" value="HIGH"><param name="wmode" value="transparent" /><embed src="'+data+'" loop="TRUE" align="absmiddle" id="videoplayer" wmode="transparent" play="TRUE" quality="HIGH" allowScriptAccess="always" allowFullScreen="true" width="100%" height="100%"></object>';
    }
});
}
// 显示视频下载地址
$("#showDownloadUrl").click(function () {
	$(".tabs_header li").removeClass("selected");
	$(this).parent().addClass("selected");
	$(".videobox").hide();
	$("#downloadurl").show();

	if($("#downloadurlval").html() == '') {
		$("#downloadurlval").html('<img src="'+API+'/images/loading.gif" /> 虎扑视频中心正在为您解析下载地址...');
		$.post(API+"/index.php?m=video&a=getDownload", {vid:vid}, function (data) {
			var obj = $.evalJSON(data);
			var urls = '';

			if(typeof(obj) == 'object') {
				var i = 0;
				$.each(obj, function(key, val){
					i++;
					urls += '<a class="icon" href="'+val+'" target="_blank">下载地址'+i+'</a> ';
				});
				if(i > 1) {
					urls = '视频被分割成'+i+'段，请在下列地址下载<br />'+urls;
				} else {
					urls = '<a class="icon" href="'+obj[0]+'" target="_blank">下载地址</a>';
				}
			} else if(typeof(obj) == 'string') {
				urls = '<a class="icon" href="'+obj+'" target="_blank">下载地址</a>';
				if(obj.split('56.com').length>1) {
					urls += '<br /><br /><span style="text-align:left;color:#648152;">提醒：请复制下载地址链接粘贴到浏览器地址栏打开，即可下载。</span>';
				}
			} else {
				urls = "下载地址无法解析 Orz <br />请点下面面的红色“举报此视频”，选“链接不能下载”提交给我们，我们会继续努力啊啊啊....";
			}

			$("#downloadurlval").html(urls);
		});
	}
});
// 显示清晰下载地址
$("#showInfocusUrl").click(function () {
	$(".tabs_header li").removeClass("selected");
	$(this).parent().addClass("selected");
	$(".videobox").hide();
	$("#infocusurl").show();
	/////记录用户动态/////
	$.ajax({type: 'POST',url: './index.php?m=video&a=logUserDynamic',
		data:'vid='+vid+'&type=downinfocus',
		success: function(s){}
	});
});

//专辑
$("#showspecial").click(function(){
	$(".tabs_header li").removeClass("selected");
	$(this).parent().addClass("selected");
	$(".videobox").hide();
	$("#specialbox").show();
});

//创建专辑
$(":button[name=createspecial]").bind("click",function(){
	var stitle = $(":input[name=stitle]").val();
	if(stitle){
		$.post(API+'/index.php?m=special&a=createspecial',{stitle:stitle,type:'fromplay'},function(data){
			//alert(data);return false;
			if(data=='not_login'){ $("#login .thickbox").click(); return false;}
			if(data>0){
				$("#myspeciallist").prepend('<input name="specialcheckbox" type="checkbox" value="'+data+'" />'+stitle);
				$(":input[name=stitle]").val("");
			}else alert("创建失败！"); return false;
		});
	}else alert("专辑标题不能为空！")
});

//将视频添加到选中的专辑中
$(":button[name=addtomyspecial]").bind("click",function(){
	var checkbox = $("input:checked[name=specialcheckbox]");
	if(checkbox.length==0){
		fadeMsg("没有选择专辑哦！");
		return false;
	}
	var sid = new Array;
	for(var i=0;i<checkbox.length;i++){
		sid[i] = checkbox[i].value;
	}
	str = "url="+window.location.toString()+"&sid="+sid;
	$.ajax({type: 'POST',url: "/index.php?m=special&a=addspecialvideobyurl",data: str,success: function(s){
			if(s==1)fadeMsg("添加成功！");
			else fadeMsg("添加失败！");
	}});
});
//相关视频
$("#inspecial").bind("click",function(){
	$(".tabs_header li").removeClass("selected");
	$(this).parent().addClass("selected");
	$(".videobox").hide();
	$("#inspecialbox").show();
});


// 其他播放地址
$(".otherplayurl").click(function () {
	$(".otherplayurl").removeClass("on");
	$(this).addClass("on");
	var url = $(this).attr("url");
	flashurl = url;
	if(url.split('qvod:').length > 1 || url.split('.torrent').length > 1 || (url.split('http://').length > 1 && url.split('.rmvb').length > 1)) {
		$.post(API+"/index.php?m=play&a=showQvod", {url:url}, function (data) {
			document.getElementById("flashcontent").innerHTML = data;
		});
		   //$("#flashcontent").html('<object classid="clsid:F3D0D36F-23F8-4682-A195-74C92B03D4AF" width="480" height="400" id="QvodPlayer" name="QvodPlayer" onError=if(window.confirm("请您先安装QvodPlayer软件,然后刷新本页才可以正常播放.")){window.open("http://www.qvod.com/download.htm")}else{self.location="http://www.qvod.com/"}><PARAM NAME="URL" VALUE="http://www.mm.com/111.torrent"><PARAM NAME="Autoplay" VALUE="1"></object>');
	} else if(url.split('gvod:').length > 1) {
		 document.getElementById("flashcontent").innerHTML = '<script src="http://gvod.xunlei.com/player/gvod.js" type="text/javascript" charset="gbk"></script><script>var player = gvod_player();player.height = 400;player.width = 480;player.play("http://rmvb.mdbchina.com/200811/marleyandme.rmvb");';
	} else {
		document.getElementById("flashcontent").innerHTML = '<a href="javascript:;" onclick="normal();" class="close"></a><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" align="absmiddle" class="play" id="videoobj" width="100%" height="100%"><param name="MOVIE" value="'+url+'"><param name="PLAY" value="TRUE"><param name="LOOP" value="TRUE"><param name="DisplaySize" value="3"><param name="QUALITY" value="HIGH"><param name="wmode" value="transparent" /><embed src="'+url+'" loop="TRUE" align="absmiddle" id="videoplayer" wmode="transparent" play="TRUE" quality="HIGH" allowScriptAccess="always" allowFullScreen="true" width="100%" height="100%"></object>';
	}
});

// 显示所有Tag
$("#viewdesc").click(function () {
	if($("#videodesc").is(":visible")) {
		$("#videodesc").hide();
		$("#videoalldesc").show();
		$(this).html("收起来");
	} else {
		$("#videodesc").show();
		$("#videoalldesc").hide();
		$(this).html("显示全部");
	}
});
// 删除视频
$("#video_del").click(function () {
	if(!confirm("确定要删除吗？")) {
		return false;
	}
	$.post(API+'/index.php?m=video&a=delete', {vid:vid, uid:uid}, function (data) {
		if(data == 1) {
			window.location = API;
		}
	});
});
// 设为头条
$("#setfocus").click(function () {
	$.post(API+'/index.php?m=video&a=addFocus', {vid:vid}, function (data) {
		if(data == 1) {
			alert("设置头条成功！");
		} else {
			alert(data+"orz...出问题了！请报告管理员。");
		}
	});
});
// 推送首页
$("#push2home").click(function () {
	$.post(API+'/index.php?m=video&a=push2home', {vid:vid}, function (data) {
		if(data == 1) {
			alert("很好，它被你推倒了！");
		} else {
			alert("囧...这条好像推不动...");
		}
	});
});
// 举报视频
$("#feedback").click(function () {
	showBox('<h2 class="mpop"><a class="closeDialogBox" onclick="closeBox();"><span>关闭</span></a><span id="now_load">举报：</span></h2><ul class="pop_error"><li>举报原因：</li><li><label for="cntplay"><input id="cntplay" name="fdinfo" type="radio" value="视频不能播放" />视频不能播放</label></li><li><label for="cntdown"><input id="cntdown" name="fdinfo" type="radio" value="链接不能下载" />链接不能下载</label></li><li><label for="ntnba"><input id="ntnba" name="fdinfo" type="radio" value="非篮球视频" />非篮球视频</label></li><li><label for="changefd"><input name="fdinfo" type="radio" value="other" id="changefd" />其他</label><span id="otherfd" style="display: none;">：<input type="text" maxlength="20" name="otherfdinfo" class="inputtext"/></span></li><li><input type="submit" name="" class="btns2 fdsubmit" value="提 交"/><input type="button" name="" class="btnb2" onclick="closeBox();" value="取 消" /></li></ul>');
	$("input[@name=fdinfo]").click(function () {
		if($("#changefd").attr('checked')) {
			$("#otherfd").show();
			$("#otherfd input").focus();
		} else {
			$("#otherfd").hide();
		}
	});
	$(".fdsubmit").click(function () {
		var content = $("input[@name=fdinfo][@checked]").val();
		if(content == 'other') {
			content = $("input[@name=otherfdinfo]").val();
		}alert(content);
		if(!content) {
			alert("请选择举报信息！");return false;
		}
		$.post(API+'/index.php?m=feedback&a=add', {vid:vid, content:content}, function (data) {
			closeBox();
			if(data == 1) {
				alert("操作成功！感谢您的反馈！");
			} else {
				alert("服务器出错！请稍后再试。");
			}
		});
	});

});
// 显示作者其他视频
$("#showauthorvideo").click(function () {
	$(this).toggleClass("spread");
	$(this).toggleClass("spread2");
	$("#authorvideo").slideToggle();
});
// 影院效果
$("#CinemaModel").click(function () {
	optionModel();
});
// 推荐
$(".commend").click(function () {
	if(!login) {
		showLogin();
		return false;
	}
	$(this).attr("disabled", "true");
	showBox('<h2 class="mpop"><a class="closeDialogBox" onclick="closeBox();"><span>关闭</span></a><span id="now_load">我要推荐：</span></h2><div class="pop_error">给友邻写一句推荐语：<br /><textarea name="rmmsg" style="width:310px;"></textarea></div><div style="padding:0 0 15px 40px;"><input type="button" name="" class="btns2 rmdsubmit" value="确 定" /> <input type="button" name="" class="btnb2 closeDialogBox" onclick="closeBox();" value="取 消" /></div>');
	$("textarea[@name=rmmsg]").focus();
	$(".rmdsubmit").click(function () {
		var rmmsg = $("textarea[@name=rmmsg]").val();
		$(this).attr("disabled", "true");
		closeBox();
		fadeMsg("你已经推荐成功了！");

		$.post(API+'/index.php?m=recommend&a=recommend', {vid:vid, rmmsg:rmmsg}, function (data) {
			if(data == 'not_login') {
				alert("请先登录！");
			} else if(data == '-1') {
				alert("操作失败！");
			} else {
				//closeBox();
				//fadeMsg("你已经推荐成功了！");
			}
		});
	});
});

//转为日志
$("#tolog").click(function(){
	if(!login) {
		showLogin();
		return false;
	}
	showBox('<h2 class="mpop"><a class="closeDialogBox" onclick="closeBox();"><span>关闭</span></a><span id="now_load">操作原因：</span></h2><div class="pop_error"><br /><textarea name="rmmsg" style="width:310px;">$user 筒子，您好！感谢您在视频中心发布《$video》，目前视频中心只接受篮球内容视频的发布，现已将您发布的视频转为日志：http://my.hoopchina.com/$myurl,<br />转为日志不会影响你的论坛等级和卡路里。再次感谢您的热心分享和支持理解！</textarea></div><div style="padding:0 0 15px 40px;"><input type="button" name="" class="btns2 rmdsubmit" value="确 定" /> <input type="button" name="" class="btnb2 closeDialogBox" onclick="closeBox();" value="取 消" /></div>');
	$(".rmdsubmit").click(function(){
		var rmmsg = $("textarea[@name=rmmsg]").val();
		$.post(API+'/index.php?m=video&a=tolog',{vid:vid,rmmsg:rmmsg},function(data){
			if(data == 'not_login'){
				alert("请先登录!");
			}else if(data == '-1'){
				alert("操作失败");
			}else {
				closeBox();
				fadeMsg("已成功转为日志");
				window.location = API;
			}
		});
	})
});

// 复制网站
$(".copy").click(function () {
	var obj = $(this).prev();
	if (navigator.appVersion.match(/\bMSIE\b/)){
		clipboardData.setData('text',obj.val());
		alert("复制成功！");
	}else{
		alert("您使用的浏览器不支持此复制功能，请使用Ctrl+C或鼠标右键。");
		obj.select();		
	}
});

//禁止用户
$("#prohibit_user").click(function(){
	var username = $(".userfavorite").attr("uname");
	var uid = $(".userfavorite").attr("uid");
	var title = $(".userfavorite").attr("vtitle");
	var content = '您在视频中心被禁言【禁言时间变量】天。禁言原因：您在视频中心发表的《'+title+'》（'+title+'）内容不当，虎扑不欢迎此类内容，您将在【禁言时间变量】天后自动恢复为正常状态。';
	var html = prohibitBox(username,content);
	showBox(html);
	$("#prohibitform").bind("submit",function(){
		var msg = $("#prohibitform :checkbox[name=msg]").val();
		var time = $("#prohibitform :input[name=time]").val();
		var content = $("#prohibitform :input[name=content]").val();
		closeBox();
		content = content.replace(/【禁言时间变量】/g,time);

		if(msg==1){
			$.post(API+'/index.php?m=interface&a=SMS',{content:content,uid:uid,author:username},function (data){
				
			});
		}
		$.post(API+'/admin.php?m=prohibit&a=addMember',{uid:uid,username:username,time:time,jumpurl:1},function (data){
			if(data==1)fadeMsg("禁言成功!");
			else alert(data)
		});
		
		return false;
		
	});
});


//海报
$(".poster").bind("click",function(){
	var id = $(this).attr("id").replace(/sposter/,'');
	$("#bposter"+id).show("slow");
	var overlay = document.createElement("div");
	overlay.id = "overlay";
	overlay.style.top = "0px";
	overlay.style.left = "0px";
	overlay.style.height = document.body.clientHeight+"px";
	overlay.style.width = "100%";
	overlay.style.position = "absolute";
	
	overlay.onclick = hideOverlay;
	document.body.appendChild(overlay);
});

$(".big_pic .close").bind("click",function(){
	$(".big_pic").hide();
});

//锁定回复
$("#commentlock").bind("click",function(){
	$.post(API+'/index.php?m=comment&a=lock',{vid:vid,status:'lock'},function(data){
		if(data=='invalid Parameter') fadeMsg("莫再试了，烦么？");
		if(data=='Access Denied')fadeMsg("木有权限唉！");
		if(data==0)fadeMsg("锁定失败");
		if(data==1){
			fadeMsg("锁定成功");
			window.location = window.location.toString();
		}
	});
});
//解除锁定
$("#uncommentlock").bind("click",function(){
	$.post(API+'/index.php?m=comment&a=lock',{vid:vid,status:'unlock'},function(data){
		if(data=='invalid Parameter') fadeMsg("莫再试了，烦么？");
		if(data=='Access Denied')fadeMsg("木有权限唉！");
		if(data==0)fadeMsg("解锁失败");
		if(data==1){
			fadeMsg("解锁成功");
			window.location = window.location.toString();
		}
	});
});

});////////////////////绑定事件结束

function hideOverlay(){
	$(".big_pic").hide("slow");
	$("#overlay").remove();
}

function removepagestat(){
	$("pagestat").remove();
}
function openCinemaModel()
{
	var bH = $("body").height();
	var bW = $("body").width();
	if(bH < document.body.clientHeight) {
		bH = document.body.clientHeight;
	}
	if(bW < document.body.clientWidth) {
		bW = document.body.clientWidth;
	}
	 
	//var ve = $("embed").attr("wmode");  
	//$("EMBED").attr("wmode","window"); 
	$("#cinemaModelLay").css({width:bW,height:bH,display:"block"});
	$("#cinemaToolbar").css({display:"block"});
}

function exitCinemaModel()
{
	$("#cinemaModelLay").hide();
	$("#cinemaToolbar").hide();
}
function optionModel()
{
	if(document.getElementById("cinemaModelLay").style.display == 'none') {
		openCinemaModel();
		$("#CinemaModel").addClass('nocinema');
		$("#CinemaModel").removeClass('cinema');
		$("#CinemaModel").attr("title", "开灯模式下观看视频");
	} else {
		exitCinemaModel();
		$("#CinemaModel").addClass('cinema');
		$("#CinemaModel").removeClass('nocinema');
		$("#CinemaModel").attr("title", "关灯模式下观看视频");
	}
}
