﻿/*
 * Pomoho UI - Space
 *
 * Copyright (c) 2007 sorrycc@gmail.com (pomoho.com)
 * Date: 2007-10-22
 */
Pui.video = {
	init: function() {
		this.gotoLink();
		this.quickComment();
		this.autoThumb('.albumlist li img',78,58);
	},
	hideIntro: function() {
		var str = $('#Layout_1 .vp .v_intro').text();
	},
	share:function(link,title,content){
		var itieba_share = 'http://tieba.baidu.com/i/sys/share?link=' + link+'&type=video&title=' + title+'&content=' + content;
    	if (!window.open(itieba_share, 'itieba', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=626,height=436')) {
        	location.href = itieba_share;
    	}
	},
	gotoLink:function(){
		var vTitle=encodeURIComponent($('title').html().replace(/(^\s*)|(\s*$)/g, ""));
		var vLink=encodeURIComponent('http://home.pomoho.com/'+_space_user.username+'/'+flvid);
		var vContent=encodeURIComponent('http://video.pomoho.com/swf/out_player.swf?flvid='+flvid);
		var vSource=encodeURIComponent('爆米花网');
		var vSourceUrl=encodeURIComponent('http://www.pomoho.com/');
		var s='<span class="icos"><a id="renren" href="http://share.renren.com/share/buttonshare.do?link='+vLink+'&title='+vTitle+'" target="_blank" title="转贴至人人网">转贴至人人网</a><a id="kaixin" href="http://www.kaixin001.com/repaste/share.php?rurl='+vLink+'&rcontent='+vLink+'&rtitle='+vTitle+'" target="_blank" title="转贴至开心网">转贴至开心网</a><a id="sina" href="http://v.t.sina.com.cn/share/share.php?c=spr_web_bd_pomoho_weibo&url='+vLink+'&title='+vTitle+'&source='+vSource+'&sourceUrl='+vSourceUrl+'" target="_blank" title="转贴至新浪微博">转贴至新浪微博</a><a id="itieba" href="" onclick="Pui.video.share(\''+vLink+'\',\''+vTitle+'\',\''+vContent+'\');return false;" title="转贴至i贴吧">转贴至i贴吧</a></span>';
		$(s).appendTo('.video_info .handle');
		this.zz();
	},
	zz: function(mv) {
		var urlParm = "";
		var htmlcode = '';
		var vTitle=encodeURIComponent($('title').html().replace(/(^\s*)|(\s*$)/g, ""));
		var vLink=encodeURIComponent('http://home.pomoho.com/'+_space_user.username+'/'+flvid);
		var vContent=encodeURIComponent('http://video.pomoho.com/swf/out_player.swf?flvid='+flvid);
		var vSource=encodeURIComponent('爆米花网');
		var vSourceUrl=encodeURIComponent('http://www.pomoho.com/');
		var s = '';
		s += '<div id="ZZ" style="display:none;">';
		s += '	<div class="s1">';
		if (mv) {
			urlParm = "mvid";
			htmlcode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="396" id="object"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://video.pomoho.com/swf/mv_out_player.swf?mvid='+flvid+'" /><embed src="http://video.pomoho.com/swf/mv_out_player.swf?mvid='+flvid+'" quality="high" width="480" height="396" allowScriptAccess="always"/></object>';
			s += '		此节目地址（URL）<br /><input type="text" class="url" value="http://video.pomoho.com/mv/'+flvid+'.shtml" /><br />';
			s += '		把播放器显示到个人空间或Blog<br /><input type="text" class="url" value="http://video.pomoho.com/swf/mv_out_player.swf?mvid='+flvid+'" /><br />';
			s += '		HTML代码,适用于个人空间（或其他类型的Blog）<br /><input type="text" class="url" value="" /><br />';
			s += '		BBS代码<br /><input type="text" class="url" value="[flash]http://video.pomoho.com/swf/mv_out_player.swf?mvid='+flvid+'[/flash]" />';
		} else {
			urlParm = "flvid";
			htmlcode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="396" id="object"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://video.pomoho.com/swf/out_player.swf?flvid='+flvid+'" /><embed src="http://video.pomoho.com/swf/out_player.swf?flvid='+flvid+'" quality="high" width="480" height="396" allowScriptAccess="always"/></object>';

			if (String(window.location).match(/http:\/\/video\.dvod.*/)) {
				s += '		此节目地址（URL）<br /><input type="text" class="url" value="http://video.dvod.com.cn/news/'+flvid+'.shtml" /><br />';
			} else {
				s += '		此节目地址（URL）<br /><input type="text" class="url" value="http://home.pomoho.com/'+_space_user.username+'/'+flvid+'" /><br />';
			}
			s += '		把播放器显示到个人空间或Blog<br /><input type="text" class="url" value="http://video.pomoho.com/swf/out_player.swf?flvid='+flvid+'" /><br />';
			s += '		HTML代码,适用于个人空间（或其他类型的Blog）<br /><input type="text" class="url" value="" /><br />';
			s += '		BBS代码<br /><input type="text" class="url" value="[flash]http://video.pomoho.com/swf/out_player.swf?flvid='+flvid+'[/flash]" />';
		}
		s += '	</div>';
		s += '  <p><a href="" onclick="$(\'#ZZ\').slideUp();return false;">关闭</a></p>';
		s += '</div>';
		var vPath = '#VideoPlayer #Handle';
		$(vPath).after(s).find('.s4').click(function(){
			$('#ZZ').slideToggle('slow');
			this.blur();
			return false;
		});
		$('#ZZ .url').eq(2).attr('value', htmlcode).end().hover(function(){
			$(this).select();
		}, function(){
			$(this).blur();	
		});
	},
	quickComment:function(){
		
		$("#Handle .h_comment").click(function(){
			if($("#QuickComment").length>0){
				$(".f_v").show();
				$("#QuickComment").show();
				$("#Quicktextarea").focus();
				return
			}
			var str='';
			str+='<div class="f_v"></div>'
			str+='<div class="f_comment" id="QuickComment">';
			str+='<input type="text" value="" class="iText01" id="Quicktextarea"/>';
			str+='<input type="text" value="" class="iText02" id="QvalidText"/>';
			str+='<a title="看不清楚？请点击刷新验证码" href="javascript:GetValidCodeImg();"><img src="" id="validImg" class="valid"/></a>';
			str+='<a href="javascript:void(0)" class="iBtn01">提交</a>';
			str+='<a href="javascript:void(0)" class="iBtn02">取消</a><input type="submit" style="display:none" onsubmit="return false" />';
			str+='</div>';
			$("#Handle").after(str);
			$("#Quicktextarea").focus();
			setTimeout(GetValidCodeImg,100)
			$("#QuickComment .iBtn02").click(function(){
				$("#Quicktextarea").val("");
				$("#QvalidText").val("");
				$(".f_v").hide();
				$("#QuickComment").hide();	
			});
			
			$("#QvalidText").keyup(function(e){
				var event = window.event || e;
				if (event.keyCode == 13) {
					$(this).blur()
					$("#QuickComment .iBtn01").click();
				}
			});	
			$("#tb_validcode").keyup(function(e){
				var event = window.event || e;
				if (event.keyCode == 13) {
					$(this).blur()
					$('#Comment input[@type=submit]').click();
				}
			});	
			$('#QuickComment .iBtn01').click(function(){	
	
				textarea=window.textarea = $('#Quicktextarea');
				if ($.trim(textarea.val()) == ''){
					alert('评论内容不可为空！');
					$("#Quicktextarea").focus();
					return;
				}
				
				var QValidCode = "";
				if(document.getElementById("QvalidText") != null){
					QValidCode = document.getElementById("QvalidText").value;
					if ($.trim(QValidCode) == ''){
						alert('验证码不可为空！');
						if($.browser.msie)
							$('#QvalidText').focus();
						return;
					}
				}
				var scontent = textarea.val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->").replace("\n", " ");
				scontent = escape(scontent);
				if ($('body').attr('id') == 'SpaceAlbum_Detail') {
					Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=6&imdbid=" + imgid + "&content=" + scontent + "&validcode=" + QValidCode, {random:true});
				} else {
					Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=1&imdbid=" + flvid + "&content=" + scontent + "&validcode=" + QValidCode, {random:true});
				}
				var ct = Pui.pos.elementTop(document.getElementById('Comment'));
				//window.scrollTo(0, ct-30);
				//$('#Comment .cl, #Comment .cc').fadeTo('slow', 0.3);
				this.blur();
				flag_comment=1;
				$(".f_v").hide();
				$("#QuickComment").hide();
				setTimeout("Pui.video.commentReplyFill()", 1000);
				//$("#Quicktextarea").val("");
				$('#QvalidText').val("");
				setTimeout(GetValidCodeImg,100)
				
			});
			
		
			});
		
	},
	hideComment: function(num) {
		if (String(window.location).match(/http:\/\/home.*/)) {
			$('#Comment .mDocument').filter(':gt(19)').hide();
		} else {
			$('#Comment .mDocument').filter(':gt(19)').hide();
		}
		$('#Comment h3 span.count').html(20);
	},
	emotion: function() {
		var emotionID = 1;
		$('#Comment .emotion').find('.l').click(function() {
			if (emotionID >= 2) {
				$('#emotionBox').animate({left: -(450*(emotionID-2))}, 1000);
				if (emotionID == 2) {
					$('#Comment .l').removeClass('l_b').attr('title', '左边没有了');
				} else if (emotionID == 4) {
					$('#Comment .r').addClass('r_b').attr('title', '向右翻');
				}
				emotionID --;
			}
			this.blur();
			return false;
		}).end().find('.r').click(function() {
			if (emotionID <= 3) {
				$('#emotionBox').animate({left: -(450*emotionID)}, 1000);
				if (emotionID == 1) {
					$('#Comment .l').addClass('l_b').attr('title', '向左翻');
				} else if (emotionID == 3) {
					$('#Comment .r').removeClass('r_b').attr('title', '右边没有了');
				}
				emotionID ++;
			}
			this.blur();
			return false;
		}).end().find('div a').each(function() {
			$(this).click(function(){
				var tmp = $('#Comment textarea').val() + $(this).find('img').attr('src').replace(/.+\/(em\d+)\.gif/g, '[$1]');
				$('#Comment textarea').val(tmp);
				return false;
			});
		});
	},
	emotionWR: function() {
		var s = '';
		s += '<div style="position:relative;width:450px;height:60px;overflow:hidden;margin:5px auto;"><div id="emotionBox" style="position:absolute;left:0;top:0;width:1800px;">';
		var l = 'http://static.pomoho.com/images/em/';
		var alt = ['黑星打','大','泡','蹦','继续','狂','黑星殴','吹','捅','被殴','飞','嘘','赖','顶','变','滚球','生','膜拜','转','口','KI','鬼','抓狂','扯','流','闭嘴','HI','可爱','摇','躲','多','吉'];		
		for(var i=1; i<=4; i++) {
			s += '<div style="width:450px;float:left;text-align:center;">';
			for(var j=(i-1)*8+1; j<=i*8; j++) {
				if(j<=32) {
					s += '<a href="" title="'+alt[j-1]+'" style="margin:0 1px;"><img src="'+l+'em'+j+'.gif" height="50" width="50" /></a>';
				}
			}
			s += '</div>';
		}
		s += '</div></div>';
		s += '<a href="" class="l" title="左边没有了">向左翻</a><a href="" class="r r_b" title="向右翻">向右翻</a>';
		document.write(s);
		this.emotion();
		var c = $('.l_honor span').text();
		if($.trim(c) == '?'){//临时 过滤问号 by SMbey0nd @ 2008-10-28 15:49:20
			$('.l_honor span').text('无');
		}
	},
	commentReply: function() {
		SetValidCodeImg();
		$('#post_content').bind('focus',function(){CodeImgLoader()});
		timer_comment = null;
		$('#Comment input[@type=submit]').click(function(){	
			
			textarea = $('#Comment textarea');
			if ($.trim(textarea.val()) == '') {
				alert('评论内容不可为空！');
				textarea.focus();
				return;
			}
			var sValidCode = "";
			if(document.getElementById("tb_validcode") != null)
			{
				sValidCode = document.getElementById("tb_validcode").value;
				if ($.trim(sValidCode) == '') {
					alert('验证码不可为空！');
					return;
				}
			}
			var scontent = textarea.val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->");
			scontent = escape(scontent);
			if ($('body').attr('id') == 'SpaceAlbum_Detail') {
				Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=6&imdbid=" + imgid + "&content=" + scontent + "&validcode=" + sValidCode, {random:true});
			} else {
				if(_is_login){
				Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=1&imdbid=" + flvid + "&content=" + scontent + "&validcode=" + sValidCode, {random:true});
				var ct = Pui.pos.elementTop(document.getElementById('Comment'));
				window.scrollTo(0, ct-30);
				$('#Comment .cl, #Comment .cc').fadeTo('slow', 0.3);
				this.blur();
				setTimeout("Pui.video.commentReplyFill()", 1000);
				GetValidCodeImg();
				return false;}
				else{flag=6;Pui.newSH.loginfo();}
			}

		});
	},
	commentReplyFill: function() {
		var c = textarea.val().replace(/\[em(\d+)\]/g, "<img src='http://static.pomoho.com/images/em/em$1.gif' />");
		var u = _is_login ? '<a href="javascript:;">'+_user.nick+'</a>' : '游客';
		var s = '';
		s += '<div class="mDocument" style="_width:100%;">';
		s += '	<div class="photo"><img src="http://static.pomoho.com/static/images/photo_68.gif" alt="" /></div>';
		s += '	<div class="detail">';
		s += '		<span class="n_user">'+u+'</span>';
		s += '		<p class="text">'+c+'</p>';
		s += '	</div>';
		s += '	<div class="handle">';
		s += '		<span class="t_release">'+Pui.ui.gettime()+'</span>';
		s += '	</div>';
		s += '</div>';
		if($('#Comment h3').length == 0) {
			if (String(window.location).match(/http:\/\/home.*/)) {
				$('<p class="cc"><a href="javascript:;">查看全部</a>共<span>1</span>条评论</p>').prependTo('#span_video_review');
				$('<div class="cl">'+s+'</div>').prependTo('#span_video_review');
				$('<h3>对该视频的评论</h3>').prependTo('#span_video_review');
			} else {
				$('<p class="cc"><a href="javascript:;">查看全部</a>共<span>1</span>条评论</p>').prependTo('#Comment');
				$('<div class="cl">'+s+'</div>').prependTo('#Comment');
				$('<h3>对该视频的评论</h3>').prependTo('#Comment');
			}
		} else {
			$('#Comment .cl').prepend(s);
			$('#Comment .cl, #Comment .cc').fadeTo('slow', 1);
		}
		textarea.attr('value', '').focus();
	},
	collect: function() {
		Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=2&imdbid=" + flvid);
	},
	delblog: function(blogid) {
		if (window.confirm("确认要删除该条评论吗?")) { 	
			if ($('body').attr('id') == 'SpaceAlbum_Detail') {
				Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=4&blogid=" + blogid+"&imdbid=" + imgid);
			} else{
				Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=4&blogid=" + blogid+"&imdbid=" + flvid);
			}
		}
	},
	quote: function(bid) {
		var re_q_txt = document.getElementById("re_q_"+bid).value;
		document.getElementById("post_content").value = "[quote]"+re_q_txt+"[/quote]";
		$('#Comment textarea').focus();
	},
	Resize:function (im,nWidth,nHeight ){
		var obj=im||document.getElementById(im);
        var w , h , p1 , p2 ;
        p1 = nWidth / nHeight ;
        p2 = obj.width / obj.height ;
        w = 0 ; h = 0 ;
        if( p1 < p2 ){
            w = nWidth ;
            h = nWidth * ( 1 / p2 ) ;
        }
        else{
			if(obj.width<nWidth && obj.height<nHeight){w=obj.width;h=obj.height;}
			else{
            	h = nHeight ;
            	w = nHeight * p2 ;}
        }
        obj.width  = w ;
        obj.height = h ;
		obj.style.marginTop=(nHeight-h)/2+'px';
    },
	autoThumb:function(path,w,h){
		var _self=this;
		$(path).each(function(i){
			var preldimg=new Image();
			preldimg.onload=function(){setTimeout(function(){_self.Resize($(path)[i],w,h);preldimg=null;},50);}
			preldimg.src=$(path)[i].src;
		});	
	}
};

$.fn.currentVideo = function(option) {
	return this.find(option.c).each(function(){
		if($(this).find('.title a').attr('href').indexOf(flvid) != -1) {
			$(this).addClass('ac');
		}
	});
}


//by zhuxf 2008-3-3 评论验证码  type 1 - 视频 2 - 用户  3 - 专题
var ValidCodeURL = "http://www.pomoho.com/do/video/ValidCode.aspx?type=1";
function GetValidCodeImg(){ //图片点击事件 更换验证码

	if(typeof(imgid)!= "undefined"){
		if (document.getElementById("validImg")) {
			document.getElementById("validImg").src = ValidCodeURL + "&objid=" + imgid + "&ran=" + Math.random();
			if (document.getElementById("validcode")) {
				setTimeout(sameValid,200)
			}
		}
		else {
		document.getElementById("validcode").src = ValidCodeURL + "&objid=" + imgid + "&ran=" + Math.random();
		}
		
	}else{
		if(document.getElementById("validImg")){
			document.getElementById("validImg").src = ValidCodeURL + "&objid=" + flvid + "&ran=" + Math.random();
			//alert()
			if(document.getElementById("validcode"))
			setTimeout(sameValid,200)
			
		}else{
			document.getElementById("validcode").src= ValidCodeURL + "&objid=" + flvid + "&ran=" + Math.random();
		}
	}
}
function CodeImgLoader(){
	var s = '<a href="javascript:GetValidCodeImg();" title="看不清楚？请点击刷新验证码！" style="position:relative;top:6px;*top:4px;" ><img id="validcode" border=0  width="60" height="20" ></a>';
	$('#tb_validcode').after(s).removeAttr('onfocus');
	$('#post_content').unbind('focus');
	$('#post_content').click(function(){
		if($("#QuickComment").length>0){
		$(".f_v").hide();
		$("#QuickComment").hide();
		}
	})
	GetValidCodeImg()
}
function sameValid(){
	document.getElementById("validcode").src = document.getElementById("validImg").src;
}
function SetValidCodeImg()
{ 
	var ValidCodeHtml =  '';
	if(typeof(imgid)
 != "undefined")
	{
		ValidCodeHtml = '请输入验证码&nbsp;&nbsp;<input id="tb_validcode" onfocus="javascript:CodeImgLoader();" type="text" style="width:60px; border:1px #7B9EBD solid;margin:0 5px 0 0;" />';
	}
	else
	{
		ValidCodeHtml = '请输入验证码&nbsp;&nbsp;<input id="tb_validcode" type="text" onfocus="javascript:CodeImgLoader();" style="width:60px; border:1px #7B9EBD solid;margin:0 5px 0 0;" />';	
	}
 	
	var s = $('#Comment .commentAdd .form .submit').html();
	$('#Comment .commentAdd .form .submit').html(ValidCodeHtml + s);
}
function SendCallBack(v,sv)
{
	if(v == 0)
	{
		alert("您的验证码错误！");
	}
	if(v == -1)
	{
		alert("您的验证码已失效。请点击验证码图片，重新获取验证码！");
	}
	setTimeout("$('#Comment .mDocument').eq(0).remove();", 1000);
	setTimeout("textarea.attr('value', '"+sv+"').focus();", 1000);
	
}
function SendDoing()
			{	
				var n = Pui.cookie('LoginInfo');
				if(n)
				{
					var arr=n.split('$***$');
					var userid = arr[0].replace('LoginInfo=','');
					var content = $.trim($('#span_video_play h2').html());
					var videourl = document.location.href;
					var content = escape(content);
					var url = baseurl+"space/mydoingajax.aspx?opreatetype=add&writecontent=" +content+"&userid="+userid+"&videourl="+videourl;
					Pui.loadScript(url, {random:false});
				}
				else
				{
					alert("请先登录！");
				}
			}

