var accordian_timer;
var ACCORDIAN_ROTATE = 5000; // time each rotation takes in ms
$(document).ready(function() {
    // intialise the accordian
    var accordian = $('#accordian').accordion({
        header: 'div.link'
    });
    // set it to automatically rotate
    accordian_timer = window.setTimeout("rotateAccordians(0)", ACCORDIAN_ROTATE);
    // remove the auto rotate if a header is clicked
    $('div.link', accordian).click(function() {
       window.clearTimeout(accordian_timer);
    });
});
/**
 * Automatically rotates each accordian item
 */
function rotateAccordians(next) {
    // get accordian and items
    var accordian = $('#accordian');
    var items = $('div.link', accordian);
    var num_accordians = items.length; // number of items in accordian
    accordian.activate(next); // show the next one
    next++; // increment for next accordian
    if (next == num_accordians) next = 0; // reset incrementer if we are the end
    accordian_timer = window.setTimeout("rotateAccordians("+next+")", ACCORDIAN_ROTATE);
}