function moveCarousel(dir, element, text, gap)
{
    var carousel = document.getElementById(element);
    var imgs = carousel.getElementsByTagName('img');
    var total = imgs.length;

    var width = $(imgs[0]).readAttribute('width');
    width = parseInt(width) + parseInt(gap);

    var x = ($(element).getStyle('left') == null) ? '0px' : $(element).getStyle('left');
    x = String(x.substring(0, (x.length - 2)));

    if (dir == 'next') {
        var image = (x == 0) ? 2 : ((Math.abs(x) / width) + 2);
    } else if (dir == 'prev') {
        var image = (Math.abs(x) / width);
    } else {
        return false;
    }

    if (dir == 'next') {
        if (image -1 == total) { //move to the beginning
          var xx = $(imgs.length) - 1;
          var xw = xx * width;
          new Effect.MoveBy(element, 0, 0 , { x: xw, y: 0, duration: 0.2,  transition: Effect.Transitions.sinoidal});
          $(text).update($(imgs[0]).readAttribute('title'));
          return true;
        }
        else
        {
          if (x > -(width * (total - 1))) {
              new Effect.MoveBy(element, 0, 0 , { x: -width, y: 0, duration: 0.2,  transition: Effect.Transitions.sinoidal});
              $(text).update($(imgs[image - 1]).readAttribute('title'));
              return true;
          }
        }

    } else if (dir == 'prev') {
        if (image - 1 == -1) { //move to the end
          var xx = $(imgs.length) - 1;
          var xw = xx * width;
          new Effect.MoveBy(element, 0, 0 , { x: -xw, y: 0, duration: 0.2,  transition: Effect.Transitions.sinoidal});
          $(text).update($(imgs[xx]).readAttribute('title'));
          return true;
        }
        if (x < 0) {
            new Effect.MoveBy(element, 0, 0 , { x: width, y: 0, duration: 0.2,  transition: Effect.Transitions.sinoidal});
            $(text).update($(imgs[image - 1]).readAttribute('title'));
            return true;
        }

    } else {

        return false;

    }

    return false;
}
