var glossary;
var glossary_width = 320;
var glossary_height = 240;

function show_term(term, x1, y1)
{
  var y2 = -1;
  
  if(glossary && !glossary.closed) {
    glossary.location = "glossary.php?term=" + term;
  }
  else {
    glossary = window.open("glossary.php?term=" + term, "glossary", "height=" + glossary_height + ",scrollbars=yes,width=" + glossary_width);
  }
  
  /* If it is small enough to move, do it */
  if(glossary_width < screen.availWidth / 2 && glossary_height < screen.availHeight / 2) {
    /* Space above */
    if(y1 - 50 > glossary_height) {
    	y2 = y1 - 50 - glossary_height;
    }
    /* Space below */
    else if(y1 + 50 + glossary_height < screen.availHeight) {
      y2 = y1 + 50;
    }

    if(y2 != -1) {
    	if(x1 + glossary_width + 50 < screen.availWidth) {
    	  glossary.moveTo(x1, y2);
    	}
    	else {
    	  glossary.moveTo(screen.availWidth - glossary_width - 50, y2);
    	}
    }
  }
  
  glossary.focus();
}