﻿$(function(){
	/****************
	通用导航效果 开始
	*****************/
	$('#mainav .mainavli:has(ul)').addClass('arrowdown');	//主导航：鼠标不移动上去默认时的样式
	$('#mainav .mainavli > a').addClass('mainavlink');		//主导航：主导航上的链接样式
	$('#mainav .mainavli li a').addClass('subnavlink');		//子导航：子导航上的链接样式
	$('#mainav .mainavli ul').css('opacity','0.9');		//子导航：设置显示透明度
	//主导航鼠标效果
	var timeoutId;
	$('#mainav .mainavli').hover(function(){
		var $mainavli=$(this);
			timeoutId=setTimeout(function(){
			$mainavli.addClass('mainavli_focus');
			$mainavli.children('a').addClass('mainavlink_focus');
			$mainavli.children('ul').fadeIn();
		},100);
	},function(){
		$(this).removeClass('mainavli_focus');
		$(this).children('a').removeClass('mainavlink_focus');
		$(this).children('ul').fadeOut();
		clearTimeout(timeoutId);
	});
	//子导航鼠标效果
	$('#mainav .mainavli li').hover(function(){
		$(this).css('background','#838383 url(http://image.jsbc.com/v_tvshow/subnavlibg_focus.gif) no-repeat center top');
		$(this).children('a').css('color','#585954');
	},function(){
		$(this).css('background','#838383 url(http://image.jsbc.com/v_tvshow/subnavlibg.gif) no-repeat center top');
		$(this).children('a').css('color','#FFF');
		clearTimeout(timeoutId);
	});
	/****************
	通用导航效果 结束
	*****************/

	/****************
	sns嵌入 开始
	*****************/
	//栏目页“最新话题”
	if($('#pro_snshow1').length > 0){
		$('#pro_snshow1').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			var bcpro=$('#bcprogramme').text();
			var gtou=new GB2312UTF8();
			bcpro=gtou.Gb2312ToUtf8(bcpro);
			$(this).html("<iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=new&pro="+bcpro+"' frameborder='0' scrolling='no' id='jsbc_new_iframe' width='480' height='233'></iframe>");	
			$(this).fadeIn('slow');
		});
	}
	//栏目页“栏目精华”
	if($('#pro_snshow2').length > 0){
		$('#pro_snshow2').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			var bcpro=$('#bcprogramme').text();
			var gtou=new GB2312UTF8();
			bcpro=gtou.Gb2312ToUtf8(bcpro);
			$(this).html("<iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=digest&pro="+bcpro+"' frameborder='0' scrolling='no' id='jsbc_new_iframe' width='480' height='233'></iframe>");	
			$(this).fadeIn('slow');
		});
	}
	//栏目播放页“最新话题”
	if($('#ply_snshow1').length > 0){
		$('#ply_snshow1').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			var vid=$('#ply_vid').text();
			$(this).html("<iframe src='http://i.jsonline.cn/index.php?act=jsbc_comment&vid="+vid+"' frameborder='0' scrolling='no' width='558' id='jsbc_comment_iframe'></iframe>");
			$(this).fadeIn('slow');
		});
	}
	//栏目播放页“栏目精华”
	if($('#ply_snshow2').length > 0){
		$('#ply_snshow2').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			var vid=$('#ply_vid').text();
			$(this).html("<div class='sec_right1top'><iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=new&vid="+vid+"' frameborder='0' scrolling='no' id='jsbc_new_iframe' width='410' height='233'></iframe></div><div class='sec_right1bt'><iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=digest&vid="+vid+"' frameborder='0' scrolling='no' id='jsbc_digest_iframe' width='410' height='233'></iframe></div>");
			$(this).fadeIn('slow');
		});
	}
	//电视剧（有视频）模板“最新话题”
	if($('#tv_snshow1').length > 0){
		$('#tv_snshow1').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			$(this).html("<iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=new&id=54' frameborder='0' scrolling='no' id='jsbc_new_iframe' width='480' height='233'></iframe>");
			$(this).fadeIn('slow');
		});
	}
	//电视剧（有视频）模板“栏目精华”
	if($('#tv_snshow2').length > 0){
		$('#tv_snshow2').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			$(this).html("<iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=digest&id=54' frameborder='0' scrolling='no' id='jsbc_new_iframe' width='480' height='233'></iframe>");
			$(this).fadeIn('slow');
		});
	}
	//电影模板“最新话题”
	if($('#mov_snshow1').length > 0){
		$('#mov_snshow1').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			$(this).html("<iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=new&id=53' frameborder='0' scrolling='no' id='jsbc_new_iframe' width='480' height='233'></iframe>");
			$(this).fadeIn('slow');
		});
	}
	//电影模板“栏目精华”
	if($('#mov_snshow2').length > 0){
		$('#mov_snshow2').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			$(this).html("<iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=digest&id=53' frameborder='0' scrolling='no' id='jsbc_new_iframe' width='480' height='233'></iframe>");
			$(this).fadeIn('slow');
		});
	}
	//封神榜播放页“最新话题”
	if($('#fsb_snshow1').length > 0){
		$('#fsb_snshow1').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			$(this).html("<iframe src='http://i.jsonline.cn/index.php?act=jsbc_comment&vid="+geturl("vid")+"' frameborder='0' scrolling='no' width='558' id='jsbc_comment_iframe'></iframe>");
			$(this).fadeIn('slow');
		});
	}
	//封神榜播放页“栏目精华”
	if($('#fsb_snshow2').length > 0){
		$('#fsb_snshow2').load('http://www.jsbc.com/include/blank.html',function(){
			$(this).hide();
			$(this).html("<div class='sec_right1top'><iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=new&vid="+geturl("vid")+"' frameborder='0' scrolling='no' id='jsbc_new_iframe' width='410' height='233'></iframe></div><div class='sec_right1bt'><iframe src='http://i.jsonline.cn/index.php?mod=group&act=topic&op=digest&vid="+geturl("vid")+"' frameborder='0' scrolling='no' id='jsbc_digest_iframe' width='410' height='233'></iframe></div>");
			$(this).fadeIn('slow');
		});
	}
	/****************
	sns嵌入 结束
	*****************/

	/****************
	读取link.json 增加所属链接 开始
	*****************/
	AddNewUrl();
	/****************
	读取link.json 增加所属链接 结束
	*****************/

	/****************
	关键词增加链接 开始
	*****************/
	AddKeyUrl();
	/****************
	关键词增加链接 结束
	*****************/

	/****************
	改变时长显示 开始
	*****************/
	var dur=$('.newdur');
	var minu,sec;
	$.each(dur,function(index){
		var serdur=dur.eq(index);
		if(serdur.text()!=''){
			minu=parseInt(parseInt(serdur.text())/60);
			sec=parseInt(serdur.text())%60;
			if(minu>0){
				serdur.text(minu+'分'+sec+'秒');
			}else{
				serdur.text(dur[index].innerHTML=sec+'秒');
			}
		}else{
			serdur.text('-');
		}
	});
	/****************
	改变时长显示 结束
	*****************/

	/****************
	snscomment链接到sns的小图标效果 开始
	*****************/
	setInterval('snscomment()',500);
	/****************
	snscomment链接到sns的小图标效果 结束
	*****************/
});
//snscomment链接到sns的小图标效果
function snscomment(){
	var snscomment=$('.snscomment');
	if(snscomment.css('opacity')==0.5){
		snscomment.animate({
			opacity: 1.0
		},100);
	}
	else{
		snscomment.animate({
			opacity: 0.5
		},400);
	}
}
//增加所属链接
function AddNewUrl(){
	$.getJSON("http://www.jsbc.com/xml/link.json",function(json){
		var newpro=$('.newpro');
		var newchl=$('.newchl');
		$.each(json,function(index){
			$.each(newpro,function(i){
				if(newpro.eq(i).text()==json[index].name){
					newpro.eq(i).html('<a href="'+json[index].url+'" target="_blank">'+json[index].name+'</a>');	//所属栏目
					//$('#lnktopro').attr('href',json[index].url);	//播放页的“栏目信息”
				}
			});
			$.each(newchl,function(i){
				if(newchl.eq(i).text()==json[index].name){
					newchl.eq(i).html('<a href="'+json[index].url+'" target="_blank">'+json[index].name+'</a>');	//所属频道
				}
			});
		});
	});
}
//关键词增加链接
function AddKeyUrl(){
	var newk=$('.newk');
	$.each(newk,function(index){
		var pernewk=newk.eq(index);	//每个关键词组
		var keys=pernewk.text().split(' ');	//每个关键词拆分后的数组
		var newkeywords='';	//新组成的关键词
		var gtou=new GB2312UTF8();	//标签gb2312转utf-8
		$.each(keys,function(i){
			newkeywords+=('<a href="http://www.jsbc.com/was40/search?channelid=17564&searchword='+gtou.Gb2312ToUtf8(keys[i])+'" target="_blank">'+keys[i]+'</a> ');
		});
		pernewk.html(newkeywords);
	});
}
//png在IE6下背景透明，用于大logo
function fixPNG(myImage) {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters))
	{
		var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
		var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
		var imgTitle = (myImage.title) ? "title='" + myImage.title   + "' " : "title='" + myImage.alt + "' ";
		var imgStyle = "display:inline-block;" + myImage.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + myImage.width
			+ "px; height:" + myImage.height
			+ "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
		myImage.outerHTML = strNewHTML;
	}
}
//标签gb2312转utf-8，用于栏目页sns嵌入
function GB2312UTF8(){
	this.Dig2Dec=function(s){
		var retV = 0;
		if(s.length == 4){
			for(var i = 0; i < 4; i ++){
				retV += eval(s.charAt(i)) * Math.pow(2, 3 - i);
			}
			return retV;
		}
		return -1;
	} 
	this.Hex2Utf8=function(s){
		 var retS = "";
		 var tempS = "";
		 var ss = "";
		 if(s.length == 16){
			 tempS = "1110" + s.substring(0, 4);
			 tempS += "10" + s.substring(4, 10); 
			 tempS += "10" + s.substring(10,16); 
			 var sss = "0123456789ABCDEF";
			 for(var i = 0; i < 3; i ++){
				retS += "%";
				ss = tempS.substring(i * 8, (eval(i)+1)*8);
				retS += sss.charAt(this.Dig2Dec(ss.substring(0,4)));
				retS += sss.charAt(this.Dig2Dec(ss.substring(4,8)));
			 }
			 return retS;
		 }
		 return "";
	} 
	this.Dec2Dig=function(n1){
		var s = "";
		var n2 = 0;
		for(var i = 0; i < 4; i++){
			n2 = Math.pow(2,3 - i);
			if(n1 >= n2){
				s += '1';
				n1 = n1 - n2;
			}
			else
			s += '0';
		}
		return s;
	}
	this.Str2Hex=function(s){
		var c = "";
		var n;
		var ss = "0123456789ABCDEF";
		var digS = "";
		for(var i = 0; i < s.length; i ++){
			c = s.charAt(i);
			n = ss.indexOf(c);
			digS += this.Dec2Dig(eval(n));
		}
		return digS;
	}
	this.Gb2312ToUtf8=function(s1){
		var s = escape(s1);
		var sa = s.split("%");
		var retV ="";
		if(sa[0] != ""){
		  retV = sa[0];
		}
		for(var i = 1; i < sa.length; i ++){
		  if(sa[i].substring(0,1) == "u"){
			retV += this.Hex2Utf8(this.Str2Hex(sa[i].substring(1,5)));
	   if(sa[i].length){
		retV += sa[i].substring(5);
	   }
		  }
		  else{
		 retV += unescape("%" + sa[i]);
	   if(sa[i].length){
		retV += sa[i].substring(5);
	   }
	   }
		}
		return retV;
	}
	this.Utf8ToGb2312=function(str1){
		var substr = "";
		var a = "";
		var b = "";
		var c = "";
		var i = -1;
		i = str1.indexOf("%");
		if(i==-1){
		  return str1;
		}
		while(i!= -1){
			if(i<3){
				substr = substr + str1.substr(0,i-1);
				str1 = str1.substr(i+1,str1.length-i);
				a = str1.substr(0,2);
				str1 = str1.substr(2,str1.length - 2);
				if(parseInt("0x" + a) & 0x80 == 0){
					substr = substr + String.fromCharCode(parseInt("0x" + a));
				}
				else if(parseInt("0x" + a) & 0xE0 == 0xC0){ //two byte
					b = str1.substr(1,2);
					str1 = str1.substr(3,str1.length - 3);
					var widechar = (parseInt("0x" + a) & 0x1F) << 6;
					widechar = widechar | (parseInt("0x" + b) & 0x3F);
					substr = substr + String.fromCharCode(widechar);
				}
				else{
					b = str1.substr(1,2);
					str1 = str1.substr(3,str1.length - 3);
					c = str1.substr(1,2);
					str1 = str1.substr(3,str1.length - 3);
					var widechar = (parseInt("0x" + a) & 0x0F) << 12;
					widechar = widechar | ((parseInt("0x" + b) & 0x3F) << 6);
					widechar = widechar | (parseInt("0x" + c) & 0x3F);
					substr = substr + String.fromCharCode(widechar);
				}
			}
			else {
				substr = substr + str1.substring(0,i);
				str1= str1.substring(i);
			}
			i = str1.indexOf("%");
		}
		return substr+str1;
	}
}
//获取url中指定参数，用于从封神榜点出的播放页
function geturl(strName,url) {
    if(!strName) return location.toString();
    var str= url?url.toString():location.toString(); 
    var intPos = str.indexOf("?"); 
    var strRight = str.substr(intPos + 1); 
    var arrTmp = strRight.split("&"); 
    for(var i = 0; i < arrTmp.length; i++) { 
        var arrTemp = arrTmp[i].split("="); 
        if(arrTemp[0].toUpperCase() == strName.toUpperCase()) {
          if(arrTemp[1].indexOf("#")>=0) {
            return arrTemp[1].split("#")[0];
          }else{
            return arrTemp[1]; 
          }
        }
    } 
    return null;
}
//如果视频没有缩略图，使用默认缩略图
function img_onerr(obj){
	obj.src="http://image.jsbc.com/v_tvshow/jsbc_tvshow.jpg";
}
//播放页分享复制代码
function fxVideos(videoid){
	var vid=videoid;
	var fxblog=$('#fxblog');
	var fxhtml=$('#fxhtml');
	var fxurl=$('#fxurl');
	fxblog.attr('value','<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="480" height="400"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://www.jsbc.com/v/fplayer/v.swf?vid='+vid+'" /><param name="quality" value="high" /><embed src="http://www.jsbc.com/v/fplayer/v.swf?vid='+vid+'" quality="high" width="480" height="400" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>')
	fxhtml.attr('value','http://www.jsbc.com/v/fplayer/v.swf?vid='+vid);
	fxurl.attr('value',location.href);
	fxblog.focus(function(){
		$(this).blur();
	});
	fxhtml.focus(function(){
		$(this).blur();
	});
	fxurl.focus(function(){
		$(this).blur();
	});
}
function copyCode(id){
	var testCode=document.getElementById(id).value;
	if(copy2Clipboard(testCode)!=false){
		alert("生成的代码已经复制！");
	}
}
copy2Clipboard=function(txt){
	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安全限制限制您进行剪贴板操作，请打开’about:config’将signed.applets.codebase_principal_support’设置为true’之后重试，相对路径为firefox根目录/greprefs/all.js");
			return false;
		}
		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);
	}
}