IMGS = new Array (
    'barranca',
    'pasion',
    'icaserver',
    'genesis',
    'xploded'
);

URLS = new Array (
    'video_3d_de_la_plazuela_sebastian_barranca.html',
    '',
    'http://icaserver.com',
    'video_publicitario_de_paperclip_genesisng.html',
    ''
);

IA = 0; // El go() siempre le añade 1 al inicio.
OP = 0; // Opacidad
CANCEL = false; // Si es true, ya no ciclamos

MAX = IMGS.length;

function drawlinks() {
    id = 1;

        document.write ( '<a class="banner_links" href="javascript:prevnext(-1)">' );
        document.write ( '&laquo;' );
        document.write ( '</a>' );

        document.write ( '<a class="banner_links" href="javascript:prevnext(1)">' );
        document.write ( '&raquo;' );
        document.write ( '</a>' );


    for ( i in IMGS  ) {
        document.write ( '<a class="banner_links" id="lnk' + id + '" href="javascript:setimage(' + id + ', true)">' );
        document.write ( id );
        document.write ( '</a>' );
    
        id++;
    }
}

function opacity ( element, op ) {
    e(element).style.opacity = op / 100;
    try {
        e(element).filters.alpha.opacity = op;
    }
    catch (err) {
    
    }
}

function click () {
    URL = URLS[IA - 1];
    if ( URL != '' )
        ir ( URL );
}

function changeOpacity () {
    //e('banner2').style.opacity = OP / 100;
    opacity ( 'banner2', OP );
    
    OP = OP + 2
    
    if ( OP < 100 ) {
        setTimeout ( 'changeOpacity()', 10 );
    }
    else {
        // Si ya acabó, intercambiamos los papeles
        e('banner1').style.backgroundImage = 
            e('banner2').style.backgroundImage;
            
        // Y los opacities
        opacity ( 'banner1', 100 );
        opacity ( 'banner2', 0 );
        
        OP = 0;
        
        // Marcamos el numero de la imagen
        for ( i = 1; i <= MAX; i++ ) {
            e('lnk' + i).className = "banner_links";
        }
        e('lnk' + IA).className = "banner_links_active";
        
        // Lito.
    }
}

function setimage( id, c ) {
    // Colocamos la nueva imagen.
    e('banner2').style.backgroundImage = 'url(html/imgs/banners/' + IMGS[id - 1] + '.jpg)';

    // Y llamamos al opacity!
    IA = id
    OP = 0
    setTimeout ( 'changeOpacity()', 0 );

    // Esto cancela?
    if ( c )
        CANCEL = true;

}

function prevnext ( dir, nocancel ) {

    if ( dir == -1 ) {
        IA -= 1;
        if ( IA < 1 )
            IA = MAX
    }
    else {
        IA += 1;
        if ( IA > MAX )
            IA = 1;
    }

    setimage ( IA );

    if ( !nocancel ) 
        CANCEL = true
}

function go (  ) {
    // Empezamos por la 1ra

    if ( CANCEL )
        return false;

    // Avanzamos una imagen
    prevnext ( 1, true );

    // Y nos llamamos al rato.
    setTimeout ( 'go()', 5000 );
}


