/*
 * Yagooar JQuery Generic Banner
 * Jquery simple banner implementation
 *
 * @author Mateusz Sojka yagooar@gmail.com
 * @version 0.1
 *
 * @license Released under the GNU General Public License v3.0
 *
 */

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

/**
 * Contains the initial configuration of the script and launches the animation
 */
function init2() {
    config = {
        'width'     :    756, // Ancho del banner
        'height'    :    98, // Altura del banner
        'effect'    :    'fade', // Efecto de transición (por ahora sólo está disponible fade)
        'speed'     :    4000 // Tiempo en pantalla de cada elemento
    };

    bannerYJQG_aperturas(config);
}

/**
 * The core function
 * @var script parameters
 */
function bannerYJQG_aperturas(config) {

    banner = $('#bannerYJQG_aperturas');
    elements = $('#image_list_YJQG_aperturas');

    banner.css('width', config.width);
    banner.css('height', config.height);

    $(elements).find('li:not(.activeYJQG_aperturas)').hide();

    // Transition type
    if (config.effect == 'fade') {
        fade2(elements, config);
    }

}

/**
 * External animation script
 * @var elements - \<ul\> list
 * @var config - script parameters
 */
function fade2(elements, config) {

    var toggleFade = function() {
        if (elements.find('.activeYJQG_aperturas'))
        elements.find('.activeYJQG_aperturas')
            .fadeOut('slow', function() {
                $(this).removeClass('activeYJQG_aperturas');
                if ($(this).next('li').length > 0) {
                    $(this)
                    .next('li')
                    .fadeIn('slow')
                    .addClass('activeYJQG_aperturas');
                } else {
                    $(elements).find('li:first')
                    .fadeIn('slow')
                    .addClass('activeYJQG_aperturas');
                }

            })
    }
    
    setInterval(toggleFade, config.speed);

}

