
var divmsgticker = 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;
                }
            }
    }
});


var divonlinebar = Class.create({
    showtime: 5,
    hidetime: 1,
    timerinterval: 0,
    ele1: null,
    ele2: null,
    divwrapper: null,
    bindele: null,

    initialize: function(elename1,elename2,divname) {
        this.ele1 = $(elename1);
        this.ele2 = $(elename2);
        this.divwrapper = $(divname);
        this.bindele = this.tick.bind(this);
    },

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

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

    ShowTime: function(val) {
        this.showtime = val;
    },

    HideTime:function(val) {
        this.hidetime = val;
    },

    start: function() {
        if (!this.timerinterval) {
            this.tick();
            this.timerinterval = setInterval( this.bindele, this.showtime*1000 );
        }
    },

    tick: function() {
        if (this.ele1.visible()) {
            this.ele1.fade({ duration: this.hidetime}); 
            this.ele2.style.left = -Math.floor(Math.random()*(this.ele2.getWidth()-this.divwrapper.getWidth()));
            this.ele2.appear({ duration: this.hidetime}); 
        } else {  
            this.ele2.fade({ duration: this.hidetime}); 
            this.ele1.style.left = -Math.floor(Math.random()*(this.ele2.getWidth()-this.divwrapper.getWidth()));
            this.ele1.appear({ duration: this.hidetime});
        }
    }
});

