Сворачивание категорий

ВЕРХ

Код:
<!----------- СВОРАЧИВАНИЕ КАТЕГОРИЙ 1 © ForumD, Gerda ----->
<script type="text/javascript">
function setcookie(a,b,c) {if(c){var d = new Date();d.setTime(d.getTime()+c);}if(a && b) document.cookie = a+'='+b+(c ? '; expires='+d.toUTCString() : '');else return false;}
function getcookie(a) {var b = new RegExp(a+'=([^;]){1,}');var c = b.exec(document.cookie);if(c) c = c[0].split('=');else return false;return c[1] ? c[1] : false;}
var aimg = {
 open: '-',
 close: '+'
}
</script>

НИЗ

Код:
<!------------ Сворачивание категорий 2 © ForumD, Gerda ------------>
<script type="text/javascript">
$('#pun-main div.category > h2 div.catleft').after('<span class="offctgr" style="float: right;">'+aimg.open+'</span>');
$('#pun-main div.category').each(function (i) {
  var ctgId = $(this).attr('id');
  var ctgCookie = getcookie(ctgId);
  if(ctgCookie && ctgCookie.hide){
    $('#' + ctgId + ' > h2 > .offctgr').text(aimg.close);
    $(this).removeClass('cat-show').addClass('cat-hide');
  }
  else if(ctgCookie && !ctgCookie.hide){
    $('#' + ctgId + ' > h2 > .offctgr').text(aimg.open);
    $(this).removeClass('cat-hide').addClass('cat-show');
  }
});

$('span.offctgr').click(function(){
  var cat = $(this).parents('div.category').attr('id');
  $(this).parents('div.category').toggleClass('cat-show').toggleClass('cat-hide');
  var s = $(this).text() == aimg.open ? aimg.close : aimg.open;
  $(this).text(s);
  var catc = getcookie(cat);
  catc = catc ? {val: catc.val, hide: !catc.hide} : {val: 'open', hide: true};
  setcookie(cat, catc.hide ? 'close' : 'open', 3600*24*30*1000);
  return false;
});

function getcookie(a) {
  var b = new RegExp(a+'=([^;]){1,}');
  var c = b.exec(document.cookie);
  if(c){
    c = c[0].split('=');
    return c[1] == 'close' ? {val: 'close', hide: true} : {val: 'open', hide: false};
  } else {
    return false;
  }
}
</script>