/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function() {
    $('#slideshow').animate({opacity: 1.0}, 1000, function() {
        setInterval( "slideSwitch()", 3000 );
    });

    $('#bannerClientiJS').animate({opacity: 1.0}, 1000, function() {
        setInterval( "slideBanner()", 3000 );
    });

    $('#bannerClientiJS img').click(function() {
        var url = $(this).attr('url');
        window.location.href = url;
    });
});

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

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

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow 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 slideBanner() {
    var $active = $('#bannerClientiJS IMG.active');

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

    var $next =  $active.next().length ? $active.next()
        : $('#bannerClientiJS IMG:first');

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

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


