 var myCaption = new Class({
      
      initialize: function(selector)
      {
         this.selector = selector;
         $each($$(selector), function(item){
            this.createCaption(item);
         }, this);
      },
      
      createCaption: function(zielement)
      {
          var caption   = document.createTextNode(zielement.title);
          var container = document.createElement('div');
          var text      = document.createElement('p');
          var width     = zielement.getAttribute('width');
          var align     = zielement.getAttribute('align');
      
          if(!width) {
         width = zielement.width;
          }
      
          text.appendChild(caption);
          container.inject(zielement, 'before');
          container.appendChild(zielement);
          if(zielement.title != '') {
         container.appendChild(text);
          }
      
          container.className   = this.selector.replace('.', '_');
          container.className   = container.className + '' + align;
          container.setAttribute('style','float:'+align);
          container.style.width = width + 'px';
      }   
   });
   
   document.caption = null;
   
   window.addEvent('load', function() {
      var caption = new myCaption('img.caption')
      document.caption = caption
   });
