banner_width = 0;
sprite_width = 800;

$(document).ready(function() {
    animateBanner();
});

function animateBanner() {
    setTimeout("slideBanner()", 6000);
}

function slideBanner() {
    if (banner_width == 0){
        var img = new Image();
        img.src = $('div#header').css('background-image').replace('url("', '').replace('")', '').replace('url(', '').replace(')', '');
        banner_width = img.width;
    }
    head_banner = $('div#header');
    if ($(head_banner).css('background-position') == 'undefined' || $(head_banner).css('background-position') == null)
        width = $(head_banner).css('background-position-x');
    else
        width = $(head_banner).css('background-position').split(' ')[0];
    next = parseInt(width) - sprite_width;
    if (next <= (0 - banner_width)){
        $(head_banner).animate({backgroundPosition: next + "px 0px"}, 1000, resetBanner);
    }
    else {
        $(head_banner).animate({backgroundPosition: next + "px 0px"}, {duration:1000});
    }
    animateBanner();
}

function resetBanner() {
    $('div#header').css('background-position', '0px 0px');
}
