var cse, page = 0;
function display(data){
	if (data.length==0) {
		$(".ui-more").hide(), $(".ul").html('<p class="noresults">很抱歉，没有找到相关的内容，请换个关键词试试！</p>');
		return;
	}
	var html = "";
	for(var i=0; i<data.length; i++){
		var article = data[i];
		html += "<div class='ui-mod-picsummary ui-border-bottom-gray js-container'><a href='" + article.linkUrl.replace(saxue_url,"") + "'>";
		if (article.image!='') {
			html += "<img class='ui-pic' src='" + article.image + "'>";
		}
		html += "<h3 class='ui-title'>" + article.title + "</h3>";
		html += "<div class='ui-summary'>" + article.abstract + "</div>";
		html += "</a></div>";
	}
	$(".ul").append(html);
	cse.getSearchInfo(key,getPage);
}
function getPage(data){
	var pageCount = Math.ceil(data.totalNum / 10);
	if (data.curPage!='') page = parseInt(data.curPage) + 1;
	if (pageCount <= page) {
		$(".ui-more").hide()
	}
}
function init(){
	cse = new BCse.Search(sid);
	cse.setResultType(6);
	GetResult()
}
function GetResult() {
	++page;
	cse.getResult(key, display, page)
}
function loadScript(){
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.charset = "utf-8";
	script.src = "http://zhannei.baidu.com/api/customsearch/apiaccept?sid=" + sid + "&v=2.0&callback=init";
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(script,s);
}
$(function(){
	loadScript(), $(".ui-more").click(function() {
		GetResult()
	});
})