var dicAjax;
function dicionarioLibras(){
	dictionary();
}
function dictionary() {
	if (navigator.appName!='Microsoft Internet Explorer') {
		var t = document.getSelection();
		od(t);
	}else {
		var t = document.selection.createRange();
		if(document.selection.type == 'Text' && t.text>'') {
			document.selection.empty();
			od(t.text);
		}
	}
};
function od(t) {
		t=t.replace(/[!.:?,;"]/, '');
		while (t.substr(t.length-1,1)==' ') 
			t=t.substr(0,t.length-1);
		while (t.substr(0,1)==' ') 
			t=t.substr(1);
		if (t){	
			dicAjax = httpInit();
			var url = 'http://www.acessobrasil.org.br/DicionarioLibras/q.do?q='+escape(t);
			dicAjax.open("GET", url, true);
			dicAjax.onreadystatechange = function updatePage(){
				if (dicAjax.readyState == 4){			
					if (dicAjax.status == 200){
						var res = dicAjax.responseText;
						if(res!=""){
							var divDic = document.getElementById("dicionarioLibras");
							res = '<div><a href=\"#\" onclick=\"return closeDicionario();\">Fechar</a></div>' + res;
							res = "<div id=\"dicionarioLibrasSwf\" style=\"position:absolute; background: #eee; width:350px;height:300px; top:" + mouseY+"px;left:"+mouseX+"px;border: 1px solid #000;z-index:101\">"+res+"<div>";
					    	divDic.innerHTML = res;
					    	divDic.style.display = "block";
						}
					}
				}
			}
			dicAjax.send('');
		} 				
}
function httpInit() {
	var xmlHttp;
	if (!xmlHttp){
	
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            xmlHttp = new XMLHttpRequest();
            if (xmlHttp.overrideMimeType) {
                xmlHttp.overrideMimeType('text/xml');                
            }
        } else if (window.ActiveXObject) { // IE
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
		
	}
	
    if (!xmlHttp) {
        alert('Cannot create an XMLHTTP instance');
        return null;
    }else{
        return xmlHttp;
    }
}
function dicionarioMostrar(swf){
	var filme = '<div><a href=\"#\" onclick=\"return closeDicionario();\">Fechar</a></div>' +
    	'<object type="application/x-shockwave-flash" data="http://www.acessobrasil.org.br/libras/filme/'+swf+'"  width="100%" height="100%" id="VideoPlayback" >'+
		'<param name="movie" value="http://www.acessobrasil.org.br/libras/filme/'+swf+'" />'+
		'<param name="allowScriptAcess" value="sameDomain" />'+
		'<param name="quality" value="best" />'+
		'<param name="bgcolor" value="#FFFFFF" />'+
		'<param name="salign" value="TC" />'+
		'<param name="wmode" value="transparent" />'+
		'<param name="FlashVars" value="playerMode=embedded" /> Filme de Libras</object>';
	var divDic = document.getElementById("dicionarioLibrasSwf");
	divDic.innerHTML = filme;
	divDic.style.display = "block";
	return false;
}
function closeDicionario(){
	var divDic = document.getElementById("dicionarioLibras");
	divDic.innerHTML = "";
	divDic.style.display = "none";
	return false;
}
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var mouseX = 0;
var mouseY = 0;

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
	mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
	mouseX = e.pageX
    mouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}  
  return true;
}