if ('undefined' != typeof jQuery) {
  var $ = jQuery;
  function HorizontalScroller(id) {
    this.el = $('#' + id);

    var a = $('a', this.el);
    this.elWidth = a.length * (8 + a.width());
    this.elLeft = -2;
    this.el.width(a.length * (8 + a.width()));
    this.el.empty();
    this.el.append(a.clone(true));
    this.el.append(a.clone(true));
    this.el.append(a.clone(true));
    this.el.append(a.clone(true));
    this.el.append('<span class="stopFloat"></span>');
    this.el.width(4 * this.el.width());
    
    this.start();
  };
  
  HorizontalScroller.prototype.interval = function(rev, step) {
  	if ('undefined' == typeof rev) var rev = true;
  	if ('undefined' == typeof step) var step = 0.5;
    if (Math.round(this.elLeft) <= (2 * -this.elWidth)) { this.elLeft = -this.elWidth; }
    if (Math.round(this.elLeft) >= 0) { this.elLeft = -this.elWidth; }
    this.elLeft += (rev ? -1 : 1) * step;
    this.el.css('left', this.elLeft + 'px');
  };
  
  HorizontalScroller.prototype.start = function(interval, rev, step) {
    var me = this;
  	if ('undefined' == typeof step) var step = 0.5;
  	if ('undefined' == typeof rev) var rev = true;
    if ('undefined' == typeof interval) var interval = 42; // entspricht rund 24 Bildern pro Sekunde
    this.stop(this.i);
    var t = function() { me.interval(rev, step); }
    this.i = window.setInterval(t, interval); 
  };
  
  HorizontalScroller.prototype.stop = function() {
    window.clearInterval(this.i);
  };

	$(document).ready(function() {
		window.hs = new HorizontalScroller('galeries-slider');
	});
};
  

