
   // textarea management

   function setMaxLength() 
   {
      var x = document.getElementsByTagName('textarea');
      var counter = document.createElement('div');
      counter.className = 'counter';
      for (var i=0;i<x.length;i++)
      {
         if (x[i].getAttribute('maxlength')) 
         {
            var counterClone = counter.cloneNode(true);
            counterClone.relatedElement = x[i];
            counterClone.innerHTML = '<span>0</span> of '+x[i].getAttribute('maxlength')+' characters';
            x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
            x[i].relatedElement = counterClone.getElementsByTagName('span')[0];
            x[i].onkeyup = x[i].onchange = checkMaxLength;
            x[i].onkeyup();
         }
      }
   }

   function checkMaxLength() 
   {
      var maxLength = this.getAttribute('maxlength');
      var currentLength = this.value.length;
      if (currentLength > maxLength)
         this.relatedElement.className = 'alert';
      else
         this.relatedElement.className = '';
      this.relatedElement.firstChild.nodeValue = currentLength;
   }

   $(function() { setMaxLength(); });


   // comment display / hide

   function showComments(id)
   {  
      $("div#commentbar" + id + " a.commentshow").fadeOut("fast",function()
      {
         $("div#commentbar" + id + " a.commentworking").fadeIn("fast",function()
         {
            $("div#comments" + id).load("/comments.php?id=" + id,function()
            {
               $(this).slideDown("fast",function()
               {
                  $("div#commentbar" + id + " a.commentworking").fadeOut("fast",function()
                  {
                     $("div#commentbar" + id + " a.commenthide").fadeIn("fast");
                  });
               });
            });
         });
      });
   }

   function hideComments(id)
   {
      $("div#comments" + id)
         .slideUp("fast",function()
         {
            $("div#commentbar" + id + " a.commenthide").fadeOut("fast",function()
            {
               $("div#commentbar" + id + " a.commentshow").fadeIn("fast");
            });
         });
   }

   // preload images for rollovers

   if (document.images) 
   {
      menudir = "/images/menu/";

      menuArchives1 = new Image(112,22);
      menuArchives1.src = menudir + "archives1.gif";
      menuArchives2 = new Image(112,22);
      menuArchives2.src = menudir + "archives2.gif";

      menuRss1 = new Image(85,22);
      menuRss1.src = menudir + "rss1.gif";
      menuRss2 = new Image(85,22);
      menuRss2.src = menudir + "rss2.gif";

      menuEmail1 = new Image(85,22);
      menuEmail1.src = menudir + "email1.gif";
      menuEmail2 = new Image(85,22);
      menuEmail2.src = menudir + "email2.gif";
   }

   // simple image replacements

   function rollOn(imgID)
   {
      if (document.images) document.images[imgID].src = eval(imgID + "2.src"); 
   }

   function rollOff(imgID)
   {
      if (document.images) document.images[imgID].src = eval(imgID + "1.src"); 
   }


