// I had a different way to do this, but I realized
// this content creates a much nicer outcome, and I didn't
// want to re-edit al my pages to change the JavaScript URL
// so ...

// only do this from arachnoid.com, not locally
// so the pages will work locally, away from an Internet connection

// function to add an event listener

addEvent(document,"dblclick", dictionary);

function addEvent(o,e,f) {
  if (o.addEventListener) {
    o.addEventListener(e,f,false);
    return true;
  }
  else if (o.attachEvent) {
    return o.attachEvent("on"+e,f);
  }
  else {
    return false;
  }
}

function dictionary() {
  // only do this if page comes from arachnoid.com
  if(location.href.match(/arachnoid.com/)) {
    if (navigator.appName!='Microsoft Internet Explorer') {
      var t = document.getSelection();
      access(t);
    }
    else {
      var t = document.selection;
      var ts = t.createRange();
      if(t.type == 'Text' && ts.text>'') {
        document.selection.empty();
        access(ts.text);
      }
    }
  }
}

function access(t) {
  // remove problem characters
  t = t.replace(/[!.:?,;"]/, '');
  // trim leading and trailing whitespace
  t = t.replace(/^\s*(\S*?)\s*$/,"$1");
  if (t) window.open('http://www.thefreedictionary.com/'+encodeURIComponent(t), 'dict', 'width=700,height=500,resizable=1,menubar=1,scrollbars=1,status=1,titlebar=1,toolbar=1,location=1,personalbar=1');
}



