var topImage=
{
    count: 0,
    current: 0,
    path: '',
    suffix: 'jpg',
    element: false,

    preloadTopImage: function( imageID )
    {
        var image = new Image();
        image.src = topImage.pathToImage( imageID );
    },

    pathToImage: function( imageID )
    {
        return topImage.path + imageID + '.' + topImage.suffix;
    },

    rotateTopImage: function()
    {
        if ( !topImage.element )
        {
            topImage.element = document.getElementById( 'frontpage-topimage' );
            if ( !topImage.element )
            {
                return;
            }
        }

        topImage.current = 1 + topImage.current % topImage.count;
        topImage.element.style.backgroundImage = 'url(' + topImage.pathToImage( topImage.current ) + ')';
        topImage.preloadTopImage( 1 + topImage.current % topImage.count );
    },

    init: function()
    {
        topImage.preloadTopImage( 1 + topImage.current % topImage.count );
        setInterval( "topImage.rotateTopImage()", 5000 );
    }
}
