function animacion_presentacion(lista_imagenes, duracion, retraso) {

    imagen_vieja = lista_imagenes.shift();

    new Effect.Parallel([
        new Effect.Opacity($(imagen_vieja), { sync: true, from: 1, to: 0 }),
        new Effect.Opacity($(lista_imagenes[0]), { sync: true, from: 0, to: 1 }) 
    ], {duration: duracion, delay:retraso, transition: Effect.Transitions.linear})

    lista_imagenes.push(imagen_vieja)

}

Event.observe(window, 'load', function() {

    var imagenes_presentacion = $$('.imagen-presentacion').collect(function(i) {return i.id})
    var imagenes_presentacion2 = $$('.imagen-presentacion2').collect(function(i) {return i.id})
    var imagenes_banda = $$('.imagen-banda').collect(function(i) {return i.id}) 

    // La animacion de los ovalos del personal
    $$(".talento").each(function(item) {
        item.observe('mouseover', function(event) {
            $('foto-'+this.id).hide()
            $('comentario-'+this.id).show()

            // Uff, compostura para bug de IE en z-index
            $$(".talento").each(function(item) {
                item.setStyle({'zIndex': 1})
                item.ancestors().each(function(ancestro) {
                    if ('relative' == ancestro.getStyle('position')) {
                        ancestro.setStyle({'zIndex': 1})
                    }
                })
            })
            this.setStyle({'zIndex': 10})
        })
        item.observe('mouseout', function(event) {
            $('foto-'+this.id).show()
            $('comentario-'+this.id).hide()
        })
    })

    // Los movimiento de la barra de proyectos
    $$(".barra-movible-izq").each(function(item) {
        item.observe('click', function(event) {
            new Effect.Move($(item.id.slice(0,-4)), { x: -380, y: 0, mode: 'relative' })
        })
    })

    $$(".barra-movible-der").each(function(item) {
        item.observe('click', function(event) {
            new Effect.Move($(item.id.slice(0,-4)), { x: 380, y: 0, mode: 'relative' })
        })
    })

    // La presentacion de la pagina inicial
    if ($('presentacion')) {
        if ($('presentacion2')) {
            new PeriodicalExecuter(function(oe) {animacion_presentacion(imagenes_presentacion, 2, 0)}, 8);
        } else {
            new PeriodicalExecuter(function(oe) {animacion_presentacion(imagenes_presentacion, 2, 0)}, 4);
        }
    }

    if ($('presentacion2')) {
        new PeriodicalExecuter(function(oe) {animacion_presentacion(imagenes_presentacion2, 2, 4)}, 8)
    }

    // La anicamcion de la banda de abajo de las paginas interiores
    if ($('banda-fotos')) {
    new PeriodicalExecuter(function(oe) {

        elemento = $(imagenes_banda.last())
        elemento.setStyle({width: '0px'})
        $('contenido-banda-fotos').insert( {top: elemento} )

        if ($('banda-fotos').hasClassName('banda-qualimetales')) {
            new Effect.Morph(elemento, {style: {width: '811px'}})
        } else if ($('banda-fotos').hasClassName('banda-qualirent')) {
            new Effect.Morph(elemento, {style: {width: '398px'}})
        } else {
            new Effect.Morph(elemento, {style: {width: '194px'}})
        }

        imagen_vieja = imagenes_banda.pop()
        imagenes_banda.unshift(imagen_vieja)

    }, 4)
    }

})

