var cur     = "top-boys-op";
var i       = 0;
var state   = true;

var arr     = new Array();

    arr[0]  = "top-boys-op";
    arr[1]  = "top-girls-op";
    arr[2]  = "random-op";
    arr[3]  = "celeb-op";

function cycleTop()
{
    if( state )
    {
        if( i == 4 ) i = 0;

        autoChangeTop( i );

        i++;
    }

    setTimeout( "cycleTop()", 5000 );
}

function autoChangeTop( obj )
{
    if( state )
    {
        // Change the background
        document.getElementById( "top-names" ).style.backgroundPosition = '0px -' + ( obj * 161 ) + 'px';

        // Hide the old one
        document.getElementById( cur ).style.visibility = 'hidden';

        // Show the new one
        document.getElementById( arr[obj] ).style.visibility = 'visible';

        cur = arr[obj];
    }
}

function changeTop( obj )
{
    // Find j
    var j = 0;

    for( var k = 0; k < arr.length; ++k )
    {
        if( arr[k] == obj )
        {
            j = k;
        }
    }

    // Change the background
    document.getElementById( "top-names" ).style.backgroundPosition = '0px -' + ( j * 161 ) + 'px';

    // Hide the old one
    document.getElementById( cur ).style.visibility = 'hidden';

    // Show the new one
    document.getElementById( obj ).style.visibility = 'visible';

    cur = obj;

    i = j;

    state = false;
}

function startRotate()
{
    state = true;
}
