var needShow = false;
var onFPage = false;
var isDic = false;
var kws = [];
var dicKWs = [];

function showKeyword(tagObj){
	if (tagObj==null){
		return;
	}
	var needSet = false;
	var content = tagObj.innerHTML;
	if (kws!=null){
		for(var i=0;i<kws.length;i++){
			if (kws[i]==null || kws[i].length<1){
				continue;
			}
			var needShow = false;
			if (content.indexOf(kws[i])>-1){
				var reg=new RegExp(kws[i],"g"); 
				content = content.replace(reg,"<a class=\"keyWord\" href=\"#\" onclick=\"javascript:return false;\" onmouseover=\"javascript:isDic=false;beginShow('"+kws[i]+"');\" onmouseout=\"javascript:stopShow();\">"+kws[i]+"</a>");
				needSet = true;
			}
		}
	}
	if (dicKWs!=null){
		for(var i=0;i<dicKWs.length;i++){
			if (dicKWs[i]==null){
				continue;
			}
			var ele = dicKWs[i].split("|");
			if (ele==null || ele.length<2){
				continue;
			}
			if (ele[0]!=null && content.indexOf(ele[0])>-1){
				var reg=new RegExp(ele[0],"g"); 
				content = content.replace(reg,"<a class=\"keyWordD\" href=\"#\" onclick=\"javascript:return false;\" onmouseover=\"javascript:isDic=true;beginShow('"+ele[1]+"',true);\" onmouseout=\"javascript:stopShow();\">"+ele[0]+"</a>");
				needSet = true;
			}
		}
	}
	if (needSet){
		tagObj.innerHTML = content;
	}
}

function initKeywordShow(){

	document.write("<div style=\"position: absolute;display:none;width:350px;\" id=\"fpage\" onmouseover=\"javascript:onFPage=true;\" onmouseout=\"javascript:fpStop();\"></div>");
	//document.write("<div id=\"debug\"></div>");
	var keywords = getHttpText("/asgetallkeywordthesaurus.ha","");
	if (keywords!=null){
		kws = keywords.split(",");
	}
	var dicKW = getHttpText("/asgetdickeywords.ha","");
	if (dicKW!=null){
		dicKWs = dicKW.split(",");
	}
}

function fpStop(){
	isShow=false;
	onFPage=false;
	setTimeout("showFPage(false)",500);
}
function beginShow(wKey){
	if (needShow){
		return;
	}
	needShow=true;
	setTimeout("showFPage(true,'"+wKey+"',"+event.clientX+","+event.clientY+")",500);
}
function stopShow(){
	if (!needShow){
		return;
	}
	needShow=false;
	setTimeout("showFPage(false)",500);
}
function showFPage(isShow,wKey,cX,xY){
	var fp = document.getElementById("fpage");
	if (isShow && needShow){
		if(document.documentElement && document.documentElement.scrollTop){
			fp.style.left = document.documentElement.scrollLeft+cX;
			fp.style.top = document.documentElement.scrollTop+xY;
		}else{
			fp.style.left = document.body.scrollLeft+cX;
			fp.style.top = document.body.scrollTop+xY;
		}
		if (isDic){
			var ar=document.createElement("div");
			ar.className="keyBlockD";
			ar.innerHTML = getHttpText("/dicpage/"+wKey+".html","");
			fp.innerHTML = "";
			fp.appendChild(ar);
		}else{
			callRssShow("/asgetkeywordthesaurusarticlelist.ha","cutnamesize=20&kw="+wKey,"/jiaoyin/rss/html/art/artkeylist.html",fp,false);
		}
		fp.style.display = "block";
	}else if (!onFPage){
		fp.style.display = "none";
	}
}