var preUrl = '';
//ie调用js不支持base 考虑匹配反斜杠获取他的目录级别, 从而定位相对路径
if($.browser.msie){
	//var pathLevel = window.location.href.split('/').length;
	//不带项目名
	var pathLevel = 4;
	//带项目名
	//var pathLevel = 5;
	var passNum = 3;
	if(4 == pathLevel){
		passNum = 2;
	}
	var path = window.location.pathname.split('/');
	var count = 0;
	for(count;count<path.length-passNum;count++){
		preUrl += '../';
	}
}

/**
 *  进入指定视频播放页
 * @param videoId
 * @return
 */
function showVideo(urlCode){
	window.location.href = preUrl + 'v/' + urlCode;
}

/**
 * 根据用户id获取他的视频列表
 * @param userId
 * @return
 */

function showVideoListByUser(userId){
	window.location.href = preUrl + 'video/showVideoListByUser.action?videoVO.userId=' + userId;
}

/**
 * 为访问失败的图片地址指定默认图片
 * @param obj
 * @param url
 * @return
 */
function defaultImg(obj, url){
	obj.src = url;
}

/**
 * 进入指定用户主页
 * @param friendId
 * @return
 */
function gotoFriendHome(friendId){
	if(logined){
		window.location.href = preUrl + 'video/friendHome.action?friendId=' + friendId;
	}else{
		myAlert('您还没有登录, 没有权限查看他的主页', 'info');
	}
}
 
/**
 * 进入指定用户好友列表页
 * @param friendId
 * @return
 */
function gotoFriendList(friendId){
	if(logined){
		window.location.href = preUrl + 'friend/friendList.action?userVO.userId=' + friendId;
	}else{
		myAlert('您还没有登录, 没有权限查看他的好友', 'info');
	}
}

/**
 * 好友请求审批
 * @param userId
 * @param type
 * @return
 */
function friendAudit(userId, type){
	window.location.href = preUrl + 'friend/friendAudit.action?friendVO.userId=' + userId + '&type=' + type;
}
var ifConfirm = false;
var currentFunction = '';

function  myConfirm(flag){
	if(flag){
		ifConfirm = true;
		eval(currentFunction);
		ifConfirm = false;
	}else{
		ifConfirm = false;
	}
}

function myAlert(message, type){
	var title = "&nbsp;&nbsp;";
	if("info" == type){
		title += "提示";
	}else if("error" == type){
		title += "错误";
	}else if("confirm" == type){
		title += "确认";
	}
	var loader=$("#div_maskContainer");
    if(loader.length==0){
    	var html = "<div id='div_maskContainer'><div id='div_Mask' ></div><div id='alertDiv'>"
    			 + "<div class='a1'>"
    			 + "<div class='whiteLine' style='width:386px; margin-left:1px;'></div>"
    			 + "<div class='a2'>" + title + "</div>"
    			 + "<div class='grayLine' style='width:386px; margin-left:1px;'></div>"
    			 + "<div class='a3'>" + message + "</div>"
    			 + "<div class='grayLine' style='width:386px; margin-left:1px;'></div>"
    			 + "<div class='a4'>";
    		if("confirm" == type){
    			html += "<input type='button' class='a5' onclick='hideAlert(); myConfirm(true);'/>"
    				 + "<input type='button' class='a6' onclick='hideAlert(); myConfirm(false);'/>";
    		}else{
    			html += "<input type='button' class='a5' onclick='hideAlert()'/>";
    		}
    		html += "</div></div></div><iframe id='T_iframe'></iframe></div>";
    	loader=$(html);
    	$("body").append(loader);

    	var w=$(window).width();
        var h=$(window).height();
        var bw=$(document.body).width();
        var bh=$(document.body).height();
        var sl = $(document).scrollLeft();
        var st = $(document).scrollTop();

        var divMask=$("#div_Mask");
        divMask.css("top",0).css("left",0).css("width",bw).css("height",bh);
        var alertDiv=$("#alertDiv");
        loader.show();
        var x=(w-alertDiv.width())/2 + sl;
        var y=(h-alertDiv.height())/2 + st;
        alertDiv.css("left",x);
        alertDiv.css("top",y);
        var T_iframe=$("#T_iframe");
        T_iframe.css("top",y).css("left",x).css("width","400px").css("height","150px");
    }
}

function hideAlert() {
	var loader=$("#div_maskContainer");
    if(loader.length==0) return ;
    loader.remove();
}

function deleteFriend(userId){
	if(!ifConfirm){
		currentFunction = 'deleteFriend(\'' + userId + '\')';
		myAlert('删除好友将不能恢复，是否继续？', 'confirm');
		return;
	}
	window.location.href = preUrl + 'friend/deleteFriend.action?friendVO.userId=' + userId;
}
var lastplay = '';
function playVideo(videoId, videoPath){
	var currentPlay = '#play_' + videoId;
	if(currentPlay != lastplay){
		if('' != lastplay){
			$(lastplay).hide();
			$(lastplay).html('');
			$(lastplay + '_img').show();
			$(lastplay + '_btn').hide();
		}
		$(currentPlay + '_img').hide();
		//var innerHTML = '<a href="' + videoPath + '" style="display:block;width:360px;height:270px; background-color:#000000;" id="player"></a>';
		var innerHTML = '<script type="text/javascript" src="player2/lib/swfobject.js"/>';
			innerHTML += '<script type="text/javascript">';
			innerHTML += 'var parameters = {';
			innerHTML += 'src: "' + videoPath + '",';
			innerHTML += 'autoPlay: "true",';
			innerHTML += 'verbose: true,';
			innerHTML += 'controlBarAutoHide: "false",';
			innerHTML += 'controlBarPosition: "bottom",';
			innerHTML += 'poster: "images/poster.png"';
			innerHTML += '};';
			innerHTML += 'swfobject.embedSWF(';
			innerHTML += '"player2/XpaiFlashPlayer.swf"';
			innerHTML += ', "XpaiFlashPlayer"';
			innerHTML += ', 360';
			innerHTML += ', 270';
			innerHTML += ', "10.1.0"';
			innerHTML += ', "player2/expressInstall.swf"';
			innerHTML += ', parameters';
			innerHTML += ', {';
			innerHTML += 'allowFullScreen: "true",';
			innerHTML += ' wmode: "opaque"';
			innerHTML += '}';
			innerHTML += ', {';
			innerHTML += 'name: "XpaiFlashPlayer"';
			innerHTML += '}';
			innerHTML += ');';
			innerHTML += '</script>';
			innerHTML += '<div id="XpaiFlashPlayer">';
			innerHTML += '<a href="http://get.adobe.com/flashplayer/">';
			innerHTML += '<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/>';
			innerHTML += '</a>';
			innerHTML += '</div>';

		$(currentPlay).html(innerHTML);
		//flowplayer("player", "player/flowplayer-3.2.5.swf");
		
		$(currentPlay).show();
		$(currentPlay + '_btn').show();
		lastplay = currentPlay;
	}
}

function closeVideo(videoId){
	var currentPlay = '#play_' + videoId;
	$(currentPlay).hide();
	$(currentPlay).html('');
	$(currentPlay + '_btn').hide();
	$(currentPlay + '_img').show();
	lastplay = '';
}

function gotoPageN(){
	var regex  = /^([1-9][0-9]*)$/;
	var targetPage = $('#gotoPage').val();
	var maxPage = $('#maxPage').val();
	var form = $('#pageTagForm');
	if(regex.test(targetPage) && (Number(targetPage) <= Number(maxPage))){
		form.submit();
	}else{
		myAlert('页码输入错误', 'info');
		return false;
	}
}
var comment_request_num = 15;
function showMoreComment(urlCode){
	if(eval('comment_loading_' + urlCode)){
		if(eval('comment_next_' + urlCode)){
			myAlert('评论加载中, 请稍候', 'info');
		}
		$('#moreComment_' + urlCode + '_' + eval('comment_current_' + urlCode + '+1')).show();
		eval('comment_next_' + urlCode + '=true');
		return;
	}else{
		eval('comment_loading_' + urlCode + '=true');
	}
	$('#moreComment_' + urlCode + '_' + eval('comment_current_' + urlCode)).show();
	if(eval('comment_current_' + urlCode + '*' + comment_request_num + '+20') >= eval('comment_max_' + urlCode)){
		$('#comment_more_' + urlCode).hide();
		return;
	}
	if(20 < eval('comment_max_' + urlCode) && eval('comment_current_' + urlCode + '*' + comment_request_num + '+20') < eval('comment_max_' + urlCode)){
		var newDiv = '<div id="moreComment_' + urlCode + '_' + eval('comment_current_' + urlCode + '+1') + '" class="commentUnit" style="background:url(\'image/onLoad.gif\') no-repeat center; display:none;"></div>';
		$('#commentDiv_' + urlCode).append(newDiv);
	}
	eval('comment_skip_' + urlCode + '=' + 'comment_current_' + urlCode + '*' + comment_request_num + '+5');
	var param = 'commentVO.urlCode=' + urlCode + '&ajaxSkip=' + eval('comment_current_' + urlCode + '*' + comment_request_num + '+20') + '&ajaxMax=' + comment_request_num;
	$.ajax({
		url : 'comment/showMoreComment.action',
		type:'post',
		async: true,
		data:param,
		success:function(result){
			var s = $.trim(result);
			if('false' == s){
				$('#moreComment_' + urlCode + '_' + eval('comment_current_' + urlCode + '+1')).remove();
				eval('comment_loading_' + urlCode + '=false');
			}else{
				var jsonObj = eval('(' + s + ')');
				var parentDiv = $('#moreComment_' + urlCode + '_' + eval('comment_current_' + urlCode + '+1'));
				//创建div
				var index = 0;
				for(index=0;index<jsonObj.length;index++){
					
					var commentUnit = $('<div></div>');
					commentUnit.addClass('commentUnit');
					commentUnit.css('border-top', '#e4e4e4 1px dashed');
					
					var img = $('<div></div>');
					img.addClass('img');
					if('' == jsonObj[index].userId){
						img.html('<img src="image/guest.gif" alt="头像" width="50px" height="50px" style="cursor:default;"/>');
					}else{
						img.html('<img src="' + jsonObj[index].headImage + '" alt="头像" width="50px" height="50px" onclick="showVideoListByUser(\'' + jsonObj[index].userId + '\')" onerror="defaultImg(this, \'image/guest.gif\')"/>');
					}
					commentUnit.append(img);
					
					var rightDiv = $('<div></div>');
					rightDiv.addClass('normalFloat');
					rightDiv.css('width', '370px');
					
					var author = $('<div></div>');
					author.addClass('author');
					author.html(jsonObj[index].nickName + '&nbsp;&nbsp;<font style="color:#999;">' + jsonObj[index].commentTime + '</font>');
					rightDiv.append(author);
					
					var comment = $('<div>' + jsonObj[index].commentTxt + '</div>');
					comment.addClass('comment');
					rightDiv.append(comment);
					
					commentUnit.append(rightDiv);
					
					var normalFloat = $('<div></div>');
					normalFloat.addClass('normalFloat');
					normalFloat.css('width', '450px');
					normalFloat.css('height', '10px');
					normalFloat.css('overflow', 'hidden');
					commentUnit.append(normalFloat);
					
					var clear = $('<div></div>');
					clear.addClass('clear');
					commentUnit.append(clear);
					
					parentDiv.append(commentUnit);
				}
				//创建div结束 
				parentDiv.css('background', '');
				eval('comment_current_' + urlCode + '+=1');
				eval('comment_loading_' + urlCode + '=false');
				if(eval('comment_next_' + urlCode)){
					eval('comment_next_' + urlCode + '=false');
					$('#comment_more_a_' + urlCode).click();
				}
			}
		},
		error:function(){
			alert('error');
			eval('comment_loading_' + urlCode + '=false');
		}
	});
}

function unHTML(str){
	while(-1 != str.indexOf('\n')){
		str = str.replace('\n', '<br/>');
	}
	while(-1 != str.indexOf(' ')){
		str = str.replace(' ', '&nbsp;');
	}
	return str;
}

var video_auto_max = 3;
var video_auto_current = 0;
var video_query_position = 300;
var video_request_num = 10;
var video_current = 0;
var video_loading = false;
var video_next = false;
function getPosition(type, url, params){
	var st = $(document).scrollTop();
	var bh=$(document.body).height();
	var h=$(window).height();
	
	var toBottom = bh - h - st;

	if(video_query_position > toBottom && (-1 == video_auto_max || video_auto_current < video_auto_max)){
		//保证滚动条高度不变
		var currentScrollTop = $(document).scrollTop();
		$('#moreVideo_' + type + '_' + video_current).show();
		$(document).scrollTop(currentScrollTop);
		if(20 >= video_max){
			return;
		}
		if(video_loading){
			$('#moreVideo_' + type + '_' + (video_current+1)).show();
			video_next = true;
			return;
		}
		video_auto_current += 1;
		if(video_max > (20 + video_current * video_request_num) && video_auto_max <= video_auto_current){
			$('#video_more').show();
		}
		video_loading = true;
		showMoreVideo(type, url, params);
	}
}

function clickShowMoreVideo(type, url, params){
	video_auto_current = 0;
	$('#video_more').hide();
	$(document).scrollTop($(document).scrollTop()-1);
}

function showMoreVideo(type, url, params){
	if(video_max <= (20 + video_current * video_request_num)){
		return;
	}
	var newDiv = $('<div id="moreVideo_' + type + '_' + (video_current+1) + '" class="videoContainer' + type + '" style="display:none; background:url(\'image/onLoad.gif\') no-repeat center;">');
	$('#videoDiv').append(newDiv);
	var param = 'ajaxSkip=' + (20 + video_current * video_request_num) + '&ajaxMax=' + video_request_num;
	if('' != params){
		param += params;
	}
	$.ajax({
		url : url,
		type:'post',
		async: true,
		data:param,
		success:function(result){
			var s = $.trim(result);
			if('false' == s){
				$('#moreVideo_' + type + '_' + (video_current+1)).remove();
				video_loading = false;
			}else if('login' == s){
				myAlert('登录超时, 请重新登录', 'error');
			}else{
				var jsonObj = eval('(' + s + ')');
				//创建div
				if(1 == type){
					createVideoDivType1(jsonObj);
				}else if(2 == type){
					createVideoDivType2(jsonObj);
				}
				video_current += 1;
				video_loading = false;
				if(video_max > (10 + video_current * video_request_num) && video_auto_max <= video_auto_current){
					$('#video_more').show();
				}
				if(video_next){
					video_next = false;
					getPosition(type, url, params);
				}
			}
		},
		error:function(){
			alert('error');
			video_loading = false;
		}
	});
}

function createVideoDivType1(jsonObj){
	var parentDiv = $('#moreVideo_1_' + (video_current+1));
	parentDiv.css('background', '');
	
	var index = 0;
	for(index=0;index<jsonObj.length;index++){
		var unitDiv = $('<div style="margin-top:0px; border-top:#e4e4e4 1px dashed;"></div>');
		unitDiv.addClass('unitDiv');
		
		var normalFloat = $('<div></div>');
		normalFloat.addClass('normalFloat');
		normalFloat.css('width', '343px');
		normalFloat.css('height', '10px');
		unitDiv.append(normalFloat);
		
		var left = $('<div></div>');
		left.addClass('left');
		
		var img = $('<div onclick="showVideoListByUser(\'' + jsonObj[index].userId + '\')"></div>');
		img.addClass('img');
		img.html('<img src="' + jsonObj[index].headImage + '" alt="头像" width="60px" height="56px" onerror="defaultImg(this, \'image/guest.gif\')"/>');
		left.append(img);
		unitDiv.append(left);
		
		var right = $('<div></div>');
		right.addClass('right');
		
		var title = $('<div><span class="author">' + jsonObj[index].nickName + '</span></div>');
		title.addClass('title');
		right.append(title);
		
		var title2 = $('<div title="' + jsonObj[index].videoTitle + '">' + jsonObj[index].subTitle + '</div>');
		title2.addClass('title');
		right.append(title2);
		
		var detail = $('<div>观看次数：' + jsonObj[index].views + '&nbsp;<font class="comment">(评论' + jsonObj[index].commentTimes + ')</font></div>');
		detail.addClass('detail');
		right.append(detail);
		
		var detail2 = $('<div>' + jsonObj[index].dateFromNow + '</div>');
		detail2.addClass('detail');
		right.append(detail2);
		var img2 = $('<div onclick="showVideo(\'' + jsonObj[index].urlCode + '\')" style="background-color: #999;"></div>');
		img2.addClass('img');
		var img2HTML = '<div class="imgRelative">';
		img2HTML += '<img src="' + jsonObj[index].imgURL + '" alt="视频截图" width="208px" height="98px" onerror="defaultImg(this, \'image/noVideoImg.jpg\')"/>';
		img2HTML += '<div class="timeDiv">';
		if(0 == jsonObj[index].videoType){
			img2HTML += '正在发生';
		}else{
			img2HTML += jsonObj[index].videoLengthStr;
		}
		img2HTML += '</div></div>';
		img2.html(img2HTML);
		right.append(img2);
		
		unitDiv.append(right);
		parentDiv.append(unitDiv);
	}
}

function createVideoDivType2(jsonObj){
	var parentDiv = $('#moreVideo_2_' + (video_current+1));
	parentDiv.css('background', '');
	
	var index = 0;
	for(index=0;index<jsonObj.length;index++){
		var unit2Div = $('<div style="margin-top:0px; border-top:#e4e4e4 1px solid;">');
		unit2Div.addClass('unit2Div');
		
		var blankDiv = $('<div style="width:343px; height:10px; overflow:hidden;"></div>');
		unit2Div.append(blankDiv);
		
		var left = $('<div></div>');
		left.addClass('left');
		
		var img = $('<div onclick="showVideoListByUser(\'' + jsonObj[index].userId + '\')"></div>');
		img.addClass('img');
		img.html('<img src="' + jsonObj[index].headImage + '" alt="头像" width="60px" height="56px" onerror="defaultImg(this, \'image/guest.gif\')"/>');
		left.append(img);
		unit2Div.append(left);
		
		var right = $('<div></div>');
		right.addClass('right');
		
		var titleHTML = '';
		titleHTML += '<table cellpadding="0" cellspacing="0" width="100%">';
		titleHTML += '<tr>';
		titleHTML += '<td title="' + jsonObj[index].videoTitle + '">';
		titleHTML += '<span class="author">' + jsonObj[index].nickName + ':</span>' + jsonObj[index].videoTitle;
		titleHTML += '</td>';
		titleHTML += '<td width="20px">';
		titleHTML += '<div id="del_' + jsonObj[index].videoId + '" onclick="deleteVideo(\'' + jsonObj[index].videoId + '\')" class="del">';
		titleHTML += '</div>';
		titleHTML += '</td>';
		titleHTML += '</tr>';
		titleHTML += '</table>';
		
		var title = $('<div>' + titleHTML + '</div>');
		title.addClass('title2');
		right.append(title);
		
		var detail2HTML = '';
		detail2HTML += '<table cellpadding="0" cellspacing="0" width="100%">';
		detail2HTML += '<tr>';
		detail2HTML += '<td>';
		detail2HTML += jsonObj[index].dateFromNow;
		detail2HTML += '</td>';
		detail2HTML += '<td width="30px">';
		detail2HTML += '<a class="blue" id="play_' + jsonObj[index].videoId + '_btn" style="display:none;" href="javascript: closeVideo(\'' + jsonObj[index].videoId + '\')">收起</a>';
		detail2HTML += '</td>';
		detail2HTML += '</tr>';
		detail2HTML += '</table>';

		var detail2 = $('<div>' + detail2HTML + '</div>');
		detail2.addClass('detail2');
		right.append(detail2);
		
		var img2 = $('<div id="play_' + jsonObj[index].videoId + '_img" onclick="playVideo(\'' + jsonObj[index].videoId + '\', \'' + jsonObj[index].videoPath + '\')" style="background-color: #999;"></div>');
		img2.addClass('img');
		var img2HTML = '<div class="imgRelative">';
		img2HTML += '<img src="' + jsonObj[index].imgURL + '" alt="视频截图" width="198px" height="108px" onerror="defaultImg(this, \'image/noVideoImg.jpg\')"/>';
		img2HTML += '<div class="timeDiv">';
		if(0 == jsonObj[index].videoType){
			img2HTML += '正在发生';
		}else{
			img2HTML += jsonObj[index].videoLengthStr;
		}
		img2HTML += '</div></div>';
		img2.html(img2HTML);
		right.append(img2);
		
		var playContainer2 = $('<div id="play_' + jsonObj[index].videoId + '"></div>');
		playContainer2.addClass('playContainer2');
		right.append(playContainer2);
		
		var clear = $('<div></div>');
		clear.addClass('clear');
		right.append(clear);
		
		unit2Div.append(right);
		
		//var playContainer = $('<div id="play_' + jsonObj[index].videoId + '"></div>');
		//playContainer.addClass('playContainer');
		//unit2Div.append(playContainer);

		var bottom = $('<div></div>');
		bottom.addClass('bottom');

		var scriptHTML = '<script type="text/javascript">';
		scriptHTML += 'var comment_max_' + jsonObj[index].urlCode + ' = ' + jsonObj[index].commentTimes + ';';
		scriptHTML += 'var comment_current_' + jsonObj[index].urlCode + ' = 0;';
		scriptHTML += 'var comment_loading_' + jsonObj[index].urlCode + ' = false;';
		scriptHTML += 'var comment_next_' + jsonObj[index].urlCode + ' = false;';
		scriptHTML += '</script>';
		
		var bottomHTML = '<table cellpadding="0" cellspacing="0" width="100%">';
		bottomHTML += '<tr><td width="20px">&nbsp;</td><td width="60px">已炫享到:</td><td width="17px">';
		if('' != jsonObj[index].shareToRR){
			bottomHTML += '<div style="width:15px; height:15px;background:url(\'image/logo_rr.jpg\') no-repeat;"></div>';
		}else{
			bottomHTML += '&nbsp';
		}
		bottomHTML += '</td><td width="17px">';
		if('' != jsonObj[index].shareToXLWB){
			bottomHTML += '<div style="width:15px; height:15px;background:url(\'image/logo_xlwb.jpg\') no-repeat;"></div>';
		}else{
			bottomHTML += '&nbsp';
		}
		bottomHTML += '</td><td width="17px">';
		if('' != jsonObj[index].shareToTXWB){
			bottomHTML += '<div style="width:15px; height:15px;background:url(\'image/logo_txwb.jpg\') no-repeat;"></div>';
		}else{
			bottomHTML += '&nbsp';
		}
		bottomHTML += '</td>';
		bottomHTML += '<td width="40px" align="right">状态：</td>';
		bottomHTML += '<td width="70px">';
		if(null != jsonObj[index].type && '10' == jsonObj[index].type){
			bottomHTML += '<select id="videoRight_' + jsonObj[index].videoId + '" style="height:20px;" onchange="changeVideoRight(\'' + jsonObj[index].videoId + '\')">';
			bottomHTML += '<option value="0"';
			if(0 == jsonObj[index].videoRight){
				bottomHTML += ' selected="selected"';
			}
			bottomHTML += '>所有人可见</option>';
			bottomHTML += '<option value="1"';
			if(1 == jsonObj[index].videoRight){
				bottomHTML += ' selected="selected"';
			}
			bottomHTML += '>好友可见</option>';
			bottomHTML += '<option value="2"';
			if(2 == jsonObj[index].videoRight){
				bottomHTML += ' selected="selected"';
			}
			bottomHTML += '>保密</option>';
			bottomHTML += '</select>';
		}else{
			if(0 == jsonObj[index].videoRight){
				bottomHTML += '所有人可见';
			}else if(1 == jsonObj[index].videoRight){
				bottomHTML += '好友可见';
			}else if(2 == jsonObj[index].videoRight){
				bottomHTML += '保密';
			}
		}
		bottomHTML += '</td><td>&nbsp;</td><td width="100px">观看次数：';
		bottomHTML += jsonObj[index].views;
		bottomHTML += '</td><td width="70px">';
		bottomHTML += '<a class="blue" href="javascript: toggleComment(\'' + jsonObj[index].videoId + '\')">评论(' + jsonObj[index].commentTimes + ')</a>';
		bottomHTML += '</td></tr></table>';
		bottomHTML += scriptHTML;

		bottom.html(bottomHTML);
		unit2Div.append(bottom);
		
		var commentContainer = $('<div id="commentContainer_' + jsonObj[index].videoId + '"></div>');
		commentContainer.addClass('commentContainer');
		
		var commentHead = $('<div></div>');
		commentHead.addClass('commentHead');
		commentHead.html('我来说两句');
		commentContainer.append(commentHead);
		
		var commentDiv = $('<div></div>');
		commentDiv.addClass('commentDiv');
		commentDiv.html('<textarea id="commentTxt_' + jsonObj[index].urlCode + '" class="commentTxt"></textarea>');
		commentContainer.append(commentDiv);
		
		var detail4 = $('<div></div>');
		detail4.addClass('detail4');
		detail4.html('<div class="publishBtn" onclick="postComment(\'' + jsonObj[index].urlCode + '\', \'' + jsonObj[index].userId + '\', \'' + jsonObj[index].videoTitle + '\')">发表评论</div><div class="commentResult"></div>');
		commentContainer.append(detail4);
		
		var commentUnit = $('<div id="commentDiv_' + jsonObj[index].urlCode + '"></div>');
		commentUnit.addClass('commentUnit');
		
		var commentList = jsonObj[index].commentList;
		
		var commentUnit2Container = $('<div id="moreComment_' + jsonObj[index].urlCode + '_0" style="display:none;">');
		commentUnit2Container.addClass('commentUnit');
		
		var j = 0;
		for(j=0;j<commentList.length;j++){
			var commentUnit2 = $('<div style="border-top:#e4e4e4 1px dashed;"></div>');
			commentUnit2.addClass('commentUnit');

			var subImg = $('<div></div>');
			subImg.addClass('img');
			if('' == commentList[j].userId){
				subImg.html('<img src="image/guest.gif" alt="头像" width="50px" height="50px" style="cursor:default;"/>');
			}else{
				subImg.html('<img src="' + commentList[j].headImage + '" alt="头像" width="50px" height="50px" onclick="showVideoListByUser(\'' + commentList[j].userId + '\')" onerror="defaultImg(this, \'image/guest.gif\')"/>');
			}
			commentUnit2.append(subImg);
			
			var subRightDiv = $('<div></div>');
			subRightDiv.addClass('normalFloat');
			subRightDiv.css('width', '370px');
			
			var subAuthor = $('<div></div>');
			subAuthor.addClass('author');
			subAuthor.html(commentList[j].nickName + '&nbsp;&nbsp;<font style="color:#999;">' + commentList[j].commentTime + '</font>');
			subRightDiv.append(subAuthor);
			
			var subComment = $('<div>' + commentList[j].commentTxt + '</div>');
			subComment.addClass('comment');
			subRightDiv.append(subComment);
			
			commentUnit2.append(subRightDiv);
			
			var subNormalFloat = $('<div></div>');
			subNormalFloat.addClass('normalFloat');
			subNormalFloat.css('width', '450px');
			subNormalFloat.css('height', '10px');
			subNormalFloat.css('overflow', 'hidden');
			commentUnit2.append(subNormalFloat);
			
			var subClear = $('<div></div>');
			subClear.addClass('clear');
			commentUnit2.append(subClear);
			
			if(5 <= j){
				commentUnit2Container.append(commentUnit2);
			}else{
				commentUnit.append(commentUnit2);
			}
			if(commentList.length-1 == j && 5 < commentList.length){
				commentUnit.append(commentUnit2Container);
			}
		}
		commentContainer.append(commentUnit);
		
		if(5 < jsonObj[index].commentTimes){
			var showMoreComment = $('<div id="comment_more_' + jsonObj[index].urlCode + '"></div>');
			showMoreComment.addClass('showMoreComment');
			showMoreComment.html('<a id="comment_more_a_' + jsonObj[index].urlCode + '" onclick="showMoreComment(\'' + jsonObj[index].urlCode + '\')" href="javascript: void(0);">查看更多评论</a>');
			commentContainer.append(showMoreComment);
		}
		
		unit2Div.append(commentContainer);
		
		var clear2 = $('<div></div>');
		clear2.addClass('clear');
		unit2Div.append(clear2);
		
		parentDiv.append(unit2Div);
	}
}

function showLetterUserList(){
	window.location.href = preUrl + 'letter/showLetterUserList.action';
}

function letterReply(letterSeq, toUserId){
	var letterTxt = $('#letterTxt_' + letterSeq).val();
	if('' == letterTxt){
		myAlert('请输入私信内容', 'info');
		$('#letterTxt_' + letterSeq).focus();
		return;
	}
	var param = 'letterVO.toUserId=' + toUserId + '&letterVO.replyLetterSeq=' + letterSeq + '&letterVO.letterTxt=' + letterTxt;
	mask.show("回复中, 请稍候...");
	$.ajax({
		url : 'letter/newLetter.action',
		type:'post',
		async: true,
		data:param,
		success:function(result){
			var s = $.trim(result);
			if('false' == s){
				myAlert('回复出错, 请稍后重试', 'error');
			}else if('login' == s){
				myAlert('登录超时, 请重新登录', 'error');
			}else{
				$('#div_loading').css('background-image', 'url("")');
				$('#div_loading').css('padding-left', '5px');
				$('#div_loading').css('color', '#ff7d00');
				$('#div_loading').html('回复成功');
				//window.setTimeout('mask.hide();', 2000);
				window.location.href = preUrl + 'letter/showLetterUserList.action';
			}
		},
		error:function(){
			alert('error');
		}
	});
}

function showLetterList(toUserId){
	window.location.href = preUrl + 'letter/showLetterList.action?letterVO.toUserId=' + toUserId;
}

function deleteLetter(letterSeq){
	if(!ifConfirm){
		currentFunction = 'deleteLetter(\'' + letterSeq + '\')';
		myAlert('删除私信将不能恢复，是否继续？', 'confirm');
		return;
	}
	var param = 'letterVO.letterSeq=' + letterSeq;
	mask.show("删除中, 请稍候...");
	$.ajax({
		url : 'letter/deleteLetter.action',
		type:'post',
		async: true,
		data:param,
		success:function(result){
			var s = $.trim(result);
			$('#div_loading').css('background-image', 'url("")');
			$('#div_loading').css('padding-left', '5px');
			$('#div_loading').css('color', '#ff7d00');
			if('false' == s){
				$('#div_loading').html('删除失败,请稍后重试');
			}else if('login' == s){
				$('#div_loading').html('登录超时, 请重新登录');
			}else{
				$('#div_loading').html('删除成功');
				$('#unit_' + letterSeq).remove();
			}
			window.setTimeout('mask.hide();', 2000);
		},
		error:function(){
			alert('error');
		}
	});
}

function showFavoriteList(){
	window.location.href = preUrl + 'favorite/showFavoriteList.action';
}

function deleteFavorite(favoriteId){
	window.location.href = preUrl + 'favorite/deleteFavorite.action?favoriteVO.favoriteId=' + favoriteId;
}

function addFavorite(urlCode){
	var param = 'favoriteVO.urlCode=' + urlCode;
	$.ajax({
		url : 'favorite/addFavorite.action',
		type:'post',
		async: true,
		data:param,
		success:function(result){
			var s = $.trim(result);
			if('false' == s){
				alert('false');
			}else if('login' == s){
				myAlert('登录超时, 请重新登录', 'error');
			}else{
				alert('ok~!');
			}
		},
		error:function(){
			alert('error');
		}
	});
}

function getCitys(){
	var param = 'provinceVO.provinceName=' + $('#province').val();
	var selected;
	$.ajax({
		url : 'area/getCityByProvinceName.action',
		type:'post',
		async: true,
		data:param,
		success:function(result){
			var s = $.trim(result);
			if('false' == s){
				myAlert('获取城市信息失败', 'error');
			}else{
				var jsonObj = eval('(' + s + ')');
				$('#city option').remove();
				var index = 0;
				for(index=0;index<jsonObj.length;index++){
					if('' != userCity && userCity == jsonObj[index].cityName){
						selected = ' selected="selected"';
					}else {
						selected = '';
					}
					$('<option value="' + jsonObj[index].cityName + '"' + selected + '>' + jsonObj[index].cityName + '</option>').appendTo('#city');
				}
			}
		},
		error:function(){
			alert('error');
		}
	});
}

function changeBg(obj, color){
	obj.style.backgroundColor = color;
}

function deleteVideo(videoId){
	if(!ifConfirm){
		currentFunction = 'deleteVideo(\'' + videoId + '\')';
		myAlert('删除视频将不能恢复，是否继续？', 'confirm');
		return;
	}
	window.location.href = preUrl + 'video/deleteVideo.action?videoVO.videoId=' + videoId;
}

function changeVideoRight(videoId){
	var param = 'videoVO.videoId=' + videoId + '&videoVO.videoRight=' + $('#videoRight_' + videoId).val();
	$.ajax({
		url : 'video/changeVideoRight.action',
		type:'post',
		async: true,
		data:param,
		success:function(result){
			var s = $.trim(result);
			if('false' == s){
				myAlert('修改视频访问权限失败, 请稍后重试', 'error');
			}else if('true' == s){
				myAlert('修改视频访问权限成功', 'info');
			}else if('login' == s){
				myAlert('登录已过期, 请重新登录', 'info');
			}else{
				myAlert('修改视频访问权限异常, 请稍后重试', 'error');
			}
		},
		error:function(){
			myAlert('修改视频访问权限异常, 请稍后重试', 'error');
		}
	});
}

var maxWords = 100;
function wordCount(obj, type){
	var words = obj.value;
	if(maxWords-words.length < 0){
		$('#' + type).html('已经超过' + (words.length-maxWords) + '个字');
	}else{
		$('#' + type).html('还能输入' + (maxWords-words.length) + '个字');
	}
}
