  function slideshow(elem) {
    var ss=$(elem);

    var self = {
      delay: 5000,
      slidetime: 3000, 
      numslides: $('img', ss).size(),
      currentslide: 0,
      elem: elem,
      jqobj: ss,
      ready_next_frame: function() {
        var ss = this.jqobj;
        
        if (this.currentslide == this.numslides-1) {
          $('.slideshow-scroll', ss).animate({ scrollLeft: '+=477'}, this.slidetime, "swing", function(){
            $('.slideshow-scroll', ss).scrollLeft(0);
          });
          this.currentslide=0;
        } else {
          $('.slideshow-scroll', ss).animate({ scrollLeft: '+=477'}, this.slidetime, "swing");
          this.currentslide++;
        }
        var self = this;
        window.setTimeout(function(){
          self.ready_next_frame();
        }, self.delay);
      },
      init: function() {
        var ss = this.jqobj;
        
        $('.slideshow-text h3', ss).each(
          function() {
            //split the line just after the middle if more than 40 characters are present
            var h=$(this).html();
            if (h.length > 40) {
              h1 = h.substring(0,h.length/2);
              h2 = h.substring(h.length/2).replace(/\s/, '<br />');
              $(this).html(h1+h2);
            }
          }
        );
        
        $('img:eq(0)', ss).clone().appendTo($('.image',ss));
        $('table:eq(0)', ss).clone().appendTo($('.slideshow-text', ss));
        
        ss.css({ position: 'relative' });
        
        var l=0;
        $('img', ss).each(function(){
          $(this).css({
            position: 'absolute',
            top: 0,
            left: l
          });
          l+=477;
        });
    
        l=0;
        $('table', ss).each(function(){
          $(this).css({
            position: 'absolute',
            top: 0,
            left: l
          });
          l+=477;
        });
  
        if (this.numslides > 1) {
          var self = this;
          window.setTimeout(function(){ self.ready_next_frame() }, self.delay);
        }
      }
    }
    
    return self;
  }
  $().ready(function(){
    $('.slideshow').each(function(){
      slideshow(this).init();
    });
  });

