function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) return r[2];
	return null;
}
var cdata = "";
$(function() {
	$('.searchbar-box-panel').width($(window).width() - 153.5);
	$('#searchbox').load('searchbar.html', function() {
		$('#star-btn').click(function() {
			$('#star_panel').attr('style', '');
			$('#hot-cover').attr('style', '');
		});
		$('#hot-cover').click(function() {
			$('body').attr('style','');
			$('#star_panel').attr('style', 'display: none;');
			$('#hot-cover').attr('style', 'display: none;');
			$('#panel-hot').attr('style','display: none');
		});
		//alert('s');
		$('.searchbar-box-panel').width($(window).width() - 153.5);
		$('.searchbar-box').bind('input', function() {
			if($('.searchbar-box').val() == "") {
				$('.searchbar-list').attr('style', "display: none");
			} else {

				$('.searchbar-list').attr('style', "");

				callbackObj.web_searchbar_result($('.searchbar-box').val());

			}
		});
		$(".searchbar-box").keyup(function() {
			if(event.keyCode == 13) {
				if($('.searchbar-box').val() == "") {
					$('.searchbar-list').attr('style', "display: none");
				} else {

					$('.searchbar-list').attr('style', "");

					callbackObj.web_searchbar_result($('.searchbar-box').val());

				}
			}
		});
		$('.searchbar-back').click(function() {
			history.back(-1);
		});
		$('.searchbar-home').click(function() {
			callbackObj.web_gotofeed();
		});

		$('#searchbar-list-user').click(function() {
			callbackObj.web_user_see($('.searchbar-box').val());
		});
		$('#searchbar-list-tb').click(function() {
			callbackObj.web_searchbar_tb($('.searchbar-box').val());
		});
		$('#searchbar-list-thread').click(function() {
			callbackObj.web_thread_enter2($('.searchbar-box').val());
		});
		$('#searchbar-list-search-panel').click(function() {
			//alert('e');
			callbackObj.web_searchbar_search($('.searchbar-box').val());
		});
		$(window).resize(function() {
			$('.searchbar-box-panel').width($(window).width() - 153.5);
		});
		callbackObj.web_collectionget();

	});
	$(window).resize(function() {
		$('.searchbar-box-panel').width($(window).width() - 153.5);
	});

});

function setcdata(cd) {
	cdata = cd;
	var obj = [];
	$('#star_add').html("");
	if(cdata != "" & cdata != null) {
		//alert(cdata);
		obj = eval("(" + cdata + ")");
		//alert(cdata);
		for(var i = 0; i < obj.length; i++) {
			$('#star_add').append('<tr id="t' + obj[i].tid + '" class="star-list"><td>' + obj[i].tid + '</td><td style="max-width: 200px;">' + obj[i].title +
				'</td><td>' + obj[i].author + '</td><td>' +
				'<span style="cursor:pointer" onclick="callbackObj.web_thread_enter2(\'' + obj[i].tid + '\')"  class="am-badge am-badge-primary am-radius">进入</span>' +
				'<span style="cursor:pointer" onclick=\'removethread("' + obj[i].tid + '")\' class="am-badge am-badge-danger am-radius">删除</span>' +
				'</td></tr>');
		}
	}
	//callbackObj.web_collectionget();
}

function removethread(tid) {
	var obj = [];
	if(cdata != "" | cdata != null) {
		obj = eval("(" + cdata + ")");
		for(var i = 0; i < obj.length; i++) {
			if(obj[i].tid == tid) {
				obj.splice(i, 1);
				$("#t" + tid).animate({
					opacity: 0
				}, 1000);
				setTimeout(function() {
					$("#t" + tid).attr('style', 'display: none;');
				});
				break;
			}
		}
		callbackObj.web_collectionset(JSON.stringify(obj));
		callbackObj.web_collectionget();
	}
}

function addresult(logo, describe, head, info, num, keyword) {
	if(logo != "") {
		$('#searchbar-list-tb').attr('style', "");
		$('#searchbar-list-tb').attr('tag', keyword);
		$('#searchbar-list-tb-logo').attr('src', logo);
		$('#searchbar-list-tb-describe').text(describe);
		$('#searchbar-list-tb-name').text('查看贴吧：' + keyword);

	} else {
		$('#searchbar-list-tb').attr('style', 'display: none');
	}
	if(head != "") {
		$('#searchbar-list-user').attr('style', "");
		$('#searchbar-list-user').attr('tag', keyword);
		$('#searchbar-list-user-info').text(info);
		$('#searchbar-list-user-head').attr('src', 'http://tb.himg.baidu.com/sys/portrait/item/' + head);
		$('#searchbar-list-user-name').text('查看用户：' + keyword);
	} else {
		$('#searchbar-list-user').attr('style', 'display: none');
	}
	if(num != "") {
		$('#searchbar-list-thread').attr('style', "");
		$('#searchbar-list-thread').attr('tag', keyword);
		$('#searchbar-list-thread-num').text('进入帖子：' + keyword);
	} else {
		$('#searchbar-list-thread').attr('style', 'display: none');
	}
	$('#searchbar-list-search').text('搜索帖子：' + keyword);
	$('.searchbar-list').attr('style', "");
}