var x = null;

function startrightscroll() {
   x = window.setInterval(function scroll() {
    hCarousel.scrollTo(hCarousel.currentIndex() + 1);
   },10);
}

function startleftscroll() {
   x = window.setInterval(function scroll() {
    hCarousel.scrollTo(hCarousel.currentIndex() - 1);
   },10);
}

function stopscroll() {
   window.clearInterval(x);
}

function runTest() {
  var photos = $('photos');
  if (photos) {
    hCarousel = new UI.Carousel("photos", {direction: "horizontal", 'scrollInc':1});
    $('scrollright').observe('mouseover', startrightscroll);
    $('scrollright').observe('mouseout', stopscroll);
    $('scrollleft').observe('mouseover', startleftscroll);
    $('scrollleft').observe('mouseout', stopscroll);

    $A(document.getElementsByTagName("script")).findAll( function(s) {
      return (s.src && s.src.match(/galerie\.js(\?.*)?$/))
    }).each( function(s) {
      var path = s.src.replace(/galerie\.js(\?.*)?$/,'');
      var current = s.src.match(/\?.*current=([0-9]*)/);
      if (current) {
        //alert(current[1]);
        hCarousel.scrollTo(current[1]);
      }
    });

  }
}

Event.observe(window, "load", runTest);