var ChatType = {
	"PERSON": 0,
	"GROUP": 1
}; // 0 - 个人聊天；1 - 群组聊天
var imServer = getParameter("imserver");
var lvid = getParameter("lvid");
var groupId = getParameter("groupid");
var tolvid = getParameter("tolvid");
var toChatname = getParameter("tonickname");
var groupname = getParameter("groupname");
var sign = getParameter("sign");
imServer = getImServer(imServer);
var msgDateArray = {};
var chatType = tolvid ? ChatType.PERSON : ChatType.GROUP;
var userNickName;
var pageNo = 1;
var pageSize = 60;
var pageCount = 0;
var recordContainer; //聊天记录容器
var chatHeight;
var chatSearchkey;
var searchPageNo = 1;
var chatname; //与谁聊天名称
var timepar = -1; //日期秒数
var mydate = new Date();
var textY = mydate.getFullYear(),
	textM = mydate.getMonth() + 1,
	textD = mydate.getDate();
var projectCache = {}; //项目列表缓存 
var pageFlag = 'history'; //页面 
var ctrlC = true; //是否按下了ctrl+c
/*分页按钮的四个href路径*/
var firstPage_href = "javascript:loadFirstPageMsg()",
	beforePage_href = "javascript:loadBeforePageMsg()",
	prePage_href = "javascript:loadPrePageMsg()",
	lastPage_href = "javascript:loadTotalPageMsg()";
var firstPage_hrefSear = "javascript:loadFirstPageMsgSear()",
	beforePage_hrefSear = "javascript:loadBeforePageMsgSear()",
	prePage_hrefSear = "javascript:loadPrePageMsgSear()",
	lastPage_hrefSear = "javascript:loadTotalPageMsgSear()";
/* 进行窗口大小自适应*/
$(window).resize(function() {
	reSize();
});
$(document).ready(function() {
	if(groupId == -1 || tolvid == -1) {
		$('.mesRecFoot').hide();
		$('.record').css({
			'overflow': 'hidden',
			'margin-top': '35px',
			'background': 'url(../images/empty.png) no-repeat center 50%'
		});
	}
	chatname = chatType == ChatType.GROUP ? groupname : toChatname;
	if(chatname) {
		$('.record_per b').text(chatname);
	}
	//去除鼠标中间滚轮的点击事件
	$(".info-none").mousedown(function(e) {
		if(2 == e.which) {
			return false;
		};
	});
	$(window).mousedown(function(event, rig) {
		$("img").removeClass("imgcutbo");
		var target = event.target;
		selContent(event);
		var imgMd5 = "",
			faceSrc = '';
		if(target.nodeName.toLowerCase() == "img") {
			if(event.which == 1 || event.which == 3) {
				$(target).not('.linkInfo img,.atMsgInfo img').addClass('imgcutbo');
				imgMd5 = $(target).attr("md5");
				if(!imgMd5) {
					faceSrc = $(target).attr("src");
				}
				if(isSelect() && window.getSelection().anchorOffset > 0 && window.getSelection().toString() != '') {
					window.getSelection().removeAllRanges();
				}
			}
		}
		if(event.which == 3 || rig == 'right') {
			var isSelectStatus = isSelect() || imgMd5 || faceSrc ? true : false;
			if(imgMd5 && isSelect()) {
				imgMd5 = '';
			}
			if($(target).parents().hasClass('projectCont')) {
				return;
			}
			var params = '{lvid:' + lvid + ', tolvid:' + tolvid + ', groupid:' + groupId + ', "select": ' + isSelectStatus + ', "img":"' + (imgMd5 || "") + '", "face":"' + (faceSrc || "") + '"}';
			sendCommand('{"command":9017, "params":' + params + '}');
		}
	});
	//控制键盘按下ctrl c/a
	$(document).on('keydown', function(e) {
		if(e.keyCode >= 37 && e.keyCode <= 40 || e.keyCode == 65) {
			keyUpOrDown = true;
			return true;
		}
		var k = e.keyCode;
		var kStatus = false;
		switch(k) {
			case 67: //c
				kStatus = true;
				if(ctrlC && !isSelect()) {
					ctrlC = false;
					var selImgMd5 = $('.imgcutbo').attr('md5');
					if(selImgMd5) {
						var params = '{lvid:' + lvid + ', tolvid:' + tolvid + ', groupid:' + groupId + ', "img":"' + selImgMd5 + '"}';
						sendCommand('{"command":9022, "params":' + params + '}');
						break;
					}
					var selFaceSrc = $('.imgcutbo').attr('src');
					if(selFaceSrc) {
						var params = '{lvid:' + lvid + ', tolvid:' + tolvid + ', groupid:' + groupId + ', "face":"' + selFaceSrc + '"}';
						sendCommand('{"command":9027, "params":' + params + '}');
					}
				}
				break;
			default:
				kStatus = false;
				break;
		}
		return kStatus;
	});
	//控制键盘按下ctrl c/a
	$(document).on('keyup', function(e) {
		if(e.keyCode >= 37 && e.keyCode <= 40) {
			keyUpOrDown = false;
			return true;
		}
		if(e.keyCode == 67) {
			ctrlC = true;
		}
	});
	recordContainer = jQuery("#container");
	textM = textM > 9 ? textM : '0' + textM;
	textD = textD > 9 ? textD : '0' + textD;
	$('#datepicker').attr('value', textY + '-' + textM + '-' + textD);
	$.getJSON(requestUrlMap['userInfo']['url'], {
		'lvid': lvid,
		'sign': sign
	}, function(data) {
		userNickName = data.userinfo.nickname;
	});
	setDataAction(textY, textM);
	loadMsg();
});

//选中当前对话块
function selContent(event) {
	var target = $(event.target).parent();
	if(target[0].nodeName != 'DL' || target.hasClass('newsData')) {
		return;
	}
	if(event.which != 1 && event.which != 3) {
		return;
	}
	$(target).addClass('newsAcitve').siblings('dl').removeClass('newsAcitve');
	$('.fileBox').css({
		'margin-left': '11px',
		'margin-top': '-1px'
	});
	if($(target).children('.fileBox')) {
		$(target).children('.fileBox').css({
			'margin-left': '5px',
			'margin-top': '-1px'
		});
	}
}
/**
 * 重新调整也没布局适配窗口大小
 */
function reSize() {
	$(".record").css({
		height: $(window).height() - 75
	});
	var docuHeight = $('.record').height();
	var contHeight = $(".chatRecord").height() + 40;
	if(docuHeight > contHeight) {
		$('.record').css('overflow', 'hidden');
	} else {
		$('.record').css({
			'overflow-y': 'scroll',
			'overflow-x': 'hidden'
		})
	}
	if($('#container').height() < docuHeight) {
		$('.record').css('overflow', 'hidden');
	}
}

function reSizeNull() {
	$(".record").css({
		height: $(window).height() - 75
	});
}
/**
 * 加载上一页聊天记录
 */
function loadBeforePageMsg() {
	$('.infoLoadicon').show();
	if(pageNo <= 1) {
		return;
	}
	jQuery("#container").empty();
	pageNo--;
	loadMsg();
	$('#uppage').attr('scrollPage', 'ups');
}

/**
 * 加载最后一页聊天记录
 */
function loadPrePageMsg() {
	if(pageNo >= pageCount) {
		return;
	}
	$('.infoLoadicon').show();
	$("#container").empty();
	pageNo = pageCount;
	loadMsg();
	$('#lastpage').attr('scrollPage', 'lastpage');
}
/**
 * 加载首页聊天记录
 */
function loadFirstPageMsg() {
	if(pageNo == 1) {
		return;
	}
	$('.infoLoadicon').show();
	$("#container").empty();
	pageNo = 1;
	loadMsg();
	$('#homepage').attr('scrollPage', 'homepage');
}

/**
 * 加载下一页聊天记录
 */
function loadTotalPageMsg() {
	$('.infoLoadicon').show();
	$("#container").empty();
	pageNo++;
	loadMsg();
	$('#downpage').attr('scrollPage', 'downpage');
}

function nationalDays(date) {
	var y = date.getFullYear();
	var m = date.getMonth();
	var d = date.getDate();
	var time = y + '-' + m;
	var dataArray = msgDateArray[time];
	if(!dataArray) {
		return [false];
	}
	for(var i = 0; i < dataArray.length; i++) {
		var dateY = dataArray[i].slice(0, 4),
			dateM = dataArray[i].slice(5, 7),
			dateD = dataArray[i].slice(8, 10);
		if(m == parseInt(dateM - 1) && d == dateD && y == dateY) {
			return [true];
		}
	}
	return [false];
}

function setDataAction(changeYear, changeMonth) {
	var time = parseInt(changeYear) + '-' + parseInt(changeMonth - 2);
	var dataArray = msgDateArray[time];
	if(dataArray) {
		return;
	}
	var chatdateMsg;
	if(chatType == ChatType.PERSON) {
		chatdateMsg = requestUrlMap['chatData']['url'];
	} else if(chatType == ChatType.GROUP) {
		chatdateMsg = requestUrlMap['chatDataG']['url'];
	};
	var dataParam = {
		"lvid": lvid,
		"tolvid": tolvid,
		"groupid": groupId,
		"sign": sign,
		'year': changeYear,
		'month': changeMonth
	}
	$.getJSON(chatdateMsg, dataParam, function(data) {
		var data = data.data;
		if(data.length == 0) {
			msgDateArray[time] = [];
			return;
		}
		var tmpDate;
		var y, m, d;
		var tmpTime;
		var dataArray;
		for(var i = 0; i < data.length; i++) {
			var y = data[i].slice(0, 4);
			var m = data[i].slice(5, 7);
			tmpTime = parseInt(y) + '-' + parseInt(m - 1);
			dataArray = msgDateArray[tmpTime];
			if(!msgDateArray[tmpTime]) {
				dataArray = [];
			}
			dataArray.push(data[i]);
			msgDateArray[tmpTime] = dataArray;
		}
	});
}

$.datepicker.setDefaults({
	closeStatus: '不改变当前选择',
	prevText: '<上月',
	prevStatus: '显示上月',
	prevBigText: '<<',
	prevBigStatus: '显示上一年',
	nextText: '下月>',
	nextStatus: '显示下月',
	nextBigText: '>>',
	nextBigStatus: '显示下一年',
	currentText: '今天',
	currentStatus: '显示本月',
	monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
	monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
	monthStatus: '选择月份',
	yearStatus: '选择年份',
	weekHeader: '周',
	weekStatus: '年内周次',
	dayNamesMin: ["一", "二", "三", "四", "五", "六", "日"],
	dayStatus: '设置 DD 为一周起始',
	dateStatus: '选择 m月 d日, DD',
	dayNames: '一',
	maxDate: new Date(),
	beforeShowDay: nationalDays,
	dateFormat: 'yy-mm-dd',
	changeMonth: true,
	changeYear: true,
	initStatus: '请选择日期',
	isRTL: false,
	onChangeMonthYear: function(selectedY, selectedM) {
		setDataAction(selectedY, selectedM);
	},
	onSelect: function(selectedDate) {
		selectedDate = selectedDate.replaceAll('-', '/');
		var mydate = new Date(selectedDate);
		timepar = parseInt(mydate.getTime() / 1000);
		pageNo = 1;
		jQuery("#container").empty();
		loadMsg();
	}
});
$("#datepicker").datepicker();
/**
 * 拉取聊天信息
 */
function loadMsg() {
	if(groupId == -1 || tolvid == -1) {
		$('.record_per').hide();
		setInterval(function() {
			reSizeNull();
		})
		return;
	}
	if(chatType == ChatType.PERSON) {
		loadPersonMsg();
	} else if(chatType == ChatType.GROUP) {
		loadGroupMsg();
	}
}
/**
 * 拉取个人聊天记录
 */
function loadPersonMsg() {
	var param = {
		"lvid": lvid,
		"tolvid": tolvid,
		"pageno": pageNo,
		"pagesize": pageSize,
		"sign": sign,
		"timepar": timepar
	};
	jQuery.getJSON(requestUrlMap['getPersonMsg']['url'], param, pringMsg);
}
/**
 * 拉取云组聊天记录
 */
function loadGroupMsg() {
	var param = {
		"lvid": lvid,
		"groupid": groupId,
		"pageno": pageNo,
		"pagesize": pageSize,
		"sign": sign,
		"timepar": timepar
	};
	jQuery.getJSON(requestUrlMap['getGroupMsg']['url'], param, pringMsg);
}

function pringMsg(result) {
	if(result['errorid'] != 0) {
		//异常
		return;
	}
	if(!chatname) {
		chatname = result['tonickname'] || result['cloudgroupname'];
		$('.record_per b').text(chatname);
	}
	if(result.count == 0) {
		//没有记录
		$("#homepage,#uppage,#downpage,#lastpage").css({
			"cursor": "default",
			"background-position-y": -14 + "px"
		}).attr("href", "#").removeClass("glide_a");
		$('.record').css({
			'overflow': 'hidden',
			'background': 'url(../images/empty.png) no-repeat center 50%'
		});
		setInterval(function() {
			reSizeNull();
		});
		return;
	}
	$('.record').css({
		'background': 'none'
	});
	pageCount = Math.ceil(result["count"] / pageSize);
	var records = result.data;
	var html = '';
	var record;
	var ownerClass, showDate;
	var chatDateTime, chatDate, chatDateTag, chatTime, currDate = jQuery.formatDateStyle1(new Date());
	var projectInfo, fileInfo;
	var toNickName = result["tonickname"];
	html += '<li class="clearfix"><div class="chatRecord">';
	for(var i = records.length - 1; i >= 0; i--) {
		record = records[i];
		chatDateTime = new Date(record["datetime"] * 1000);
		chatDate = jQuery.formatDateStyle1(chatDateTime);
		chatTime = jQuery.formatDateStyle2(chatDateTime);
		ownerClass = record["lvid"] == lvid ? "partner-one" : "partner-two";
		showDate = chatTime;
		if(chatDateTag != chatDate) { //不是同一天的
			chatDateTag = chatDate;
			html += '<dl class="newsData" style="width:100%;text-align:center">';
			html += '<dt style="padding-left:0"><div><p class="dialogueTit"><b>—————— </b>' + chatDate + '<b> ——————</b></p></div>';
			html += '</dt>';
			html += '</dl>';
		}
		var userNick = record["nickname"];
		var groupNick = record["groupnickname"];
		if(record['lvid'] != lvid && toNickName) {
			userNick = chatname;
		}
		userNick = groupNick || userNick || "未知";
		userNick = userNick.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
		html += '<dl>';
		html += '<dt class="' + ownerClass + '">' + userNick;
		if(chatType == ChatType.GROUP) {
			html += ' (' + (record['lvid'] || "未知") + ')';
		}
		html += '　 ' + showDate + '</dt>';
		projectInfo = parseProject(record['msgcontent']);
		if(projectInfo) {
			html += projectInfo;
		}
		fileInfo = parseFileHtml(record['msgcontent']);
		if(fileInfo) {
			html += fileInfo;
		}
		html += '<dd style="' + parseFontStyle(record['fontstyle']) + '">' + parseMsg(record["msgcontent"]) + '</dd>';
		html += '</dl>';
	}
	html += '</div>';
	html += '</li>';
	recordContainer.html(html + recordContainer.html());
	if(pageCount <= 1) {
		$("#homepage,#uppage,#downpage,#lastpage").css({
			"cursor": "default",
			"background-position-y": -14 + "px"
		}).attr("href", "#").removeClass("glide_a");
	} else {
		if(pageNo == 1) {
			$("#homepage,#uppage").css({
				"cursor": "default",
				"background-position-y": -14 + "px"
			}).attr("href", "#").removeClass("glide_a");
		} else {
			$("#homepage").css({
				"cursor": "pointer",
				"background-position-y": 3 + "px"
			}).attr("href", firstPage_href).addClass("glide_a");
			$("#uppage").css({
				"cursor": "pointer",
				"background-position-y": 3 + "px"
			}).attr("href", beforePage_href).addClass("glide_a");
		}
		if(pageNo == pageCount) {
			$("#downpage,#lastpage").css({
				"cursor": "default",
				"background-position-y": -14 + "px"
			}).attr("href", "#").removeClass("glide_a");
			$('.infoLoadicon').hide();
		} else {
			$("#lastpage").css({
				"cursor": "pointer",
				"background-position-y": 3 + "px"
			}).attr("href", prePage_href).addClass("glide_a");
			$("#downpage").css({
				"cursor": "pointer",
				"background-position-y": 3 + "px"
			}).attr("href", lastPage_href).addClass("glide_a");
		}
	}
	$('img').load(function(){
		reSize();
	})
	reSize();
	resetImgView();
	if($('#downpage').attr('scrollPage') == 'downpage' || $('#homepage').attr('scrollPage') == 'homepage') {
		$('.infoLoadicon').hide();
		infoNews();
		$('img').load(function() {
			infoNews();
		})
	}
	if($('#uppage').attr('scrollPage') == 'ups' || $('#lastpage').attr('scrollPage') == 'lastpage') {
		$('.infoLoadicon').hide();
		$('#downpage,#homepage,#lastpage').attr('scrollPage', '')
		$('.record').scrollTop(0);
	}
}

//聊天信息滚动条
function infoNews() {
	var contHei = $('#container').height();
	var top = $(document).height() - $('.mesRecFoot').height() - 40;
	var scinfo = contHei - top;
	$('.record').scrollTop(scinfo);
	$('#uppage,#downpage,#homepage').attr('scrollPage', '');
}

/**
 * 解析项目
 */
function parseProject(text) {
	var projectBaseInfo = parseProjectBaseInfo(text);
	if(!projectBaseInfo) {
		var projectId = parseProjectId(text);
		if(!projectId) {
			return "";
		}
		projectBaseInfo = {
			'id': projectId,
			'name': ''
		};
	}
	var params = {
		"projectid": projectBaseInfo['id'],
		"lvid": lvid,
		"sign": sign
	};
	$.getJSON(requestUrlMap['projectInfo']['url'], params, function(resultData) {
		if(!resultData || resultData['errorid'] != 0) {
			var delTip = '项目：';
			if(projectBaseInfo['name']) {
				delTip += projectBaseInfo['name'] + ' (' + projectBaseInfo['id'] + ')';
			} else {
				delTip += projectBaseInfo['id'];
			}
			delTip += ' 已被删除!';
			$('.project_' + projectBaseInfo['id']).parent().html(delTip);
			return;
		}
		var data = resultData['projectinfo'];
		var html = '';
		createorname = data['creatorname'];
		if(createorname && createorname.length > 3) {
			createorname = createorname.substring(0, 3) + "...";
		}
		var projectType = data['projecttype'] == 0 ? "硫酸纸" : "3D";
		if(data['iconurl'] == '') {
			data['iconurl'] = '../images/blue/projectImg.png'
		}
		html += '<div class="linkWarp">';
		html += '<div class="linkInfo">';
		html += '<div class="linkImg" onclick="openProject(' + data['projectid'] + ')"><img src="' + data['iconurl'] + '" onerror=\'javascript:this.src ="../images/blue/projectImg.png"\'></div>';
		html += '<div class="linkMessage msgWid">';
		html += '<dl>';
		html += '<dt style="padding-left:0px;">' + data['projectname'] + '</dt>';
		html += '<dd style="padding-left: 0px;"><span style="float:left" class="linkUpdated">' + jQuery.formatDateStyle3(new Date(data['uploadtime'] * 1000)) + '</span></dd>';
		html += '</dl>';
		html += '</div>';
		html += '<div class="clear"></div>';
		html += '<div class="linkOpen">';
		if(projectType == '3D') {
			html += '<img src="../images/3D.png" alt="">';
			html += '<span onclick="openProject(' + data['projectid'] + ')">打开</span>';
			html += '<i></i>';
			html += '<p>' + projectType + '模型' + '&nbsp;(<span>' + data['handlenum'] + '</span>张)</p>';
		} else {
			html += '<img src="../images/2D.png" alt="">';
			html += '<span onclick="openProject(' + data['projectid'] + ')">打开</span>';
			html += '<i></i>';
			html += '<p>' + projectType + '&nbsp;(<span>' + data['handlenum'] + '</span>张)</p>';
		}
		html += '</div>';
		html += '</div>';
		$('.project_' + data['projectid']).html(html);
		projectCache[data['projectid']] = data;
	});
	return '<dd><div class="linkBox project_' + projectBaseInfo['id'] + '"></div></dd>'
}

/**
 * 打开项目
 * @param projectId 项目ID
 */
function openProject(projectId) {
	var projectInfo = projectCache[projectId];
	if(projectInfo) {
		var projectJSON = $.toJSON(projectInfo);
		var params = "{command:1008,params:" + projectJSON + "}";
		sendCommand(params);
	}
}

function getToday() {
	var mydate = new Date();
	var year = mydate.getFullYear();
	var month = mydate.getMonth();
	var day = mydate.getDate();
	var str = "" + mydate.getFullYear() + "-";
	str += month < 9 ? "0" + (month + 1) + "-" : (month + 1) + "-";
	str += day < 10 ? "0" + day : day;
	return str;
}
$('#chatReload').click(function() {
	window.location.reload();
})

function chatSearch(data) {
	chatSearchkey = data.key;
	loadChatMsg();
}

function loadChatMsg() {
	var params = {
		lvid: lvid,
		tolvid: tolvid,
		groupid: groupId,
		pagesize: 60,
		pageno: searchPageNo,
		sign: sign,
		key: chatSearchkey
	}
	var searchUrl = !groupId ? requestUrlMap['searchPersonMsg']['url'] : requestUrlMap['searchGroupMsg']['url'];
	if(groupId && tolvid) {
		searchUrl = requestUrlMap['searchPersonMsg']['url'];
	}
	$.getJSON(searchUrl, params, pringSearchMsg);
}

function pringSearchMsg(result) {
	$('#container').empty();
	if(!chatname) {
		chatname = result['tonickname'] || result['cloudgroupname'];
		$('.record_per b').text(chatname);
	}
	if(result.total == 0) {
		//没有记录
		$("#homepage,#uppage,#downpage,#lastpage").css({
			"cursor": "default",
			"background-position-y": -14 + "px"
		}).attr("href", "#").removeClass("glide_a");
		$('.record').css({
			'overflow': 'hidden',
			'background': 'url(../images/empty.png) no-repeat center 50%'
		});
		$('.record_per').text('搜索不到结果');
		$('.record_per').append('<div class="record_img"><b>返回</b></div>');
		setInterval(function() {
			reSizeNull();
		});
		return;
	}
	$('.record').css({
		'background': 'none'
	});
	$('.record_per').text('已搜索到' + result["total"] + '聊天记录');
	$('.record_per').append('<div class="record_img"><b>返回</b></div>')
	pageCount = Math.ceil(result["total"] / pageSize);
	var records = result.data;
	var html = '';
	var record;
	var ownerClass;
	var projectInfo, fileInfo;
	html += '<li class="clearfix"><div class="chatRecord">';
	for(var i = records.length - 1; i >= 0; i--) {
		record = records[i];
		ownerClass = record["fromlvid"] == lvid ? "partner-one" : "partner-two";
		if(record["nickname"]) {
			userNick = record["nickname"];
		} else {
			userNick = record["fromlvid"] == lvid ? userNickName : toChatname;
		}
		html += '<dl>';
		html += '<dt class="' + ownerClass + '">' + userNick;
		if(chatType == ChatType.GROUP) {
			html += ' (' + record['fromlvid'] + ')';
		}
		html += '&nbsp;&nbsp;&nbsp;&nbsp;' + record["datetime"] + '</dt>';
		projectInfo = parseProject(record['msgcontent']);
		if(projectInfo) {
			html += projectInfo;
		}
		fileInfo = parseFileHtml(record['msgcontent']);
		if(fileInfo) {
			html += fileInfo;
		}
		html += '<dd>' + parseMsg(record["msgcontent"], "", "", true) + '</dd>';
		html += '</dl>';
	}
	html += '</div>';
	html += '</li>';
	recordContainer.html(html + recordContainer.html());
	if(pageCount <= 1) {
		$("#homepage,#uppage,#downpage,#lastpage").css({
			"cursor": "default",
			"background-position-y": -14 + "px"
		}).attr("href", "#").removeClass("glide_a");
	} else {
		if(searchPageNo == 1) {
			$("#homepage,#uppage").css({
				"cursor": "default",
				"background-position-y": -14 + "px"
			}).attr("href", "#").removeClass("glide_a");
		} else {
			$("#homepage").css({
				"cursor": "pointer",
				"background-position-y": 3 + "px"
			}).attr("href", firstPage_hrefSear).addClass("glide_a");
			$("#uppage").css({
				"cursor": "pointer",
				"background-position-y": 3 + "px"
			}).attr("href", beforePage_hrefSear).addClass("glide_a");
		}
		if(searchPageNo == pageCount) {
			$("#downpage,#lastpage").css({
				"cursor": "default",
				"background-position-y": -14 + "px"
			}).attr("href", "#").removeClass("glide_a");
			$('.infoLoadicon').hide();
		} else {
			$("#lastpage").css({
				"cursor": "pointer",
				"background-position-y": 3 + "px"
			}).attr("href", prePage_hrefSear).addClass("glide_a");
			$("#downpage").css({
				"cursor": "pointer",
				"background-position-y": 3 + "px"
			}).attr("href", lastPage_hrefSear).addClass("glide_a");
		}
	}
	reSize();
	resetImgView();
	if($('#downpage').attr('scrollPage') == 'downpage' || $('#homepage').attr('scrollPage') == 'homepage') {
		$('.infoLoadicon').hide();
		infoNews();
		$('img').load(function() {
			infoNews();
		})
	}
	if($('#uppage').attr('scrollPage') == 'ups' || $('#lastpage').attr('scrollPage') == 'lastpage') {
		$('.infoLoadicon').hide();
		$('#downpage,#homepage,#lastpage').attr('scrollPage', '')
		$('.record').scrollTop(0);
	}
}
$(document).on('click', '.record_img b', function() {
	window.location.reload();
})

function loadBeforePageMsgSear() {
	$('.infoLoadicon').show();
	if(searchPageNo <= 1) {
		return;
	}
	jQuery("#container").empty();
	searchPageNo--;
	loadChatMsg();
	$('#uppage').attr('scrollPage', 'ups');
}

function loadPrePageMsgSear() {
	if(searchPageNo >= pageCount) {
		return;
	}
	$('.infoLoadicon').show();
	$("#container").empty();
	searchPageNo = pageCount;
	loadChatMsg();
	$('#lastpage').attr('scrollPage', 'lastpage');
}

function loadFirstPageMsgSear() {
	if(searchPageNo == 1) {
		return;
	}
	$('.infoLoadicon').show();
	$("#container").empty();
	searchPageNo = 1;
	loadChatMsg();
	$('#homepage').attr('scrollPage', 'homepage');
}

function loadTotalPageMsgSear() {
	$('.infoLoadicon').show();
	$("#container").empty();
	searchPageNo++;
	loadChatMsg();
	$('#downpage').attr('scrollPage', 'downpage');
}