Event.observe(document.onresize ? document : window, "resize", function(){stretchNav();});  

function initPage() {
  stretchNav();
}

function stretchNav() {
  var left = $('sidebar');
  var main = $('main');
  var contentHeight = $('content').getHeight();
  left.style.height = contentHeight+"px";
  main.style.height = contentHeight+"px";
}

function collapse() {
  var collapsed = '30px';
  var right = $('rightBar');
  right.fullWidth = right.getWidth();
  hide('quickNewsContent');
  hide('collapseBtn');
  $('quickNewsLabel').innerHTML = '...'
  show('expandBtn');
  head = $('quickNewsHead');
  head.style.width = collapsed;
  right.style.width = collapsed;
  $('content').style.marginRight = collapsed;
}

function expand() {
  var right = $('rightBar');
  var expanded = right.fullWidth+'px';
  $('content').style.marginRight = $('rightBar').fullWidth+'px';
  right.style.width = expanded;
  head = $('quickNewsHead');
  head.style.width = '100%';
  hide('expandBtn');
  show('quickNewsContent');
  show('collapseBtn');
  $('quickNewsLabel').innerHTML = 'Quick News'
  stretchNav();
}

function hide(id) {
  id=$(id);
  id.addClassName('invisible');
}

function show(id) {
  id=$(id);
  id.removeClassName('invisible');
}

function checkInput(){
  if($('words').value == ''){
    var host = document.location.protocol+'//'+document.location.host;
    var location = host+'/search.html';
    document.location = location;
  }else{
    $('submit').click();
    return(true);
  }
}

/* dbWrite is a debugging tool.  It writes msg into the innerHTML of the specified element.  */
function dbWrite(msg){
  msg = "<br />"+msg;
  var limit = 20;
  var db = $('debug');
  var tmp = db.innerHTML + msg;
  var lines = limit * parseInt(msg.length);
  while (tmp.length > lines){
    pos = parseInt(tmp.indexOf('<')) + 4;
    tmp = tmp.substr(pos);
  }
  db.innerHTML = tmp;
}


