// XXX - unused?
function scrollToTop() {
   scroll(0,0);
}


jQuery(function ($) {
    var boxes, current_box;

    boxes = $('.fade-box');
    current_box = 0;

    if (boxes.length > 1) {
        var first_div, firstDisplayInterval;

        //KDB use the data-displayinterval attribute to add a displayinterval data item to each div.fade-box and cleanup the attributes
        boxes.each(function () {
            var that = $(this);
            that.data('displayinterval', that.attr('data-displayinterval'));
            that.removeAttr('data-displayinterval');
        });

        first_div = $(boxes[current_box]);
        firstDisplayInterval = first_div.data('displayinterval') ? parseInt(first_div.data('displayinterval')) : 4000;

        setTimeout(next_box, firstDisplayInterval);
    }

    function next_box() {
        var from_div, to_div;

        from_div = boxes[current_box];
        current_box++;

        if (!boxes[current_box])
            current_box = 0;

        to_div = boxes[current_box];

        $(from_div).fadeOut(1000);
        $(to_div).fadeIn(1000);

        var nextDisplayInterval = $(to_div).data('displayinterval') ? parseInt($(to_div).data('displayinterval')) : 4000;
        setTimeout(next_box, nextDisplayInterval);
    }


    // popup - XXX seems unused
    $('a.popup').click(function () {
        window.open($(this).attr('href'), "viewmap", "width=800,height=650,toolbar=0,directories=0,menubar=0,status=yes,resizable=1,location=0,scrollbars=1,copyhistory=0");
        return false;
    });


    // rollover
    $('#roll li')
    .mouseenter(function () {
        $(this).addClass('over');
    })
    .mouseleave(function () {
        $(this).removeClass('over');
    })


    $('a.toggler').click(function () {
        var a = $(this),
          alt = a.attr('alt'),
          rel = '#' + a.attr('rel');

        a.attr('alt', a.text())
       .text(alt);

        if ($(rel).is(':hidden'))
            $(rel).show();
        else
            $(rel).hide();
    });

});

