
var divticker = Class.create({
    tickspeed: 1,
    ticktime: 55,
    timerinterval: 0,
    ele: null,
    bindele: null,

    initialize: function(scrolldiv) {
        this.ele = scrolldiv;
        this.bindele = this.tick.bind(this);
    },

    Pause: function() {
        if (this.timerinterval) {
            clearInterval(this.timerinterval);
            this.timerinterval = 0;
        }
    },

    Resume: function() {
        this.start();
    },

    SetSpeed: function(speed) {
        this.tickspeed = speed;
    },

    TickTime :function(timex) {
        this.ticktime = timex;
    },

    start: function() {
        if (!this.timerinterval) {
            this.timerinterval = setInterval( this.bindele, this.ticktime );
        }
    },

    tick: function() {
            this.ele.scrollLeft += this.tickspeed;
            if((this.ele.scrollWidth/2) > this.ele.offsetWidth) {
                if(this.ele.scrollLeft >= this.ele.scrollWidth/2) {
                    this.ele.scrollLeft = 0; // big images
                }
            } else {
                // this will jitter.  images too small.
                if(this.ele.scrollLeft >= (this.ele.scrollWidth - this.ele.offsetWidth)) {
                    this.ele.scrollLeft = 0;
                }
            }
    }
});
