var news =
{
    currentIndex : 0,
    timer : 0,
    items : [],
    links : [],
    init : function()
    {
        var entries = $('.news_container div.news_item');

        for(i = 0; i < entries.length; i++)
        {
            var entry = entries[i];
            this.items.push(entry);
        }

        $('.changer span.links a').each(function(i)
        {

            $(this).click(function()
            {
                if(news.timer) clearInterval(news.timer);
                setTimeout("news.play()", 8000);
            });

            if($(this).is('.previous'))
            {
                $(this).click(function() { news.prev(); return false; });
            }
            else if($(this).is('.next'))
            {
                $(this).click(function() { news.next(); return false; });
            }
            else
            {                
                news.links.push($(this));
                $(this).click(function() { news.navTo(i-1); return false; });
            }
            
        });

        this.displayFirst();
        
    },
    next : function()
    {
        this.unselect();
        this.currentIndex++;
        if(this.currentIndex > this.items.length - 1)
        {
            this.currentIndex = 0;
        }
        this._wrap();
        return false;
    },
    prev : function()
    {
        this.unselect();
        this.currentIndex--;
        if(this.currentIndex < 0 )
        {
            this.currentIndex = this.items.length - 1;
        }
        this._wrap();
        return false;
    },
    navTo : function(num)
    {
        this.unselect();
        this.currentIndex = num;
        this._wrap();
        return false;
    },
    displayFirst : function()
    {
        this._wrap();
        if(this.items.length > 1) this.play();
    },
    select : function()
    {
        $(this.links[this.currentIndex]).css({'font-weight' : 'bold', 'text-decoration' : 'underline'});
    },
    unselect : function()
    {
        $(this.links[this.currentIndex]).css({'font-weight' : 'normal', 'text-decoration' : 'none'});
    },
    _change : function()
    {
        $('.news_placeholder').wrapInner(news.items[news.currentIndex]);

//        $('.news_placeholder').slideDown(400);
        $('.news_placeholder').fadeIn(400);
    },
    _wrap : function()
    {
        this.select();
        $('.news_placeholder').fadeOut(400, this._change );        
    },
    play : function()
    {
        if(this.timer) clearInterval(this.timer);
        this.timer = setInterval("news.next()", 8000);
    }
};


