if (window.Event) {
 document.captureEvents(Event.MOUSEUP);  
 document.captureEvents(Event.MOUSEDOWN); 
}
document.onmouseup = mouseup;
document.onmousedown = mousedown;

var msgWindow;    // new window for google search results
var mouse_x=0;
var mouse_y=0;

function update_mouse_coords(e)
{  
	if (window.getSelection) {  // Moz
    mouse_x=e.layerX;
    mouse_y=e.layerY;
	} else if (document.selection && document.selection.createRange) { // IE
    if (document.documentElement) // IE 6 + XHTML doctype
    {
      mouse_x=window.event.clientX+document.documentElement.scrollLeft-4;
      mouse_y=window.event.clientY+document.documentElement.scrollTop-4;
    }
    else
    {
      mouse_x=window.event.clientX+document.body.scrollLeft-4;
      mouse_y=window.event.clientY+document.body.scrollTop-4;
    }
	} else { // out of luck below v.4
		var str = "";
		  window.status="Sorry, event capture is not possible with your browser.";
		return;
	}
}

function mousedown(e) 
{
  update_mouse_coords(e);
  setTimeout('adict_box_hide()',10);   // hide the "G" after 10 ms.
                                   // Doing it right away makes things not behave right (try it and see).
}

function mouseup(e) 
{
  update_mouse_coords(e);          // get current mouse coordinates
  setTimeout('adict_box_show()',10);   // display a little "G" in 10 ms 
                                   // Doing it right away makes things not behave right (try it and see).
}

function adict_box_hide() 
{
  var str = get_selection();
	if (str.length != 0) return;     // if nothing is selected
  
  var adict_box = document.getElementById("adict_box");
  adict_box.style.visibility = "hidden";
}

function adict_box_show() 
{
  var str = get_selection();       // see what's selected
  if (str.length == 0) return;     // if nothing is selected return
  var adict_box = document.getElementById("adict_box");
  if (adict_box.style.visibility == "visible") return;
  
	if (window.getSelection) // Moz
  {  
    adict_box.style.left = mouse_x + "px";
    adict_box.style.top =  mouse_y + "px";
	} 
  else if (document.selection && document.selection.createRange) // IE
  { 
    // experimental stuff for using IE textrange to put
    // the Aquatic Dictionary Link at the end of the selection
  
		//var range = document.selection.createRange();
    //var corner_x=range.boundingLeft+range.boundingWidth;
    //var corner_y=range.boundingTop+range.boundingHeight;
    //adict_box.style.left = corner_x;
    //adict_box.style.top = corner_y;
    
    adict_box.style.left = mouse_x + "px";
    adict_box.style.top =  mouse_y + "px";
  }
  //alert("corner x: "+adict_box.style.left+" corner y: "+adict_box.style.top);
  
  adict_box.style.visibility = "visible";
  
  //alert("mouse x: "+mouse_x+" mouse y: "+mouse_y+"\nmouse window x: "+mouse_window_x+" mouse window y: "+mouse_window_y);
}

function adict_search() 
{
  var target='http://www.aquaticdictionary.com/dictionary/define.asp?term=';
  var str = get_selection();
	self.name = "body";
	msgWindow = window.open(target + str, "_blank", "location=yes,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,height=480,width=740,screenX=0,left=0,screenY=0,top=0");
}

function adict_search_mouseover_status() // my_function_name_is_longer_than_your_function_name_ha_ha
{
  var str = get_selection();
  window.status = "Aquatic Dictionary search for \""+str+"\"";
  return true;
}

function get_selection() 
{
  var str = new String("");
  if (window.getSelection)   // Moz
  {
		str = window.getSelection().toString();
	} 
  else if (document.selection && document.selection.createRange) // IE
  { 
		var range = document.selection.createRange();
		str = range.text.toString();
	} 
  else // out-of-luck below v.4
  { 
		//alert("Sorry, event capture is not possible with your browser.");
	}
  
  // remove non-alphanumeric stuff from the string
  str = str.replace(/[^a-zA-Z 0-9]+/g,'');

  return str;
}
document.write("<a id='adict_box' class='adict_box' "); 
document.write("style='position:absolute; visibility:hidden; posi"); 
document.write("tion:absolute; display:block; margin:1px;	padding:"); 
document.write("1px; color: #FFCC33; border: solid 1px; background"); 
document.write("-color:#FF9900; border-color: #000000 #000000 #000"); 
document.write("000 #000000;	font-family:Verdana, Arial, serif;	fo"); 
document.write("nt-weight:bold; text-decoration:none; z-index:1000"); 
document.write("; left: 883px; font-size: 10px;' href='javascript:"); 
document.write("adict_search();' onMouseOver='adict_search_mouseov"); 
document.write("er_status();return true;' ");
document.write(String.fromCharCode(111,110,77,111,117,115,101,79,117,116,61,34,119,105,110,100,111,119,46,115,116,97,116,117,115,32,61,32,39,68,111,110,101,39,59,34));
document.write(">");
document.write("Search at<br> <span style='color: #" +"FFFFFF; font-family: 'Times New Roman', Times, ser" +"if; font-size: 14px; font-style: normal;'>AquaticD" +"ictionary.com</span></a>");



