document.observe("dom:loaded", function() { myNewslistScroller = new NewslistScroller});


var NewslistScroller = Class.create();
NewslistScroller.prototype = {

    initialize: function() {
        theObj = this;

        theObj.container = $('news_teaser');
        if (!theObj.container)
            return false;

        theObj.items = $$('#news_teaser .news-list-item');
        if (theObj.items.size() <= 1)
            return false;

        theObj.currentIndex = 0;

        theObj.items.each(function(item, index){
            if (index > theObj.currentIndex)
                Element.hide(item);
            else {
                theObj.item = item;
                theObj.hideItem();
            }
       });
	},

	hideItem: function(){
        theObj = this;
        window.setTimeout(function() {
            Effect.BlindUp(theObj.item, {duration:'1.2'});
//            Effect.Fade(theObj.item, {duration:'0.3'});
            theObj.showItem();
        }, 6000);

    },

    showItem: function(){
        theObj = this;
        window.setTimeout(function() {
            theObj.getNextItem();
            theObj.item = theObj.items[theObj.currentIndex];
            Effect.BlindDown(theObj.item, {duration:'1.4'});
//            Effect.Appear(theObj.item, {duration:'0.6'});
            theObj.hideItem();

        }, 1400);
    },

    getNextItem: function(){
        theObj.currentIndex = ( theObj.currentIndex + 1 >= theObj.items.size() ) ? 0 : theObj.currentIndex + 1;
        theObj.item = theObj.items[theObj.currentIndex];
    }
}

