var Editorial = {
    current : 1,
    refresher: null,
    count: 0,

    init : function()
    {
	    $$('a.editorial-link').each(
	    function (link, i)
            {
		link.observe('click', Editorial.showSelected);
                Editorial.count++;
            });

            if (Editorial.count > 1) {
                Editorial.refresher = new PeriodicalExecuter(Editorial.showNext, 7.0);
            }
	
    },

    showNext: function()
    {
        var next;

        if (Editorial.current == Editorial.count) {
            next = 1;
        } else {
            next = Editorial.current + 1;
        }

        Editorial.show(next);
    },

    showSelected: function(event)
    {
        Editorial.show(this.id.replace(/editorial-link-/, ''));
    },

    show: function(editorialId)
    {
        editorialId = parseInt(editorialId);
        if (editorialId != Editorial.current) {

	    new Effect.Parallel([
				 new Effect.Fade('editorial-' + Editorial.current, { sync: true}),
				 new Effect.Appear('editorial-' + editorialId,{ sync: true})
                            ],
                            {
                                duration: 1.0
                            });
				    
	    $('editorial-link-' + Editorial.current).removeClassName('current-edito');
	    $('editorial-link-' + editorialId).addClassName('current-edito');
	    Editorial.current = editorialId;
	}
    }
};

document.observe('dom:loaded', function() { Editorial.init(); });