/**
 * mootools 1.2 news scroller
 *
 * By Meir Kriheli <meir@mksoft.co.il>
 */

var INTERVAL = 60;
var STEP = 1;

var Scroller = new Class({
    initialize: function(el) {
        this.el = $(el);
        this.el.setStyle('position','relative');

        // get the inner el, and set it styles
        this.scrollEl = this.el.getChildren()[0];
        this.scrollEl.setStyles({ position:'absolute', top: 0, width:this.el.getSize().x });

        this.top = 0;

        this.periodical_id = this.scroll.periodical(INTERVAL, this);
        this.isScrolling = true;

        this.el.addEvents({
            'mouseenter': function(ev) {
                    if (this.isScrolling) {
                        this.isScrolling = false;
                        $clear(this.periodical_id);
                    }
                }.bindWithEvent(this), 
            'mouseleave': function(ev) {
                    if (!this.isScrolling) {
                        this.isScrolling = true;
                        this.periodical_id = this.scroll.periodical(INTERVAL, this);
                    }
                }.bindWithEvent(this) 

        });
    },
    scroll: function() {
        // is the 1st element out of view ? remove and append at bottm
        the_el = this.scrollEl.getChildren()[0];
        box = the_el.getSize();

        if (this.top + box.y < 0) {
            the_el = the_el.dispose();
            the_el.inject(this.scrollEl);
            this.top = -STEP;
        }
        this.top -= STEP;
        this.scrollEl.setStyle('top', this.top);
    }

});

