// German Traslation Widget
// (c) 2008 Stan James
// Beta Beta Beta Version
// June 2008

var last=1;
var lastSel = "";
var clickInDef = false;

function getWord(e)
{

  // IE sucks
  if (window.event) {
    e = [];
    e.pageX = event.clientX + document.body.scrollLeft;
    e.pageY = event.clientY + document.body.scrollTop;
  }

  last = last + 1;

  var txt = '';
  var foundIn = '';

  if (window.getSelection)
  {
    txt = window.getSelection();
    foundIn = 'window.getSelection()';
  }
  else if (document.getSelection)
  {
    txt = document.getSelection();
    foundIn = 'document.getSelection()';
  }
  else if (document.selection)
  {
    txt = document.selection.createRange().text;
    foundIn = 'document.selection.createRange()';
  }
  else return;

  txt = txt+"";

  if ((txt.length < 2) || (txt.length > 45) || ("X" +txt) == lastSel) {
    // close the definition window;
    jQuery("#output-div").style.visibility="hidden";
    return;
  };

  // don't do it if nothing's changed
  lastSel = "X" + txt ;

  trackURL = 'http://syn.dict.cc/dcc-gadget.php';
  var pars = 's=' + encodeURIComponent(txt);
  var target = 'output-div';
  //var myAjax = new Ajax.Updater(target, trackURL, {method: 'get', parameters: pars});
  //$(target).innerHTML = trackURL+'?'+pars;

  //document.getElementById("output-div").innerHTML = trackURL+'?'+pars;
  document.getElementById("output-div").style.position="absolute";
  document.getElementById("output-div").style.top= (e.pageY - 110) + "px";
  document.getElementById("output-div").style.left= (e.pageX - 50) + "px";

  document.getElementById("def-iframe").src= trackURL+'?'+pars;

  jQuery("#output-div").style.visibility="visible"


}

function closeDef() {
  alert(window.clickInDef);
}
function processClicks() {
  alert("Thank you for clicking the mouse button.");
}


if (document.addEventListener) {
  document.addEventListener('mouseup', getWord, false);
}
else {
  // IE sucks ass
  document.onmouseup = getWord;
}

divhtml = '';
divhtml += '<div';
divhtml += '  id="output-div"';
divhtml += '  onclick="window.clickInDef = true"';
divhtml += '  style="position:absolute; top: 200px; left: 200px; height:90px; width:343px; padding-left: 5px; padding-right: 5px; margin: 0 0 0 0;  background-color: white; border: 1px solid black; visibility: hidden;">';
divhtml +=   '<div style="width: 20px; height:20px;float:right;padding-right:2px;">';
divhtml +=     '<a href="#" onclick=\'javascript:document.getElementById("output-div").style.visibility="hidden"; document.getElementById("def-iframe").src = "about:blank"; return false;\'>';
divhtml +=     '[X]</a>';
divhtml +=   '</div>';
divhtml += '<iframe style="width: 320px; height: 90px;" id="def-iframe" src="about:blank; padding: 0 0 0 0; margin: 0 0 0 0; border: 0px solid white;" frameborder="0"></iframe>';
divhtml += '</div>';


//document.body.innerHTML += divhtml;
jQuery('document').append(divhtml);


