CntxLinks = {
	VERSION:'2.1.0.0',
	ACTIVE:true,
	ttID: 'trrToolTip',
	ttLT: 'SearchKey_Text',
	ContentSite: 'http://buscador.terra.com.br/LinkRedirection.aspx?ca=t&ltarget=_blank&bctFilter=CHANNEL:tecnologia:AND&query=',
	exact: true,
	replaceAll: false,
	onload: true,
	followMouse: true,
	showDelay: 200,
	hideDelay: 1000,
	offSetW: 2,
	offSetH: -12,
	IE:document.all,
	NS:document.getElementById && !document.all,
	overL: false,
	overT: false,
	tooltip:null,
	onMouseMove:null,
	activeLink:"",
	nrTxt:"Nenhum resultado foi encontrado",
	dwnlData:false,
	Cache: new Array,
	debug:false
};

CntxLinks.Body = function(){return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;}
CntxLinks.isArray = function(o){if(CntxLinks.isObject(o) && o.constructor == Array)	return true; else return false;}
CntxLinks.isFunction = function(o){if(typeof o !="undefined" && typeof o =="function") return true; else return false;}
CntxLinks.isObject = function(o){if(typeof o !="undefined" && typeof o =="object") return true; else return false;}
CntxLinks.isNumber = function(o){if(typeof o !="undefined" && typeof o =="number") return true; else return false;}
CntxLinks.isText = function(o){if(typeof o !="undefined" && typeof o =="string") return true; else return false;}

CntxLinks.MouseMove = function(a) {
	if (CntxLinks.onMouseMove!=null && a) document.onmousemove = function(ev) {CntxLinks.onMouseMove(ev); CntxLinks.Move(ev);};
	else if(a) document.onmousemove=CntxLinks.Move;
	else document.onmousemove=CntxLinks.onMouseMove;
}

CntxLinks.Show = function(k, s, c, w) {
	if (CntxLinks.tooltip!=null && (CntxLinks.NS||CntxLinks.IE)) {
		if (CntxLinks.isNumber(w)) CntxLinks.tooltip.style.width=w+"px";
		if (CntxLinks.isText(c) && c.length>0) CntxLinks.tooltip.style.backgroundColor=c;
		if(CntxLinks.activeLink!=k.toLowerCase()){
			CntxLinks.activeLink=k.toLowerCase();
			if(typeof CntxLinks.Cache[CntxLinks.activeLink]!='undefined') {CntxLinks.tooltip.innerHTML = CntxLinks.Cache[CntxLinks.activeLink]; CntxLinks.dwnlData = true; }
			else {CntxLinks.tooltip.innerHTML=s; CntxLinks.dwnlData=false;}
		}
		CntxLinks.overL=true;
		if(CntxLinks.tooltip.style.visibility!='visible' || CntxLinks.followMouse || !CntxLinks.dwnlData) CntxLinks.MouseMove(true);
		return false;
	}
}

CntxLinks.ShowTooltip =	function() {
	if(CntxLinks.overL) CntxLinks.tooltip.style.visibility='visible';
	if(!CntxLinks.followMouse || CntxLinks.dwnlData) CntxLinks.MouseMove(false);
}

CntxLinks.Move = function (e) {
	var mX=CntxLinks.NS ? e.pageX : window.event.x + CntxLinks.Body().scrollLeft;
	var mY=CntxLinks.NS ? e.pageY : window.event.y + CntxLinks.Body().scrollTop;
	var mMaxX=CntxLinks.NS ? window.innerWidth+window.pageXOffset : CntxLinks.Body().clientWidth+CntxLinks.Body().scrollLeft;
	var mMaxY=CntxLinks.NS ? window.innerHeight+window.pageYOffset : CntxLinks.Body().clientHeight+CntxLinks.Body().scrollTop;
	var freeX=CntxLinks.IE && !window.opera ? CntxLinks.Body().clientWidth-event.clientX-CntxLinks.offSetW : window.innerWidth-e.clientX-CntxLinks.offSetW-20;
	var freeY=CntxLinks.IE && !window.opera ? CntxLinks.Body().clientHeight-event.clientY-CntxLinks.offSetH : window.innerHeight-e.clientY-CntxLinks.offSetH-20;
	var t = (CntxLinks.offSetW<0) ? CntxLinks.offSetW*(-1) : -960;

	if (CntxLinks.overL && CntxLinks.isObject(CntxLinks.tooltip)) {
		if (freeX<CntxLinks.tooltip.offsetWidth) CntxLinks.tooltip.style.left=CntxLinks.IE ? CntxLinks.Body().scrollLeft+event.clientX-CntxLinks.tooltip.offsetWidth+"px" : window.pageXOffset+e.clientX-CntxLinks.tooltip.offsetWidth+"px";
		else if (mX<(t+5)) CntxLinks.tooltip.style.left="5px";
		else CntxLinks.tooltip.style.left=mX+CntxLinks.offSetW+"px";

		if (freeY<CntxLinks.tooltip.offsetHeight) CntxLinks.tooltip.style.top=CntxLinks.IE ? CntxLinks.Body().scrollTop+event.clientY-CntxLinks.tooltip.offsetHeight-CntxLinks.offSetH+"px" : window.pageYOffset+e.clientY-CntxLinks.tooltip.offsetHeight-CntxLinks.offSetH+"px";
		else CntxLinks.tooltip.style.top=mY+CntxLinks.offSetH+"px";

		if(CntxLinks.tooltip.style.visibility!='visible' || CntxLinks.dwnlData) window.setTimeout("CntxLinks.ShowTooltip();", CntxLinks.showDelay);
	}
	if(CntxLinks.debug)	window.status = "xMousePos=" + mX + ", yMousePos=" + mY + ", xMousePosMax=" + mMaxX + ", yMousePosMax=" + mMaxY + ", TTx=" + CntxLinks.tooltip.style.left + ", TTy=" + CntxLinks.tooltip.style.top;
}

CntxLinks.Hide = function () {
	if (CntxLinks.tooltip!=null && (CntxLinks.NS||CntxLinks.IE)) {
		CntxLinks.overL=false;
		CntxLinks.overT=false;
		if(CntxLinks.followMouse) CntxLinks.MouseMove(false);
		window.setTimeout("CntxLinks.HideTooltip();", CntxLinks.hideDelay);
	}
}

CntxLinks.HideTooltip =	function(){if(!CntxLinks.overL && !CntxLinks.overT) CntxLinks.tooltip.style.visibility="hidden";}
	
CntxLinks.MakeCall = function(k) {
	if(typeof CntxLinks.Cache[k]=='undefined'){
		CntxLinks.tooltip.innerHTML =  "Carregando...";
		CntxLinks.MouseMove(false);
		CntxLinks.dwnlData = true;
		var c=document.createElement('script');
		c.setAttribute('type','text/javascript');
		var cK;
		if(k.indexOf(' ')>-1 && k.indexOf('"')==-1) cK = '"'+k+'"';
		else cK = k;
		c.setAttribute('src',CntxLinks.ContentSite+escape(cK));
		document.body.appendChild(c);
	}else CntxLinks.tooltip.innerHTML = CntxLinks.Cache[k];
}

CntxLinks.ContentLoaded = function(){CntxLinks.Cache[CntxLinks.activeLink] = CntxLinks.tooltip.innerHTML;}

CntxLinks.Click = function(a) {
	return true;
}

CntxLinks.getKeyExp = function(k){
	if (CntxLinks.exact && k.length > 0){
		var l = k.substring(k.length - 1);
		var r = new RegExp('[ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ]', "gi");
		if(l.match(r)) return '\\b'+k+'\\B';
		else return '\\b'+k+'\\b';
	}else return k;
}

CntxLinks.hiliteHTML = function(h, q) {
	var r = new RegExp('('+q.join("|")+')', "gi");
	var m = typeof msgTT != 'undefined' && CntxLinks.isText(msgTT) ? msgTT : "Noticias de";
	var k = '<a href="javascript:CntxLinks.MakeCall(\'$1\')" class="SearchKey_Href" style="text-decoration:none; color:#000; font-weight: bold;" onMouseover="CntxLinks.Show(\'$1\', \''+m+' $1 \');" onMouseout="CntxLinks.Hide();">$1</a>';
	var l = 0;
	var t = '<';
	var s = false;
	var b = new RegExp('^(script|style|textarea|a|object)', 'gi');
	var p = null;
	var o = '';
	while (l >= 0) {
		var pos = h.indexOf(t, l);
		if (pos < 0) {p = h.substring(l); l = -1;} 
		else {p = h.substring(l, pos); l = pos+1; }
		if (t == '<') {
			if (!s && q.length>0 && p.match(r)) {
				if(CntxLinks.replaceAll) p = p.replace(r, k);
				else {
					for (var i=0;i<q.length;i++) {
						r = new RegExp("("+q[i]+")","i");
						if (p.match(r)) {p = p.replace(r, k); q.splice(i,1); i--;}
					}
					if (q.length>0) r = new RegExp('('+q.join("|")+')', "i");
				}
			}else s = false;
		}else if (p.match(b)) s = true;
		else if(p.toLowerCase().indexOf('span')==0 && p.indexOf('googlesyndication.com')>-1){	
			l = h.toLowerCase().indexOf('</span', l) + 6;
			p += h.substring(pos, l);
			l++;
		}
		o += p + (pos < 0 ? '' : t);
		t = t == '<' ? '>' : '<';
	}
	return o;
};
CntxLinks.hiliteElement = function(e, q) {
	if(CntxLinks.debug) window.status = "Início";
	if (!q) return;
	var o = e.innerHTML;
	var n = CntxLinks.hiliteHTML(o, q);
	if (o != n) e.innerHTML = n;
	if(CntxLinks.debug) window.status = "Fim";
};
CntxLinks.hilite = function() {
	var e = null;
	if (CntxLinks.IE || CntxLinks.NS) CntxLinks.tooltip = document.all ? document.all[CntxLinks.ttID] : document.getElementById ? document.getElementById(CntxLinks.ttID) : null;
	if(CntxLinks.tooltip!=null){
		if ((e = document.getElementById('content')) || (e = document.getElementById('container')) || (e = document.body)){
			var ar = new Array();
			for (var i=0;i<linkKeywords.length;i++){
				if(ar.toString().indexOf(linkKeywords[i].toLowerCase())==-1)
					ar.push(CntxLinks.getKeyExp(linkKeywords[i].toLowerCase()));
			}
			if(CntxLinks.ttLT==null || CntxLinks.ttLT=='') CntxLinks.hiliteElement(e,ar);
			else {
				var oTL = document.getElementById(CntxLinks.ttLT);
				if(oTL!=null) CntxLinks.hiliteElement(oTL,ar);
				var skt=1;
				while((oTL=document.getElementById(CntxLinks.ttLT+skt++))!=null)
					CntxLinks.hiliteElement(oTL,ar);
			}
			if(typeof offSetX != 'undefined' && CntxLinks.isNumber(offSetX)) CntxLinks.offSetW = CntxLinks.offSetW + offSetX;
			if(typeof offSetY != 'undefined' && CntxLinks.isNumber(offSetY)) CntxLinks.offSetH = CntxLinks.offSetH + offSetY;
			if(CntxLinks.debug) document.onmousemove = CntxLinks.Move;
			if (document.layers) document.captureEvents(Event.MOUSEMOVE); // Netscape
			CntxLinks.onMouseMove = document.onmousemove;
			if (CntxLinks.IE || CntxLinks.NS) CntxLinks.tooltip = document.all ? document.all[CntxLinks.ttID] : document.getElementById ? document.getElementById(CntxLinks.ttID) : "";
		}
	}
};
if(CntxLinks.ACTIVE && typeof linkKeywords != 'undefined' && CntxLinks.isArray(linkKeywords) && linkKeywords.length>0)
{
	if (CntxLinks.onload){
		if (window.onload){
			CntxLinks._old_onload = window.onload;
			window.onload = function(ev) {CntxLinks._old_onload(ev); CntxLinks.hilite(); };
		}else window.onload = CntxLinks.hilite;
	}else CntxLinks.hilite();
}
