horus.cookie=
  function (cookie) {
    var cookies=document.cookie.split(/; */);
    var test=new RegExp('^'+cookie+'(=|$)');
    var oldvalue=null;

    for (var c in cookies)
      if (test.test(cookies[c])) {
	oldvalue=decodeURIComponent(cookies[c].replace(/^[^=]*=?/, ''));
	break;
      }

    if (arguments.length>1) {
      var newvalue=arguments[1];
      var expiry=arguments.length>2 ? arguments[2] : null;
      var path=arguments.length>3 ? arguments[3] : '/';

      if (newvalue==null) {
	expiry=-1;
	newvalue='';
      }

      var date=new Date();
      date.setTime(date.getTime()+expiry*24*60*60*1000);
      cookie+='='+encodeURIComponent(newvalue);
      if (expiry!=null) cookie+=';expires='+date.toGMTString();
      if (path!=null) cookie+=';path='+path;
      document.cookie=cookie;
    }

    return oldvalue;
  };


horus.script.loaded('cookie.js');
