// JavaScript Document
// Script per slideshow casuale di immagini con jQuery

//HO DOVUTO MODIFICARE TUTTE LE FUNZIONI $() di jquery perchè fanno conflitto con prototype.js ed ho aggiunto una riga a jquery.js



function slideShow() {
    var $active = $('#slideshow div.active'); //$('#slideshow img.active');
	
    if ( $active.length == 0 ) $active = $('#slideshow div:last');
	
	var $next =  $active.next().length ? $active.next()
        : $('#slideshow div:first');
	
	
	// 3 linee che servono per far comparire le immagini in ordine casuale
	//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 slideShowDestroHome() {
    var $active = $('#slideshowFoto-slide div.active'); //$('#slideshow img.active');
	
    if ( $active.length == 0 ) $active = $('#slideshowFoto-slide div:last');
	
	var $next =  $active.next().length ? $active.next()
        : $('#slideshowFoto-slide div:first');
	
	
	// 3 linee che servono per far comparire le immagini in ordine casuale
	//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 slideShowAzienda() {
    var $active = $('#slideshowAzienda div.active'); //$('#slideshow img.active');
	
    if ( $active.length == 0 ) $active = $('#slideshowAzienda div:last');
	
	var $next =  $active.next().length ? $active.next()
        : $('#slideshowAzienda div:first');
	
	
	// 3 linee che servono per far comparire le immagini in ordine casuale
	//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 slideShow_goto(slideshow_id, slide_number) {
	clearInterval(intervalSlideshow);
	
	var $allSlide = $('#'+slideshow_id+' div');
	
	$allSlide.removeClass('active last-active');
	
	var last = (slide_number - 1) <= 0 ? 4 : slide_number - 1;
	
	var $active = $('#div_'+slide_number);
	
	
	$active.addClass('active');
	
	var $slideshow = $('#'+slideshow_id+' div');
	if ( $slideshow.length > 0 )
		intervalSlideshow = setInterval( "slideShow()", 5000 );
	
}

var intervalSlideshow;

jQuery(document).ready(function() {
   /* jQuery('#mycarousel').jcarousel({
        auto: 1,
        wrap: 'circular',
        scroll: 1,
        initCallback: mycarousel_initCallback
    });
	*/
	
	
	var $slideshow = $('#slideshowFoto-slide div');
	if ( $slideshow.length > 0 )
		setInterval( "slideShowDestroHome()", 3000 );
	
	var $slideshow = $('#slideshow div');
	if ( $slideshow.length > 0 )
		intervalSlideshow = setInterval( "slideShow()", 5000 );
	
	
	
	var $slideshow = $('#slideshowAzienda div');
	if ( $slideshow.length > 0 )
		setInterval( "slideShowAzienda()", 4000 );
});
