function findXY(o) {
  var x = 0;
  var y = 0;
  while (o != null) {
    x += o.offsetLeft;
    y += o.offsetTop;
    o = o.offsetParent;
  }
  return {x: x, y: y};
}

function categories_fold_up_sub(exclude) {
  var i = 0;
  var c;
  while((c = document.getElementById('drop'+i))) {
    if (i != exclude && c.style.visibility == 'visible') {
      bc = document.getElementById('drop'+i+'_button');
      bc.src = 'images/category-plus.gif';
      c.style.visibility = 'hidden';
    }
    i++;
  }
  return true;
}

function categories_fold_up(e) {
  categories_fold_up_sub(-1);
}

function category_drop_down(e, id) {
  e.cancelBubble = true;

  //@JSD_BREAK

  var o = document.getElementById('drop'+id);
  var b = document.getElementById('drop'+id+'_button');

  if (!o || !b)
    return false;

  categories_fold_up_sub(id);

  if (o.style.visibility == 'visible') {
    b = document.getElementById('drop'+id+'_button');
    b.src = 'images/category-plus.gif';
    o.style.visibility = 'hidden';
    return false;
  }

  var pos = findXY(o.parentNode);
  o.style.top =  (pos.y-3) + "px";
  o.style.left = (pos.x-3) + "px";
  b.src = 'images/category-minus.gif';
  o.style.visibility = 'visible';

  return false;
}
