// Main picture changer
$(document).ready(function() {
    $('.fader').after('<div class="pager">').cycle({
        timeout: 7000,
        pause: 1,
        pager: '.pager'
    });
});

// What's on tabs
$(document).ready(function() {
    $('.whats-on').tabify();
});

// Calendar tab buttons
$(document).ready(function() {
    function connect_calendar(calendar) {
        calendar.find('a.next, a.previous').click(function() {
            var url = $(this).attr('href');

            $.get(url, function(data) {
                calendar.html(data);
                connect_calendar(calendar);
            });
            return false;
        });
    }

    connect_calendar($('div.list'));
});

// News and photos scroller
//$(document).ready(function() {
    /*
     * Gets the next slide in the sequence and adds it to the
     * slide show
     */
    /*
    addNextSlide = function(curr, next, opts) {
        if(opts.currSlide < opts.elements.length - 1) {
            $('.photos .next').fadeTo('fast', 1).removeClass('inactive');
        }
        else {
            $('.photos .next').fadeTo('fast', 0.5).addClass('inactive');
        }

        if(opts.currSlide > 0) {
            $('.photos .previous').fadeTo('fast', 1).removeClass('inactive');
        }
        else {
            $('.photos .previous').fadeTo('fast', 0.5).addClass('inactive');
        }
        
        if(opts.currSlide == opts.elements.length - 2) { 
            getNextSlide(function(nextSlide) {    
                opts.addSlide(nextSlide);
            });
        }
    }
    */
    
    /*
     * Gets the next slide in the sequence and calls the given
     * function on success
     */
    /*
    getNextSlide = function(success) {
        var nextOffset = $('.photos .story').length + 1;
        
        $.get('/news/offset/' + nextOffset + '/', function(data) {
            data = $.trim(data);
            if(data) {
                var nextSlide = $('<div></div>').append(data).hide();
                
                success(nextSlide);
            }
        });
    }
    */

    /*
     * Gets the next slide in the sequence, appends it to the slide
     * panel and then creates the slide show
     */
    /*
    getNextSlide(function(nextSlide) {
        $('.photos .stories').append(nextSlide).cycle({
            fx: 'scrollHorz',
            timeout: 0,
            next: '.photos .next',
            prev: '.photos .previous',
            after: addNextSlide,
            nowrap: true,
            height: '290px',
        });
    });

    $('.photos h2').after('<ul class="controls">' +
        '<li><a class="previous"><img src="/static/images/left-arrow.gif" /></a></li>' +
        '<li><a class="next"><img src="/static/images/right-arrow.gif" /></a></li>' +
        '</ul>');
    */
//});

