var page = 1,
	keyword = '',
	maxpage = 0,
	issign=false,
	islike=false;

$(function() {
	$('#alert-loading').modal("open");
	keyword= decodeURIComponent(getQueryString("k"));
	setTimeout(function(){callbackObj.web_tb_callback(keyword, page+"")},500); 
	$('.img-thumb').click(function() {
		$('.img-thumb').attr('style', 'display:none;');
	});
	$('.panel').click(function() {
		$(this).find('.content').attr('style', 'display:inline;')
	});
	$('#reload').click(function() {
		location.reload();
	});
	$('#tbsignbtn').click(function(){
		if(issign)
		{
			$('#alert-info').text("亲，你已经签到过了哦");
			$('#alert').modal("open");
		}
		else
		{
			$('#alert-loading').modal("open");
			callbackObj.web_sign(keyword);
		}
	});
	$('#tblikebtn').click(function(){
		$('#alert-loading').modal("open");
		if(islike)
		{
			callbackObj.web_unlike(keyword);
		}
		else
		{
			callbackObj.web_like(keyword);
		}
	});
	$('#post').click(function() {
		callbackObj.web_threadpost(keyword);
	});
	
	$(window).scroll(function() {　　
		var scrollTop = $(this).scrollTop();　　
		var scrollHeight = $(document).height();　　
		var windowHeight = $(this).height();　　
		if(scrollTop + windowHeight == scrollHeight) {　　　　
			if(!lock) {
				lock = true;
				$('#add').attr('style', '');
				if (maxpage > page) {
					page++;
					callbackObj.web_tb_callback(keyword, page+"");
					if (maxpage < page) {
						$('#add').attr('style', 'display: none;');
					}
				} else {
					$('#add').attr('style', 'display: none;');
				}
			}　　
		}
	});
});

function setinfo(tbname, like, threadnum, head, info, is_like, is_sign) {
	$('#tbname').text(tbname);
	$('#tblike').text(like);
	$('#tbthreadnum').text(threadnum);
	$('#tbhead').attr('src', head);
	$('#tbinfo').text(info);
	if (is_like == "1") {
		$('#tblikebtn').text('取消关注');
		$('#tblikebtn').removeClass('am-btn-danger');
		$('#tblikebtn').addClass('am-btn-default');
		islike=true;
	}
	if (is_sign == "1") {
		$('#tbsignbtn').text('已签到');
		$('#tbsignbtn').removeClass('am-btn-danger');
		$('#tbsignbtn').addClass('am-disabled');
		issign=true;
	}
}

function addthread(title, content, author, time, tid, err) {
	$('#alert-loading').modal("close");
	if (err == "0") {
		lock = false;
		//alert(content);
		$('#add').before('<div class="am-panel am-panel-default panel"><div class="am-panel-bd"><a onclick="callbackObj.web_thread_enter(\''+ tid 
		+ '\',\''+keyword+'\')" >' + title.replace('[is_top]','<span class="am-badge am-badge-primary am-radius">置顶</span>').replace('[is_good]','<span class="am-badge am-badge-danger am-radius">精品</span>')
		+ '</a><span class="am-icon-user span">  ' + author
		+ '</span><div class="content"><br/><span class="am-icon-clock-o span">  ' + time 
		+ '</span>' + content + '</div></div></div>');
		$('.panel').click(function() {
		$(this).find('.content').attr('style', 'display:inline;')
	});
	
	} else {
		alert("获取失败：" + err+keyword);
		if (pn != 1) {
			pn--;
		} else {
			$('#alert-loading').modal("open");
		setTimeout("callbackObj.web_searchbar_tb('"+tbname+"');$('#alert-loading').modal(\"close\");",1000)
			
		}
	}
}
