Effect.DefaultOptions.duration = 0.3;
NewsTicker = Class.create();
Object.extend(NewsTicker.prototype, 
{
    tickerDiv : "newsticker-spacer", tickerLocation : "billboard", tickerTitle : "news-link", 
    pauseLength : 3500, timer : 0, currentTitle : 0, items : null, 
    initialize : function (items)
    {
        this.items = items;

        this.buildTicker();
    },
    buildTicker : function ()
    {
        if (this.items[this.currentTitle]) {
            $(this.tickerTitle).innerHTML = this.items[this.currentTitle]["title"];
            this.start();

			$(this.tickerTitle).observe('mouseover', this.stop.bind(this));
			$(this.tickerTitle).observe('mouseout', this.start.bind(this));
        }
    },
    start : function ()
    {
        this.interval = setInterval(this.showNext.bind(this), this.pauseLength);
    },
    stop : function ()
    {
        clearInterval(this.interval)
    },
    showNext : function ()
    {
        if (this.currentTitle < this.items.length - 1) {
            this.currentTitle = this.currentTitle + 1
        }
        else {
            this.currentTitle = 0
        }
        new Effect.Fade("news-link", 
        {
            afterFinish : function ()
            {
                this.switchData();
                new Effect.Appear("news-link")
            }
            .bind(this)
        })
    },
    switchData : function ()
    {
        $(this.tickerTitle).setAttribute("href", this.items[this.currentTitle]["link"]);
        if (this.items[this.currentTitle]) {
            $(this.tickerTitle).innerHTML = this.items[this.currentTitle]["title"];
        }
    }
});
