// JavaScript Document

function slideSwitchBanner() {
    var $active = $('#slideshowBanner IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshowBanner IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshowBanner IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideSwitchTextoBanner() {
    var $active = $('#slideshowTextoBanner IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshowTextoBanner IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshowTextoBanner IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideSwitchMiniBanner() {
    var $active = $('#slideshowMiniBanner IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshowMiniBanner IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshowMiniBanner IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function slideSwitchMiniPromocao() {
    var $active = $('#slideshowMiniPromocao IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshowMiniPromocao IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshowMiniPromocao IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$(function() {
	var time=5000;
    setInterval( "slideSwitchBanner()", time);
	setInterval( "slideSwitchTextoBanner()", time);
	setInterval( "slideSwitchMiniBanner()", 10000 );
	setInterval( "slideSwitchMiniPromocao()", time);
});
