// Home page banner image support without flash.  

nonflash_image_cache = [];
nonflash_image_num = 0;

NONFLASH_INTERVAL = 10000;
nonflash_timer = null;

function nonflash_next(offset) {
    // Reset timer in case this was from mouse click
    clearTimeout(nonflash_timer);

    if (offset < 0) {
        offset = nonflash_image_data.length + offset;
    }

    nonflash_image_num = (nonflash_image_num + offset) % nonflash_image_data.length
    image_data = nonflash_image_data[nonflash_image_num];

    $("div#nonflash").fadeOut(500, function() {
        $(this).find('a').remove();
        $(this).prepend(nonflash_image_cache[nonflash_image_num]).fadeIn(500);
    });

    nonflash_timer = setTimeout("nonflash_next(1)", NONFLASH_INTERVAL);
}
    
$(document).ready(function() {
    // Hide navigation div until we get images
    nonflash_nav = $("div#nonflash .navigation")
    nonflash_nav.hide();

    $.ajax({
        type: "GET",
        url: "data.xml",
        dataType: "xml",
        success: function(xml) {
            nonflash_image_data = $(xml).find('set');

            if (nonflash_image_data.length != 0) {
                // Preload images into cache
                for (var i=0; i<nonflash_image_data.length; i++) {
                    nonflash_image_cache.push($('<a href="'+
                                                $(nonflash_image_data[i]).find('helpText').attr('urlLink')+
                                                '"><img src="'+$(nonflash_image_data[i]).find('image').text()+'"></a>'));
                }
                // Enable navigation
                nonflash_nav.show();
                $(nonflash_nav).find(".prev").click(function() { nonflash_next(-1); });
                $(nonflash_nav).find(".next").click(function() { nonflash_next(1); });

                // Set up for first transition
                nonflash_timer = setTimeout("nonflash_next(1)", NONFLASH_INTERVAL);
            }}
    });
});

